2 * collectd - src/perl.c
3 * Copyright (C) 2007-2009 Sebastian Harl
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Sebastian Harl <sh at tokkee.org>
25 * Pavel Rochnyak <pavel2000 ngs.ru>
29 * This plugin embeds a Perl interpreter into collectd and provides an
30 * interface for collectd plugins written in perl.
33 /* do not automatically get the thread specific Perl interpreter */
34 #define PERL_NO_GET_CONTEXT
43 /* Some versions of Perl define their own version of DEBUG... :-/ */
48 /* ... while we want the definition found in plugin.h. */
52 #include "filter_chain.h"
54 #if !defined(USE_ITHREADS)
55 #error "Perl does not support ithreads!"
56 #endif /* !defined(USE_ITHREADS) */
58 /* clear the Perl sub's stack frame
59 * (this should only be used inside an XSUB) */
60 #define CLEAR_STACK_FRAME PL_stack_sp = PL_stack_base + *PL_markstack_ptr
64 #define PLUGIN_WRITE 2
65 #define PLUGIN_SHUTDOWN 3
67 #define PLUGIN_NOTIF 5
68 #define PLUGIN_FLUSH 6
69 #define PLUGIN_FLUSH_ALL 7 /* For collectd-5.6 only */
71 #define PLUGIN_TYPES 8
73 #define PLUGIN_CONFIG 254
74 #define PLUGIN_DATASET 255
81 #define FC_CB_CREATE 0
82 #define FC_CB_DESTROY 1
87 #define log_debug(...) DEBUG("perl: " __VA_ARGS__)
88 #define log_info(...) INFO("perl: " __VA_ARGS__)
89 #define log_warn(...) WARNING("perl: " __VA_ARGS__)
90 #define log_err(...) ERROR("perl: " __VA_ARGS__)
92 /* this is defined in DynaLoader.a */
93 void boot_DynaLoader(PerlInterpreter *, CV *);
95 static XS(Collectd_plugin_register_read);
96 static XS(Collectd_plugin_register_write);
97 static XS(Collectd_plugin_register_log);
98 static XS(Collectd_plugin_register_notification);
99 static XS(Collectd_plugin_register_flush);
100 static XS(Collectd_plugin_unregister_read);
101 static XS(Collectd_plugin_unregister_write);
102 static XS(Collectd_plugin_unregister_log);
103 static XS(Collectd_plugin_unregister_notification);
104 static XS(Collectd_plugin_unregister_flush);
105 static XS(Collectd_plugin_register_ds);
106 static XS(Collectd_plugin_unregister_ds);
107 static XS(Collectd_plugin_dispatch_values);
108 static XS(Collectd_plugin_get_interval);
109 static XS(Collectd__plugin_write);
110 static XS(Collectd__plugin_flush);
111 static XS(Collectd_plugin_dispatch_notification);
112 static XS(Collectd_plugin_log);
113 static XS(Collectd__fc_register);
114 static XS(Collectd_call_by_name);
116 static int perl_read(user_data_t *ud);
117 static int perl_write(const data_set_t *ds, const value_list_t *vl,
118 user_data_t *user_data);
119 static void perl_log(int level, const char *msg, user_data_t *user_data);
120 static int perl_notify(const notification_t *notif, user_data_t *user_data);
121 static int perl_flush(cdtime_t timeout, const char *identifier,
122 user_data_t *user_data);
128 typedef struct c_ithread_s {
129 /* the thread's Perl interpreter */
130 PerlInterpreter *interp;
131 bool running; /* thread is inside Perl interpreter */
135 /* double linked list of threads */
136 struct c_ithread_s *prev;
137 struct c_ithread_s *next;
145 /* some usage stats */
146 int number_of_threads;
147 #endif /* COLLECT_DEBUG */
149 pthread_mutex_t mutex;
150 pthread_mutexattr_t mutexattr;
153 /* name / user_data for Perl matches / targets */
159 #define PFC_USER_DATA_FREE(data) \
161 sfree((data)->name); \
162 if (NULL != (data)->user_data) \
163 sv_free((data)->user_data); \
170 extern char **environ;
176 static bool register_legacy_flush = true;
178 /* if perl_threads != NULL perl_threads->head must
179 * point to the "base" thread */
180 static c_ithread_list_t *perl_threads;
182 /* the key used to store each pthread's ithread */
183 static pthread_key_t perl_thr_key;
185 static int perl_argc;
186 static char **perl_argv;
188 static char base_name[DATA_MAX_NAME_LEN] = "";
194 {"Collectd::plugin_register_read", Collectd_plugin_register_read},
195 {"Collectd::plugin_register_write", Collectd_plugin_register_write},
196 {"Collectd::plugin_register_log", Collectd_plugin_register_log},
197 {"Collectd::plugin_register_notification",
198 Collectd_plugin_register_notification},
199 {"Collectd::plugin_register_flush", Collectd_plugin_register_flush},
200 {"Collectd::plugin_unregister_read", Collectd_plugin_unregister_read},
201 {"Collectd::plugin_unregister_write", Collectd_plugin_unregister_write},
202 {"Collectd::plugin_unregister_log", Collectd_plugin_unregister_log},
203 {"Collectd::plugin_unregister_notification",
204 Collectd_plugin_unregister_notification},
205 {"Collectd::plugin_unregister_flush", Collectd_plugin_unregister_flush},
206 {"Collectd::plugin_register_data_set", Collectd_plugin_register_ds},
207 {"Collectd::plugin_unregister_data_set", Collectd_plugin_unregister_ds},
208 {"Collectd::plugin_dispatch_values", Collectd_plugin_dispatch_values},
209 {"Collectd::plugin_get_interval", Collectd_plugin_get_interval},
210 {"Collectd::_plugin_write", Collectd__plugin_write},
211 {"Collectd::_plugin_flush", Collectd__plugin_flush},
212 {"Collectd::plugin_dispatch_notification",
213 Collectd_plugin_dispatch_notification},
214 {"Collectd::plugin_log", Collectd_plugin_log},
215 {"Collectd::_fc_register", Collectd__fc_register},
216 {"Collectd::call_by_name", Collectd_call_by_name},
222 } constants[] = {{"Collectd::TYPE_INIT", PLUGIN_INIT},
223 {"Collectd::TYPE_READ", PLUGIN_READ},
224 {"Collectd::TYPE_WRITE", PLUGIN_WRITE},
225 {"Collectd::TYPE_SHUTDOWN", PLUGIN_SHUTDOWN},
226 {"Collectd::TYPE_LOG", PLUGIN_LOG},
227 {"Collectd::TYPE_NOTIF", PLUGIN_NOTIF},
228 {"Collectd::TYPE_FLUSH", PLUGIN_FLUSH},
229 {"Collectd::TYPE_CONFIG", PLUGIN_CONFIG},
230 {"Collectd::TYPE_DATASET", PLUGIN_DATASET},
231 {"Collectd::DS_TYPE_COUNTER", DS_TYPE_COUNTER},
232 {"Collectd::DS_TYPE_GAUGE", DS_TYPE_GAUGE},
233 {"Collectd::DS_TYPE_DERIVE", DS_TYPE_DERIVE},
234 {"Collectd::DS_TYPE_ABSOLUTE", DS_TYPE_ABSOLUTE},
235 {"Collectd::LOG_ERR", LOG_ERR},
236 {"Collectd::LOG_WARNING", LOG_WARNING},
237 {"Collectd::LOG_NOTICE", LOG_NOTICE},
238 {"Collectd::LOG_INFO", LOG_INFO},
239 {"Collectd::LOG_DEBUG", LOG_DEBUG},
240 {"Collectd::FC_MATCH", FC_MATCH},
241 {"Collectd::FC_TARGET", FC_TARGET},
242 {"Collectd::FC_CB_CREATE", FC_CB_CREATE},
243 {"Collectd::FC_CB_DESTROY", FC_CB_DESTROY},
244 {"Collectd::FC_CB_EXEC", FC_CB_EXEC},
245 {"Collectd::FC_MATCH_NO_MATCH", FC_MATCH_NO_MATCH},
246 {"Collectd::FC_MATCH_MATCHES", FC_MATCH_MATCHES},
247 {"Collectd::FC_TARGET_CONTINUE", FC_TARGET_CONTINUE},
248 {"Collectd::FC_TARGET_STOP", FC_TARGET_STOP},
249 {"Collectd::FC_TARGET_RETURN", FC_TARGET_RETURN},
250 {"Collectd::NOTIF_FAILURE", NOTIF_FAILURE},
251 {"Collectd::NOTIF_WARNING", NOTIF_WARNING},
252 {"Collectd::NOTIF_OKAY", NOTIF_OKAY},
255 * Helper functions for data type conversion.
270 static int hv2data_source(pTHX_ HV *hash, data_source_t *ds) {
273 if ((NULL == hash) || (NULL == ds))
276 if (NULL != (tmp = hv_fetch(hash, "name", 4, 0))) {
277 sstrncpy(ds->name, SvPV_nolen(*tmp), sizeof(ds->name));
279 log_err("hv2data_source: No DS name given.");
283 if (NULL != (tmp = hv_fetch(hash, "type", 4, 0))) {
284 ds->type = SvIV(*tmp);
286 if ((DS_TYPE_COUNTER != ds->type) && (DS_TYPE_GAUGE != ds->type) &&
287 (DS_TYPE_DERIVE != ds->type) && (DS_TYPE_ABSOLUTE != ds->type)) {
288 log_err("hv2data_source: Invalid DS type.");
292 ds->type = DS_TYPE_COUNTER;
295 if (NULL != (tmp = hv_fetch(hash, "min", 3, 0)))
296 ds->min = SvNV(*tmp);
300 if (NULL != (tmp = hv_fetch(hash, "max", 3, 0)))
301 ds->max = SvNV(*tmp);
305 } /* static int hv2data_source (HV *, data_source_t *) */
307 /* av2value converts at most "len" elements from "array" to "value". Returns the
308 * number of elements converted or zero on error. */
309 static size_t av2value(pTHX_ char *name, AV *array, value_t *value,
311 const data_set_t *ds;
313 if ((NULL == name) || (NULL == array) || (NULL == value) || (array_len == 0))
316 ds = plugin_get_ds(name);
318 log_err("av2value: Unknown dataset \"%s\"", name);
322 if (array_len < ds->ds_num) {
323 log_warn("av2value: array does not contain enough elements for type "
324 "\"%s\": got %" PRIsz ", want %" PRIsz,
325 name, array_len, ds->ds_num);
327 } else if (array_len > ds->ds_num) {
328 log_warn("av2value: array contains excess elements for type \"%s\": got "
329 "%" PRIsz ", want %" PRIsz,
330 name, array_len, ds->ds_num);
333 for (size_t i = 0; i < ds->ds_num; ++i) {
334 SV **tmp = av_fetch(array, i, 0);
337 if (DS_TYPE_COUNTER == ds->ds[i].type)
338 value[i].counter = SvIV(*tmp);
339 else if (DS_TYPE_GAUGE == ds->ds[i].type)
340 value[i].gauge = SvNV(*tmp);
341 else if (DS_TYPE_DERIVE == ds->ds[i].type)
342 value[i].derive = SvIV(*tmp);
343 else if (DS_TYPE_ABSOLUTE == ds->ds[i].type)
344 value[i].absolute = SvIV(*tmp);
351 } /* static size_t av2value (char *, AV *, value_t *, size_t) */
356 * values => [ @values ],
360 * plugin_instance => $pinstance,
361 * type_instance => $tinstance,
364 static int hv2value_list(pTHX_ HV *hash, value_list_t *vl) {
367 if ((NULL == hash) || (NULL == vl))
370 if (NULL == (tmp = hv_fetch(hash, "type", 4, 0))) {
371 log_err("hv2value_list: No type given.");
375 sstrncpy(vl->type, SvPV_nolen(*tmp), sizeof(vl->type));
377 if ((NULL == (tmp = hv_fetch(hash, "values", 6, 0))) ||
378 (!(SvROK(*tmp) && (SVt_PVAV == SvTYPE(SvRV(*tmp)))))) {
379 log_err("hv2value_list: No valid values given.");
384 AV *array = (AV *)SvRV(*tmp);
385 /* av_len returns the highest index, not the actual length. */
386 size_t array_len = (size_t)(av_len(array) + 1);
390 vl->values = calloc(array_len, sizeof(*vl->values));
392 av2value(aTHX_ vl->type, (AV *)SvRV(*tmp), vl->values, array_len);
393 if (vl->values_len == 0) {
399 if (NULL != (tmp = hv_fetch(hash, "time", 4, 0))) {
400 double t = SvNV(*tmp);
401 vl->time = DOUBLE_TO_CDTIME_T(t);
404 if (NULL != (tmp = hv_fetch(hash, "interval", 8, 0))) {
405 double t = SvNV(*tmp);
406 vl->interval = DOUBLE_TO_CDTIME_T(t);
409 if (NULL != (tmp = hv_fetch(hash, "host", 4, 0)))
410 sstrncpy(vl->host, SvPV_nolen(*tmp), sizeof(vl->host));
412 if (NULL != (tmp = hv_fetch(hash, "plugin", 6, 0)))
413 sstrncpy(vl->plugin, SvPV_nolen(*tmp), sizeof(vl->plugin));
415 if (NULL != (tmp = hv_fetch(hash, "plugin_instance", 15, 0)))
416 sstrncpy(vl->plugin_instance, SvPV_nolen(*tmp),
417 sizeof(vl->plugin_instance));
419 if (NULL != (tmp = hv_fetch(hash, "type_instance", 13, 0)))
420 sstrncpy(vl->type_instance, SvPV_nolen(*tmp), sizeof(vl->type_instance));
422 } /* static int hv2value_list (pTHX_ HV *, value_list_t *) */
424 static int av2data_set(pTHX_ AV *array, char *name, data_set_t *ds) {
427 if ((NULL == array) || (NULL == name) || (NULL == ds))
433 log_err("av2data_set: Invalid data set.");
437 ds->ds = smalloc((len + 1) * sizeof(*ds->ds));
438 ds->ds_num = len + 1;
440 for (int i = 0; i <= len; ++i) {
441 SV **elem = av_fetch(array, i, 0);
444 log_err("av2data_set: Failed to fetch data source %i.", i);
448 if (!(SvROK(*elem) && (SVt_PVHV == SvTYPE(SvRV(*elem))))) {
449 log_err("av2data_set: Invalid data source.");
453 if (-1 == hv2data_source(aTHX_(HV *) SvRV(*elem), &ds->ds[i]))
456 log_debug("av2data_set: "
457 "DS.name = \"%s\", DS.type = %i, DS.min = %f, DS.max = %f",
458 ds->ds[i].name, ds->ds[i].type, ds->ds[i].min, ds->ds[i].max);
461 sstrncpy(ds->type, name, sizeof(ds->type));
463 } /* static int av2data_set (pTHX_ AV *, data_set_t *) */
468 * severity => $severity,
474 * plugin_instance => $instance,
475 * type_instance => $type_instance,
476 * meta => [ { name => <name>, value => <value> }, ... ]
479 static int av2notification_meta(pTHX_ AV *array,
480 notification_meta_t **ret_meta) {
481 notification_meta_t *tail = NULL;
483 int len = av_len(array);
485 for (int i = 0; i <= len; ++i) {
486 SV **tmp = av_fetch(array, i, 0);
491 if (!(SvROK(*tmp) && (SVt_PVHV == SvTYPE(SvRV(*tmp))))) {
492 log_warn("av2notification_meta: Skipping invalid "
493 "meta information.");
497 HV *hash = (HV *)SvRV(*tmp);
499 notification_meta_t *m = calloc(1, sizeof(*m));
503 SV **name = hv_fetch(hash, "name", strlen("name"), 0);
505 log_warn("av2notification_meta: Skipping invalid "
506 "meta information.");
510 sstrncpy(m->name, SvPV_nolen(*name), sizeof(m->name));
512 SV **value = hv_fetch(hash, "value", strlen("value"), 0);
514 log_warn("av2notification_meta: Skipping invalid "
515 "meta information.");
521 m->nm_value.nm_double = SvNVX(*value);
522 m->type = NM_TYPE_DOUBLE;
523 } else if (SvUOK(*value)) {
524 m->nm_value.nm_unsigned_int = SvUVX(*value);
525 m->type = NM_TYPE_UNSIGNED_INT;
526 } else if (SvIOK(*value)) {
527 m->nm_value.nm_signed_int = SvIVX(*value);
528 m->type = NM_TYPE_SIGNED_INT;
530 m->nm_value.nm_string = sstrdup(SvPV_nolen(*value));
531 m->type = NM_TYPE_STRING;
543 } /* static int av2notification_meta (AV *, notification_meta_t *) */
545 static int hv2notification(pTHX_ HV *hash, notification_t *n) {
548 if ((NULL == hash) || (NULL == n))
551 if (NULL != (tmp = hv_fetch(hash, "severity", 8, 0)))
552 n->severity = SvIV(*tmp);
554 n->severity = NOTIF_FAILURE;
556 if (NULL != (tmp = hv_fetch(hash, "time", 4, 0))) {
557 double t = SvNV(*tmp);
558 n->time = DOUBLE_TO_CDTIME_T(t);
562 if (NULL != (tmp = hv_fetch(hash, "message", 7, 0)))
563 sstrncpy(n->message, SvPV_nolen(*tmp), sizeof(n->message));
565 if (NULL != (tmp = hv_fetch(hash, "host", 4, 0)))
566 sstrncpy(n->host, SvPV_nolen(*tmp), sizeof(n->host));
568 sstrncpy(n->host, hostname_g, sizeof(n->host));
570 if (NULL != (tmp = hv_fetch(hash, "plugin", 6, 0)))
571 sstrncpy(n->plugin, SvPV_nolen(*tmp), sizeof(n->plugin));
573 if (NULL != (tmp = hv_fetch(hash, "plugin_instance", 15, 0)))
574 sstrncpy(n->plugin_instance, SvPV_nolen(*tmp), sizeof(n->plugin_instance));
576 if (NULL != (tmp = hv_fetch(hash, "type", 4, 0)))
577 sstrncpy(n->type, SvPV_nolen(*tmp), sizeof(n->type));
579 if (NULL != (tmp = hv_fetch(hash, "type_instance", 13, 0)))
580 sstrncpy(n->type_instance, SvPV_nolen(*tmp), sizeof(n->type_instance));
583 while (NULL != (tmp = hv_fetch(hash, "meta", 4, 0))) {
584 if (!(SvROK(*tmp) && (SVt_PVAV == SvTYPE(SvRV(*tmp))))) {
585 log_warn("hv2notification: Ignoring invalid meta information.");
589 if (0 != av2notification_meta(aTHX_(AV *) SvRV(*tmp), &n->meta)) {
590 plugin_notification_meta_free(n->meta);
597 } /* static int hv2notification (pTHX_ HV *, notification_t *) */
599 static int data_set2av(pTHX_ data_set_t *ds, AV *array) {
600 if ((NULL == ds) || (NULL == array))
603 av_extend(array, ds->ds_num);
605 for (size_t i = 0; i < ds->ds_num; ++i) {
606 HV *source = newHV();
608 if (NULL == hv_store(source, "name", 4, newSVpv(ds->ds[i].name, 0), 0))
611 if (NULL == hv_store(source, "type", 4, newSViv(ds->ds[i].type), 0))
614 if (!isnan(ds->ds[i].min))
615 if (NULL == hv_store(source, "min", 3, newSVnv(ds->ds[i].min), 0))
618 if (!isnan(ds->ds[i].max))
619 if (NULL == hv_store(source, "max", 3, newSVnv(ds->ds[i].max), 0))
622 if (NULL == av_store(array, i, newRV_noinc((SV *)source)))
626 } /* static int data_set2av (data_set_t *, AV *) */
628 static int value_list2hv(pTHX_ value_list_t *vl, data_set_t *ds, HV *hash) {
632 if ((NULL == vl) || (NULL == ds) || (NULL == hash))
636 /* av_extend takes the last *index* to which the array should be extended. */
637 av_extend(values, vl->values_len - 1);
639 assert(ds->ds_num == vl->values_len);
640 for (i = 0; i < vl->values_len; ++i) {
643 if (DS_TYPE_COUNTER == ds->ds[i].type)
644 val = newSViv(vl->values[i].counter);
645 else if (DS_TYPE_GAUGE == ds->ds[i].type)
646 val = newSVnv(vl->values[i].gauge);
647 else if (DS_TYPE_DERIVE == ds->ds[i].type)
648 val = newSViv(vl->values[i].derive);
649 else if (DS_TYPE_ABSOLUTE == ds->ds[i].type)
650 val = newSViv(vl->values[i].absolute);
652 if (NULL == av_store(values, i, val)) {
658 if (NULL == hv_store(hash, "values", 6, newRV_noinc((SV *)values), 0))
662 double t = CDTIME_T_TO_DOUBLE(vl->time);
663 if (NULL == hv_store(hash, "time", 4, newSVnv(t), 0))
668 double t = CDTIME_T_TO_DOUBLE(vl->interval);
669 if (NULL == hv_store(hash, "interval", 8, newSVnv(t), 0))
673 if ('\0' != vl->host[0])
674 if (NULL == hv_store(hash, "host", 4, newSVpv(vl->host, 0), 0))
677 if ('\0' != vl->plugin[0])
678 if (NULL == hv_store(hash, "plugin", 6, newSVpv(vl->plugin, 0), 0))
681 if ('\0' != vl->plugin_instance[0])
682 if (NULL == hv_store(hash, "plugin_instance", 15,
683 newSVpv(vl->plugin_instance, 0), 0))
686 if ('\0' != vl->type[0])
687 if (NULL == hv_store(hash, "type", 4, newSVpv(vl->type, 0), 0))
690 if ('\0' != vl->type_instance[0])
692 hv_store(hash, "type_instance", 13, newSVpv(vl->type_instance, 0), 0))
695 } /* static int value2av (value_list_t *, data_set_t *, HV *) */
697 static int notification_meta2av(pTHX_ notification_meta_t *meta, AV *array) {
699 for (notification_meta_t *m = meta; m != NULL; m = m->next) {
703 av_extend(array, meta_num);
705 for (int i = 0; NULL != meta; meta = meta->next, ++i) {
709 if (NULL == hv_store(m, "name", 4, newSVpv(meta->name, 0), 0))
712 if (NM_TYPE_STRING == meta->type)
713 value = newSVpv(meta->nm_value.nm_string, 0);
714 else if (NM_TYPE_SIGNED_INT == meta->type)
715 value = newSViv(meta->nm_value.nm_signed_int);
716 else if (NM_TYPE_UNSIGNED_INT == meta->type)
717 value = newSVuv(meta->nm_value.nm_unsigned_int);
718 else if (NM_TYPE_DOUBLE == meta->type)
719 value = newSVnv(meta->nm_value.nm_double);
720 else if (NM_TYPE_BOOLEAN == meta->type)
721 value = meta->nm_value.nm_boolean ? &PL_sv_yes : &PL_sv_no;
725 if (NULL == hv_store(m, "value", 5, value, 0)) {
730 if (NULL == av_store(array, i, newRV_noinc((SV *)m))) {
737 } /* static int notification_meta2av (notification_meta_t *, AV *) */
739 static int notification2hv(pTHX_ notification_t *n, HV *hash) {
740 if (NULL == hv_store(hash, "severity", 8, newSViv(n->severity), 0))
744 double t = CDTIME_T_TO_DOUBLE(n->time);
745 if (NULL == hv_store(hash, "time", 4, newSVnv(t), 0))
749 if ('\0' != *n->message)
750 if (NULL == hv_store(hash, "message", 7, newSVpv(n->message, 0), 0))
753 if ('\0' != *n->host)
754 if (NULL == hv_store(hash, "host", 4, newSVpv(n->host, 0), 0))
757 if ('\0' != *n->plugin)
758 if (NULL == hv_store(hash, "plugin", 6, newSVpv(n->plugin, 0), 0))
761 if ('\0' != *n->plugin_instance)
762 if (NULL == hv_store(hash, "plugin_instance", 15,
763 newSVpv(n->plugin_instance, 0), 0))
766 if ('\0' != *n->type)
767 if (NULL == hv_store(hash, "type", 4, newSVpv(n->type, 0), 0))
770 if ('\0' != *n->type_instance)
772 hv_store(hash, "type_instance", 13, newSVpv(n->type_instance, 0), 0))
775 if (NULL != n->meta) {
777 if ((0 != notification_meta2av(aTHX_ n->meta, meta)) ||
778 (NULL == hv_store(hash, "meta", 4, newRV_noinc((SV *)meta), 0))) {
785 } /* static int notification2hv (notification_t *, HV *) */
787 static int oconfig_item2hv(pTHX_ oconfig_item_t *ci, HV *hash) {
791 if (NULL == hv_store(hash, "key", 3, newSVpv(ci->key, 0), 0))
795 if (0 < ci->values_num)
796 av_extend(values, ci->values_num);
798 if (NULL == hv_store(hash, "values", 6, newRV_noinc((SV *)values), 0)) {
804 for (int i = 0; i < ci->values_num; ++i) {
807 switch (ci->values[i].type) {
808 case OCONFIG_TYPE_STRING:
809 value = newSVpv(ci->values[i].value.string, 0);
811 case OCONFIG_TYPE_NUMBER:
812 value = newSVnv((NV)ci->values[i].value.number);
814 case OCONFIG_TYPE_BOOLEAN:
815 value = ci->values[i].value.boolean ? &PL_sv_yes : &PL_sv_no;
818 log_err("oconfig_item2hv: Invalid value type %i.", ci->values[i].type);
819 value = &PL_sv_undef;
822 if (NULL == av_store(values, i, value)) {
828 /* ignoring 'parent' member which is uninteresting in this case */
831 if (0 < ci->children_num)
832 av_extend(children, ci->children_num);
834 if (NULL == hv_store(hash, "children", 8, newRV_noinc((SV *)children), 0)) {
840 for (int i = 0; i < ci->children_num; ++i) {
843 if (0 != oconfig_item2hv(aTHX_ ci->children + i, child)) {
849 if (NULL == av_store(children, i, newRV_noinc((SV *)child))) {
856 } /* static int oconfig_item2hv (pTHX_ oconfig_item_t *, HV *) */
859 * Internal functions.
862 static char *get_module_name(char *buf, size_t buf_len, const char *module) {
864 if (base_name[0] == '\0')
865 status = snprintf(buf, buf_len, "%s", module);
867 status = snprintf(buf, buf_len, "%s::%s", base_name, module);
868 if ((status < 0) || ((unsigned int)status >= buf_len))
871 } /* char *get_module_name */
874 * Add a plugin's data set definition.
876 static int pplugin_register_data_set(pTHX_ char *name, AV *dataset) {
881 if ((NULL == name) || (NULL == dataset))
884 if (0 != av2data_set(aTHX_ dataset, name, &ds))
887 ret = plugin_register_data_set(&ds);
891 } /* static int pplugin_register_data_set (char *, SV *) */
894 * Remove a plugin's data set definition.
896 static int pplugin_unregister_data_set(char *name) {
899 return plugin_unregister_data_set(name);
900 } /* static int pplugin_unregister_data_set (char *) */
903 * Submit the values to the write functions.
905 static int pplugin_dispatch_values(pTHX_ HV *values) {
906 value_list_t vl = VALUE_LIST_INIT;
913 if (0 != hv2value_list(aTHX_ values, &vl))
916 ret = plugin_dispatch_values(&vl);
920 } /* static int pplugin_dispatch_values (char *, HV *) */
923 * Submit the values to a single write function.
925 static int pplugin_write(pTHX_ const char *plugin, AV *data_set, HV *values) {
927 value_list_t vl = VALUE_LIST_INIT;
934 if (0 != hv2value_list(aTHX_ values, &vl))
937 if ((NULL != data_set) && (0 != av2data_set(aTHX_ data_set, vl.type, &ds)))
940 ret = plugin_write(plugin, NULL == data_set ? NULL : &ds, &vl);
942 log_warn("Dispatching value to plugin \"%s\" failed with status %i.",
943 NULL == plugin ? "<any>" : plugin, ret);
945 if (NULL != data_set)
949 } /* static int pplugin_write (const char *plugin, HV *, HV *) */
952 * Dispatch a notification.
954 static int pplugin_dispatch_notification(pTHX_ HV *notif) {
955 notification_t n = {0};
962 if (0 != hv2notification(aTHX_ notif, &n))
965 ret = plugin_dispatch_notification(&n);
966 plugin_notification_meta_free(n.meta);
968 } /* static int pplugin_dispatch_notification (HV *) */
971 * Call perl sub with thread locking flags handled.
973 static int call_pv_locked(pTHX_ const char *sub_name) {
977 c_ithread_t *t = (c_ithread_t *)pthread_getspecific(perl_thr_key);
978 if (t == NULL) /* thread destroyed */
981 old_running = t->running;
985 t->running = old_running;
989 ret = call_pv(sub_name, G_SCALAR | G_EVAL);
991 t->running = old_running;
993 } /* static int call_pv_locked (pTHX, *sub_name) */
996 * Call all working functions of the given type.
998 static int pplugin_call(pTHX_ int type, ...) {
1007 if ((type < 0) || (type >= PLUGIN_TYPES))
1017 if (PLUGIN_READ == type) {
1018 subname = va_arg(ap, char *);
1019 } else if (PLUGIN_WRITE == type) {
1026 subname = va_arg(ap, char *);
1028 * $_[0] = $plugin_type;
1043 * values => [ $v1, ... ],
1045 * host => $hostname,
1046 * plugin => $plugin,
1048 * plugin_instance => $instance,
1049 * type_instance => $type_instance
1052 ds = va_arg(ap, data_set_t *);
1053 vl = va_arg(ap, value_list_t *);
1055 if (-1 == data_set2av(aTHX_ ds, pds)) {
1058 pds = (AV *)&PL_sv_undef;
1062 if (-1 == value_list2hv(aTHX_ vl, ds, pvl)) {
1065 pvl = (HV *)&PL_sv_undef;
1069 XPUSHs(sv_2mortal(newSVpv(ds->type, 0)));
1070 XPUSHs(sv_2mortal(newRV_noinc((SV *)pds)));
1071 XPUSHs(sv_2mortal(newRV_noinc((SV *)pvl)));
1072 } else if (PLUGIN_LOG == type) {
1073 subname = va_arg(ap, char *);
1079 XPUSHs(sv_2mortal(newSViv(va_arg(ap, int))));
1080 XPUSHs(sv_2mortal(newSVpv(va_arg(ap, char *), 0)));
1081 } else if (PLUGIN_NOTIF == type) {
1083 HV *notif = newHV();
1085 subname = va_arg(ap, char *);
1089 * severity => $severity,
1093 * plugin => $plugin,
1095 * plugin_instance => $instance,
1096 * type_instance => $type_instance
1099 n = va_arg(ap, notification_t *);
1101 if (-1 == notification2hv(aTHX_ n, notif)) {
1104 notif = (HV *)&PL_sv_undef;
1108 XPUSHs(sv_2mortal(newRV_noinc((SV *)notif)));
1109 } else if (PLUGIN_FLUSH == type) {
1111 subname = va_arg(ap, char *);
1114 * $_[1] = $identifier;
1116 timeout = va_arg(ap, cdtime_t);
1118 XPUSHs(sv_2mortal(newSVnv(CDTIME_T_TO_DOUBLE(timeout))));
1119 XPUSHs(sv_2mortal(newSVpv(va_arg(ap, char *), 0)));
1120 } else if (PLUGIN_FLUSH_ALL == type) {
1122 subname = "Collectd::plugin_call_all";
1125 * $_[1] = $identifier;
1127 timeout = va_arg(ap, cdtime_t);
1129 XPUSHs(sv_2mortal(newSViv((IV)PLUGIN_FLUSH)));
1130 XPUSHs(sv_2mortal(newSVnv(CDTIME_T_TO_DOUBLE(timeout))));
1131 XPUSHs(sv_2mortal(newSVpv(va_arg(ap, char *), 0)));
1132 } else if (PLUGIN_INIT == type) {
1133 subname = "Collectd::plugin_call_all";
1134 XPUSHs(sv_2mortal(newSViv((IV)type)));
1135 } else if (PLUGIN_SHUTDOWN == type) {
1136 subname = "Collectd::plugin_call_all";
1137 XPUSHs(sv_2mortal(newSViv((IV)type)));
1138 } else { /* Unknown type. Run 'plugin_call_all' and make compiler happy */
1139 subname = "Collectd::plugin_call_all";
1140 XPUSHs(sv_2mortal(newSViv((IV)type)));
1145 retvals = call_pv_locked(aTHX_ subname);
1148 if (SvTRUE(ERRSV)) {
1149 if (PLUGIN_LOG != type)
1150 ERROR("perl: %s error: %s", subname, SvPV_nolen(ERRSV));
1152 } else if (0 < retvals) {
1164 } /* static int pplugin_call (int, ...) */
1167 * collectd's Perl interpreter based thread implementation.
1169 * This has been inspired by Perl's ithreads introduced in version 5.6.0.
1172 /* must be called with perl_threads->mutex locked */
1173 static void c_ithread_destroy(c_ithread_t *ithread) {
1174 dTHXa(ithread->interp);
1176 assert(NULL != perl_threads);
1178 PERL_SET_CONTEXT(aTHX);
1179 /* Mark as running to avoid deadlock:
1180 c_ithread_destroy -> log_debug -> perl_log()
1182 ithread->running = true;
1183 log_debug("Shutting down Perl interpreter %p...", aTHX);
1188 --perl_threads->number_of_threads;
1189 #endif /* COLLECT_DEBUG */
1191 perl_destruct(aTHX);
1194 if (NULL == ithread->prev)
1195 perl_threads->head = ithread->next;
1197 ithread->prev->next = ithread->next;
1199 if (NULL == ithread->next)
1200 perl_threads->tail = ithread->prev;
1202 ithread->next->prev = ithread->prev;
1206 } /* static void c_ithread_destroy (c_ithread_t *) */
1208 static void c_ithread_destructor(void *arg) {
1209 c_ithread_t *ithread = (c_ithread_t *)arg;
1210 c_ithread_t *t = NULL;
1212 if (NULL == perl_threads)
1215 pthread_mutex_lock(&perl_threads->mutex);
1217 for (t = perl_threads->head; NULL != t; t = t->next)
1221 /* the ithread no longer exists */
1223 pthread_mutex_unlock(&perl_threads->mutex);
1227 c_ithread_destroy(ithread);
1229 pthread_mutex_unlock(&perl_threads->mutex);
1231 } /* static void c_ithread_destructor (void *) */
1233 /* must be called with perl_threads->mutex locked */
1234 static c_ithread_t *c_ithread_create(PerlInterpreter *base) {
1235 c_ithread_t *t = NULL;
1238 assert(NULL != perl_threads);
1240 t = smalloc(sizeof(*t));
1241 memset(t, 0, sizeof(c_ithread_t));
1243 t->interp = (NULL == base) ? NULL : perl_clone(base, CLONEf_KEEP_PTR_TABLE);
1247 if ((NULL != base) && (NULL != PL_endav)) {
1254 ++perl_threads->number_of_threads;
1255 #endif /* COLLECT_DEBUG */
1259 if (NULL == perl_threads->tail) {
1260 perl_threads->head = t;
1263 perl_threads->tail->next = t;
1264 t->prev = perl_threads->tail;
1267 t->pthread = pthread_self();
1269 t->shutdown = false;
1270 perl_threads->tail = t;
1272 pthread_setspecific(perl_thr_key, (const void *)t);
1274 } /* static c_ithread_t *c_ithread_create (PerlInterpreter *) */
1277 * Filter chains implementation.
1280 static int fc_call(pTHX_ int type, int cb_type, pfc_user_data_t *data, ...) {
1286 notification_meta_t **meta = NULL;
1291 if ((type < 0) || (type >= FC_TYPES))
1294 if ((cb_type < 0) || (cb_type >= FC_CB_TYPES))
1304 XPUSHs(sv_2mortal(newSViv((IV)type)));
1305 XPUSHs(sv_2mortal(newSVpv(data->name, 0)));
1306 XPUSHs(sv_2mortal(newSViv((IV)cb_type)));
1308 if (FC_CB_CREATE == cb_type) {
1311 * $_[1] = $user_data;
1314 HV *config = newHV();
1316 ci = va_arg(ap, oconfig_item_t *);
1318 if (0 != oconfig_item2hv(aTHX_ ci, config)) {
1321 config = (HV *)&PL_sv_undef;
1325 XPUSHs(sv_2mortal(newRV_noinc((SV *)config)));
1326 } else if (FC_CB_DESTROY == cb_type) {
1328 * $_[1] = $user_data;
1331 /* nothing to be done - the user data pointer
1332 * is pushed onto the stack later */
1333 } else if (FC_CB_EXEC == cb_type) {
1338 * $_[3] = $user_data;
1346 ds = va_arg(ap, data_set_t *);
1347 vl = va_arg(ap, value_list_t *);
1348 meta = va_arg(ap, notification_meta_t **);
1350 if (0 != data_set2av(aTHX_ ds, pds)) {
1353 pds = (AV *)&PL_sv_undef;
1357 if (0 != value_list2hv(aTHX_ vl, ds, pvl)) {
1360 pvl = (HV *)&PL_sv_undef;
1367 if (0 != notification_meta2av(aTHX_ * meta, pmeta)) {
1370 pmeta = (AV *)&PL_sv_undef;
1374 pmeta = (AV *)&PL_sv_undef;
1377 XPUSHs(sv_2mortal(newRV_noinc((SV *)pds)));
1378 XPUSHs(sv_2mortal(newRV_noinc((SV *)pvl)));
1379 XPUSHs(sv_2mortal(newRV_noinc((SV *)pmeta)));
1382 XPUSHs(sv_2mortal(newRV_inc(data->user_data)));
1386 retvals = call_pv_locked(aTHX_ "Collectd::fc_call");
1388 if ((FC_CB_EXEC == cb_type) && (meta != NULL)) {
1389 assert(pmeta != NULL);
1391 plugin_notification_meta_free(*meta);
1392 av2notification_meta(aTHX_ pmeta, meta);
1396 if (SvTRUE(ERRSV)) {
1397 ERROR("perl: Collectd::fc_call error: %s", SvPV_nolen(ERRSV));
1399 } else if (0 < retvals) {
1402 /* the exec callbacks return a status, while
1403 * the others return a boolean value */
1404 if (FC_CB_EXEC == cb_type)
1406 else if (!SvTRUE(tmp))
1416 } /* static int fc_call (int, int, pfc_user_data_t *, ...) */
1418 static int fc_create(int type, const oconfig_item_t *ci, void **user_data) {
1419 pfc_user_data_t *data;
1425 if (NULL == perl_threads)
1429 c_ithread_t *t = NULL;
1431 pthread_mutex_lock(&perl_threads->mutex);
1432 t = c_ithread_create(perl_threads->head->interp);
1433 pthread_mutex_unlock(&perl_threads->mutex);
1438 log_debug("fc_create: c_ithread: interp = %p (active threads: %i)", aTHX,
1439 perl_threads->number_of_threads);
1441 if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
1442 log_warn("A \"%s\" block expects a single string argument.",
1443 (FC_MATCH == type) ? "Match" : "Target");
1447 data = smalloc(sizeof(*data));
1448 data->name = sstrdup(ci->values[0].value.string);
1449 data->user_data = newSV(0);
1451 ret = fc_call(aTHX_ type, FC_CB_CREATE, data, ci);
1454 PFC_USER_DATA_FREE(data);
1458 } /* static int fc_create (int, const oconfig_item_t *, void **) */
1460 static int fc_destroy(int type, void **user_data) {
1461 pfc_user_data_t *data = *(pfc_user_data_t **)user_data;
1467 if ((NULL == perl_threads) || (NULL == data))
1471 c_ithread_t *t = NULL;
1473 pthread_mutex_lock(&perl_threads->mutex);
1474 t = c_ithread_create(perl_threads->head->interp);
1475 pthread_mutex_unlock(&perl_threads->mutex);
1480 log_debug("fc_destroy: c_ithread: interp = %p (active threads: %i)", aTHX,
1481 perl_threads->number_of_threads);
1483 ret = fc_call(aTHX_ type, FC_CB_DESTROY, data);
1485 PFC_USER_DATA_FREE(data);
1488 } /* static int fc_destroy (int, void **) */
1490 static int fc_exec(int type, const data_set_t *ds, const value_list_t *vl,
1491 notification_meta_t **meta, void **user_data) {
1492 pfc_user_data_t *data = *(pfc_user_data_t **)user_data;
1496 if (NULL == perl_threads)
1499 assert(NULL != data);
1502 c_ithread_t *t = NULL;
1504 pthread_mutex_lock(&perl_threads->mutex);
1505 t = c_ithread_create(perl_threads->head->interp);
1506 pthread_mutex_unlock(&perl_threads->mutex);
1511 log_debug("fc_exec: c_ithread: interp = %p (active threads: %i)", aTHX,
1512 perl_threads->number_of_threads);
1514 return fc_call(aTHX_ type, FC_CB_EXEC, data, ds, vl, meta);
1515 } /* static int fc_exec (int, const data_set_t *, const value_list_t *,
1516 notification_meta_t **, void **) */
1518 static int pmatch_create(const oconfig_item_t *ci, void **user_data) {
1519 return fc_create(FC_MATCH, ci, user_data);
1520 } /* static int pmatch_create (const oconfig_item_t *, void **) */
1522 static int pmatch_destroy(void **user_data) {
1523 return fc_destroy(FC_MATCH, user_data);
1524 } /* static int pmatch_destroy (void **) */
1526 static int pmatch_match(const data_set_t *ds, const value_list_t *vl,
1527 notification_meta_t **meta, void **user_data) {
1528 return fc_exec(FC_MATCH, ds, vl, meta, user_data);
1529 } /* static int pmatch_match (const data_set_t *, const value_list_t *,
1530 notification_meta_t **, void **) */
1532 static match_proc_t pmatch = {pmatch_create, pmatch_destroy, pmatch_match};
1534 static int ptarget_create(const oconfig_item_t *ci, void **user_data) {
1535 return fc_create(FC_TARGET, ci, user_data);
1536 } /* static int ptarget_create (const oconfig_item_t *, void **) */
1538 static int ptarget_destroy(void **user_data) {
1539 return fc_destroy(FC_TARGET, user_data);
1540 } /* static int ptarget_destroy (void **) */
1542 static int ptarget_invoke(const data_set_t *ds, value_list_t *vl,
1543 notification_meta_t **meta, void **user_data) {
1544 return fc_exec(FC_TARGET, ds, vl, meta, user_data);
1545 } /* static int ptarget_invoke (const data_set_t *, value_list_t *,
1546 notification_meta_t **, void **) */
1548 static target_proc_t ptarget = {ptarget_create, ptarget_destroy,
1552 * Exported Perl API.
1555 static void _plugin_register_generic_userdata(pTHX, int type,
1558 user_data_t userdata;
1564 log_err("Usage: Collectd::plugin_register_%s(pluginname, subname)", desc);
1569 log_err("Collectd::plugin_register_%s(pluginname, subname): "
1570 "Invalid pluginname",
1575 log_err("Collectd::plugin_register_%s(pluginname, subname): "
1581 /* Use pluginname as-is to allow flush a single perl plugin */
1582 pluginname = SvPV_nolen(ST(0));
1584 log_debug("Collectd::plugin_register_%s: "
1585 "plugin = \"%s\", sub = \"%s\"",
1586 desc, pluginname, SvPV_nolen(ST(1)));
1588 memset(&userdata, 0, sizeof(userdata));
1589 userdata.data = strdup(SvPV_nolen(ST(1)));
1590 userdata.free_func = free;
1592 if (PLUGIN_READ == type) {
1593 ret = plugin_register_complex_read(
1595 pluginname, perl_read, plugin_get_interval(), /* Default interval */
1597 } else if (PLUGIN_WRITE == type) {
1598 ret = plugin_register_write(pluginname, perl_write, &userdata);
1599 } else if (PLUGIN_LOG == type) {
1600 ret = plugin_register_log(pluginname, perl_log, &userdata);
1601 } else if (PLUGIN_NOTIF == type) {
1602 ret = plugin_register_notification(pluginname, perl_notify, &userdata);
1603 } else if (PLUGIN_FLUSH == type) {
1604 if (1 == register_legacy_flush) { /* For collectd-5.7 only, #1731 */
1605 register_legacy_flush = 0;
1606 ret = plugin_register_flush("perl", perl_flush, /* user_data = */ NULL);
1610 ret = plugin_register_flush(pluginname, perl_flush, &userdata);
1612 free(userdata.data);
1622 } /* static void _plugin_register_generic_userdata ( ... ) */
1625 * Collectd::plugin_register_TYPE (pluginname, subname).
1628 * name of the perl plugin
1631 * name of the plugin's subroutine that does the work
1634 static XS(Collectd_plugin_register_read) {
1635 _plugin_register_generic_userdata(aTHX, PLUGIN_READ, "read");
1638 static XS(Collectd_plugin_register_write) {
1639 _plugin_register_generic_userdata(aTHX, PLUGIN_WRITE, "write");
1642 static XS(Collectd_plugin_register_log) {
1643 _plugin_register_generic_userdata(aTHX, PLUGIN_LOG, "log");
1646 static XS(Collectd_plugin_register_notification) {
1647 _plugin_register_generic_userdata(aTHX, PLUGIN_NOTIF, "notification");
1650 static XS(Collectd_plugin_register_flush) {
1651 _plugin_register_generic_userdata(aTHX, PLUGIN_FLUSH, "flush");
1654 typedef int perl_unregister_function_t(const char *name);
1656 static void _plugin_unregister_generic(pTHX, perl_unregister_function_t *unreg,
1661 log_err("Usage: Collectd::plugin_unregister_%s(pluginname)", desc);
1666 log_err("Collectd::plugin_unregister_%s(pluginname): "
1667 "Invalid pluginname",
1672 log_debug("Collectd::plugin_unregister_%s: plugin = \"%s\"", desc,
1675 unreg(SvPV_nolen(ST(0)));
1678 } /* static void _plugin_unregister_generic ( ... ) */
1681 * Collectd::plugin_unregister_TYPE (pluginname).
1684 * type of callback to be unregistered: read, write, log, notification, flush
1687 * name of the perl plugin
1690 static XS(Collectd_plugin_unregister_read) {
1691 _plugin_unregister_generic(aTHX, plugin_unregister_read, "read");
1694 static XS(Collectd_plugin_unregister_write) {
1695 _plugin_unregister_generic(aTHX, plugin_unregister_write, "write");
1698 static XS(Collectd_plugin_unregister_log) {
1699 _plugin_unregister_generic(aTHX, plugin_unregister_log, "log");
1702 static XS(Collectd_plugin_unregister_notification) {
1703 _plugin_unregister_generic(aTHX, plugin_unregister_notification,
1707 static XS(Collectd_plugin_unregister_flush) {
1708 _plugin_unregister_generic(aTHX, plugin_unregister_flush, "flush");
1712 * Collectd::plugin_register_data_set (type, dataset).
1715 * type of the dataset
1718 * dataset to be registered
1720 static XS(Collectd_plugin_register_ds) {
1726 log_warn("Using plugin_register() to register new data-sets is "
1727 "deprecated - add new entries to a custom types.db instead.");
1730 log_err("Usage: Collectd::plugin_register_data_set(type, dataset)");
1734 log_debug("Collectd::plugin_register_data_set: "
1735 "type = \"%s\", dataset = \"%s\"",
1736 SvPV_nolen(ST(0)), SvPV_nolen(ST(1)));
1740 if (SvROK(data) && (SVt_PVAV == SvTYPE(SvRV(data)))) {
1741 ret = pplugin_register_data_set(aTHX_ SvPV_nolen(ST(0)), (AV *)SvRV(data));
1743 log_err("Collectd::plugin_register_data_set: Invalid data.");
1751 } /* static XS (Collectd_plugin_register_ds) */
1754 * Collectd::plugin_unregister_data_set (type).
1757 * type of the dataset
1759 static XS(Collectd_plugin_unregister_ds) {
1763 log_err("Usage: Collectd::plugin_unregister_data_set(type)");
1767 log_debug("Collectd::plugin_unregister_data_set: type = \"%s\"",
1770 if (0 == pplugin_unregister_data_set(SvPV_nolen(ST(0))))
1774 } /* static XS (Collectd_plugin_register_ds) */
1777 * Collectd::plugin_dispatch_values (name, values).
1780 * name of the plugin
1783 * value list to submit
1785 static XS(Collectd_plugin_dispatch_values) {
1793 log_err("Usage: Collectd::plugin_dispatch_values(values)");
1797 log_debug("Collectd::plugin_dispatch_values: values=\"%s\"",
1798 SvPV_nolen(ST(/* stack index = */ 0)));
1800 values = ST(/* stack index = */ 0);
1805 /* Make sure the argument is a hash reference. */
1806 if (!(SvROK(values) && (SVt_PVHV == SvTYPE(SvRV(values))))) {
1807 log_err("Collectd::plugin_dispatch_values: Invalid values.");
1811 ret = pplugin_dispatch_values(aTHX_(HV *) SvRV(values));
1817 } /* static XS (Collectd_plugin_dispatch_values) */
1820 * Collectd::plugin_get_interval ().
1822 static XS(Collectd_plugin_get_interval) {
1825 /* make sure we don't get any unused variable warnings for 'items';
1826 * don't abort, though */
1828 log_err("Usage: Collectd::plugin_get_interval()");
1830 XSRETURN_NV((NV)CDTIME_T_TO_DOUBLE(plugin_get_interval()));
1831 } /* static XS (Collectd_plugin_get_interval) */
1833 /* Collectd::plugin_write (plugin, ds, vl).
1836 * name of the plugin to call, may be 'undef'
1839 * data-set that describes the submitted values, may be 'undef'
1842 * value-list to be written
1844 static XS(Collectd__plugin_write) {
1854 log_err("Usage: Collectd::plugin_write(plugin, ds, vl)");
1858 log_debug("Collectd::plugin_write: plugin=\"%s\", ds=\"%s\", vl=\"%s\"",
1859 SvPV_nolen(ST(0)), SvOK(ST(1)) ? SvPV_nolen(ST(1)) : "",
1865 plugin = SvPV_nolen(ST(0));
1868 if (SvROK(ds) && (SVt_PVAV == SvTYPE(SvRV(ds))))
1869 ds_array = (AV *)SvRV(ds);
1873 log_err("Collectd::plugin_write: Invalid data-set.");
1878 if (!(SvROK(vl) && (SVt_PVHV == SvTYPE(SvRV(vl))))) {
1879 log_err("Collectd::plugin_write: Invalid value-list.");
1883 ret = pplugin_write(aTHX_ plugin, ds_array, (HV *)SvRV(vl));
1889 } /* static XS (Collectd__plugin_write) */
1892 * Collectd::_plugin_flush (plugin, timeout, identifier).
1895 * name of the plugin to flush
1898 * timeout to use when flushing the data
1901 * data-set identifier to flush
1903 static XS(Collectd__plugin_flush) {
1904 char *plugin = NULL;
1911 log_err("Usage: Collectd::_plugin_flush(plugin, timeout, id)");
1916 plugin = SvPV_nolen(ST(0));
1919 timeout = (int)SvIV(ST(1));
1922 id = SvPV_nolen(ST(2));
1924 log_debug("Collectd::_plugin_flush: plugin = \"%s\", timeout = %i, "
1926 plugin, timeout, id);
1928 if (0 == plugin_flush(plugin, timeout, id))
1932 } /* static XS (Collectd__plugin_flush) */
1935 * Collectd::plugin_dispatch_notification (notif).
1938 * notification to dispatch
1940 static XS(Collectd_plugin_dispatch_notification) {
1948 log_err("Usage: Collectd::plugin_dispatch_notification(notif)");
1952 log_debug("Collectd::plugin_dispatch_notification: notif = \"%s\"",
1957 if (!(SvROK(notif) && (SVt_PVHV == SvTYPE(SvRV(notif))))) {
1958 log_err("Collectd::plugin_dispatch_notification: Invalid notif.");
1962 ret = pplugin_dispatch_notification(aTHX_(HV *) SvRV(notif));
1968 } /* static XS (Collectd_plugin_dispatch_notification) */
1971 * Collectd::plugin_log (level, message).
1974 * log level (LOG_DEBUG, ... LOG_ERR)
1979 static XS(Collectd_plugin_log) {
1983 log_err("Usage: Collectd::plugin_log(level, message)");
1987 plugin_log(SvIV(ST(0)), "%s", SvPV_nolen(ST(1)));
1989 } /* static XS (Collectd_plugin_log) */
1992 * Collectd::_fc_register (type, name)
2000 static XS(Collectd__fc_register) {
2009 log_err("Usage: Collectd::_fc_register(type, name)");
2014 name = SvPV_nolen(ST(1));
2016 if (FC_MATCH == type)
2017 ret = fc_register_match(name, pmatch);
2018 else if (FC_TARGET == type)
2019 ret = fc_register_target(name, ptarget);
2025 } /* static XS (Collectd_fc_register) */
2028 * Collectd::call_by_name (...).
2030 * Call a Perl sub identified by its name passed through $Collectd::cb_name.
2032 static XS(Collectd_call_by_name) {
2036 if (NULL == (tmp = get_sv("Collectd::cb_name", 0))) {
2037 sv_setpv(get_sv("@", 1), "cb_name has not been set");
2042 name = SvPV_nolen(tmp);
2044 if (NULL == get_cv(name, 0)) {
2045 sv_setpvf(get_sv("@", 1), "unknown callback \"%s\"", name);
2050 /* simply pass on the subroutine call without touching the stack,
2051 * thus leaving any arguments and return values in place */
2053 } /* static XS (Collectd_call_by_name) */
2056 * Interface to collectd.
2059 static int perl_init(void) {
2063 if (NULL == perl_threads)
2067 c_ithread_t *t = NULL;
2069 pthread_mutex_lock(&perl_threads->mutex);
2070 t = c_ithread_create(perl_threads->head->interp);
2071 pthread_mutex_unlock(&perl_threads->mutex);
2076 log_debug("perl_init: c_ithread: interp = %p (active threads: %i)", aTHX,
2077 perl_threads->number_of_threads);
2079 /* Lock the base thread to avoid race conditions with c_ithread_create().
2080 * See https://github.com/collectd/collectd/issues/9 and
2081 * https://github.com/collectd/collectd/issues/1706 for details.
2083 assert(aTHX == perl_threads->head->interp);
2084 pthread_mutex_lock(&perl_threads->mutex);
2086 status = pplugin_call(aTHX_ PLUGIN_INIT);
2088 pthread_mutex_unlock(&perl_threads->mutex);
2091 } /* static int perl_init (void) */
2093 static int perl_read(user_data_t *user_data) {
2096 if (NULL == perl_threads)
2100 c_ithread_t *t = NULL;
2102 pthread_mutex_lock(&perl_threads->mutex);
2103 t = c_ithread_create(perl_threads->head->interp);
2104 pthread_mutex_unlock(&perl_threads->mutex);
2109 /* Assert that we're not running as the base thread. Otherwise, we might
2110 * run into concurrency issues with c_ithread_create(). See
2111 * https://github.com/collectd/collectd/issues/9 for details. */
2112 assert(aTHX != perl_threads->head->interp);
2114 log_debug("perl_read: c_ithread: interp = %p (active threads: %i)", aTHX,
2115 perl_threads->number_of_threads);
2117 return pplugin_call(aTHX_ PLUGIN_READ, user_data->data);
2118 } /* static int perl_read (user_data_t *user_data) */
2120 static int perl_write(const data_set_t *ds, const value_list_t *vl,
2121 user_data_t *user_data) {
2125 if (NULL == perl_threads)
2129 c_ithread_t *t = NULL;
2131 pthread_mutex_lock(&perl_threads->mutex);
2132 t = c_ithread_create(perl_threads->head->interp);
2133 pthread_mutex_unlock(&perl_threads->mutex);
2138 /* Lock the base thread if this is not called from one of the read threads
2139 * to avoid race conditions with c_ithread_create(). See
2140 * https://github.com/collectd/collectd/issues/9 for details. */
2141 if (aTHX == perl_threads->head->interp)
2142 pthread_mutex_lock(&perl_threads->mutex);
2144 log_debug("perl_write: c_ithread: interp = %p (active threads: %i)", aTHX,
2145 perl_threads->number_of_threads);
2146 status = pplugin_call(aTHX_ PLUGIN_WRITE, user_data->data, ds, vl);
2148 if (aTHX == perl_threads->head->interp)
2149 pthread_mutex_unlock(&perl_threads->mutex);
2152 } /* static int perl_write (const data_set_t *, const value_list_t *) */
2154 static void perl_log(int level, const char *msg, user_data_t *user_data) {
2157 if (NULL == perl_threads)
2161 c_ithread_t *t = NULL;
2163 pthread_mutex_lock(&perl_threads->mutex);
2164 t = c_ithread_create(perl_threads->head->interp);
2165 pthread_mutex_unlock(&perl_threads->mutex);
2170 /* Lock the base thread if this is not called from one of the read threads
2171 * to avoid race conditions with c_ithread_create(). See
2172 * https://github.com/collectd/collectd/issues/9 for details.
2175 if (aTHX == perl_threads->head->interp)
2176 pthread_mutex_lock(&perl_threads->mutex);
2178 pplugin_call(aTHX_ PLUGIN_LOG, user_data->data, level, msg);
2180 if (aTHX == perl_threads->head->interp)
2181 pthread_mutex_unlock(&perl_threads->mutex);
2184 } /* static void perl_log (int, const char *) */
2186 static int perl_notify(const notification_t *notif, user_data_t *user_data) {
2189 if (NULL == perl_threads)
2193 c_ithread_t *t = NULL;
2195 pthread_mutex_lock(&perl_threads->mutex);
2196 t = c_ithread_create(perl_threads->head->interp);
2197 pthread_mutex_unlock(&perl_threads->mutex);
2201 return pplugin_call(aTHX_ PLUGIN_NOTIF, user_data->data, notif);
2202 } /* static int perl_notify (const notification_t *) */
2204 static int perl_flush(cdtime_t timeout, const char *identifier,
2205 user_data_t *user_data) {
2208 if (NULL == perl_threads)
2212 c_ithread_t *t = NULL;
2214 pthread_mutex_lock(&perl_threads->mutex);
2215 t = c_ithread_create(perl_threads->head->interp);
2216 pthread_mutex_unlock(&perl_threads->mutex);
2221 /* For collectd-5.6 only, #1731 */
2222 if (user_data == NULL || user_data->data == NULL)
2223 return pplugin_call(aTHX_ PLUGIN_FLUSH_ALL, timeout, identifier);
2225 return pplugin_call(aTHX_ PLUGIN_FLUSH, user_data->data, timeout, identifier);
2226 } /* static int perl_flush (const int) */
2228 static int perl_shutdown(void) {
2234 plugin_unregister_complex_config("perl");
2235 plugin_unregister_read_group("perl");
2237 if (NULL == perl_threads)
2241 pthread_mutex_lock(&perl_threads->mutex);
2242 t = c_ithread_create(perl_threads->head->interp);
2243 pthread_mutex_unlock(&perl_threads->mutex);
2248 log_debug("perl_shutdown: c_ithread: interp = %p (active threads: %i)", aTHX,
2249 perl_threads->number_of_threads);
2251 plugin_unregister_init("perl");
2252 plugin_unregister_flush("perl"); /* For collectd-5.6 only, #1731 */
2254 ret = pplugin_call(aTHX_ PLUGIN_SHUTDOWN);
2256 pthread_mutex_lock(&perl_threads->mutex);
2257 t = perl_threads->tail;
2260 struct timespec ts_wait;
2261 c_ithread_t *thr = t;
2263 /* the pointer has to be advanced before destroying
2264 * the thread as this will free the memory */
2267 thr->shutdown = true;
2269 /* Give some time to thread to exit from Perl interpreter */
2270 WARNING("perl shutdown: Thread is running inside Perl. Waiting.");
2272 ts_wait.tv_nsec = 500000;
2273 nanosleep(&ts_wait, NULL);
2276 pthread_kill(thr->pthread, SIGTERM);
2277 ERROR("perl shutdown: Thread hangs inside Perl. Thread killed.");
2279 c_ithread_destroy(thr);
2282 pthread_mutex_unlock(&perl_threads->mutex);
2283 pthread_mutex_destroy(&perl_threads->mutex);
2284 pthread_mutexattr_destroy(&perl_threads->mutexattr);
2286 sfree(perl_threads);
2288 pthread_key_delete(perl_thr_key);
2292 plugin_unregister_shutdown("perl");
2294 } /* static void perl_shutdown (void) */
2297 * Access functions for global variables.
2299 * These functions implement the "magic" used to access
2300 * the global variables from Perl.
2303 static int g_pv_get(pTHX_ SV *var, MAGIC *mg) {
2304 char *pv = mg->mg_ptr;
2307 } /* static int g_pv_get (pTHX_ SV *, MAGIC *) */
2309 static int g_pv_set(pTHX_ SV *var, MAGIC *mg) {
2310 char *pv = mg->mg_ptr;
2311 sstrncpy(pv, SvPV_nolen(var), DATA_MAX_NAME_LEN);
2313 } /* static int g_pv_set (pTHX_ SV *, MAGIC *) */
2315 static int g_interval_get(pTHX_ SV *var, MAGIC *mg) {
2316 log_warn("Accessing $interval_g is deprecated (and might not "
2317 "give the desired results) - plugin_get_interval() should "
2318 "be used instead.");
2319 sv_setnv(var, CDTIME_T_TO_DOUBLE(interval_g));
2321 } /* static int g_interval_get (pTHX_ SV *, MAGIC *) */
2323 static int g_interval_set(pTHX_ SV *var, MAGIC *mg) {
2324 double nv = (double)SvNV(var);
2325 log_warn("Accessing $interval_g is deprecated (and might not "
2326 "give the desired results) - plugin_get_interval() should "
2327 "be used instead.");
2328 interval_g = DOUBLE_TO_CDTIME_T(nv);
2330 } /* static int g_interval_set (pTHX_ SV *, MAGIC *) */
2332 static MGVTBL g_pv_vtbl = {g_pv_get,
2339 #if HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL
2344 static MGVTBL g_interval_vtbl = {g_interval_get,
2351 #if HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL
2357 /* bootstrap the Collectd module */
2358 static void xs_init(pTHX) {
2361 char *file = __FILE__;
2365 /* enable usage of Perl modules using shared libraries */
2366 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
2369 for (int i = 0; NULL != api[i].f; ++i)
2370 newXS(api[i].name, api[i].f, file);
2372 stash = gv_stashpv("Collectd", 1);
2374 /* export "constants" */
2375 for (int i = 0; '\0' != constants[i].name[0]; ++i)
2376 newCONSTSUB(stash, constants[i].name, newSViv(constants[i].value));
2378 /* export global variables
2379 * by adding "magic" to the SV's representing the globale variables
2380 * perl is able to automagically call the get/set function when
2381 * accessing any such variable (this is basically the same as using
2383 /* global strings */
2387 } g_strings[] = {{"Collectd::hostname_g", hostname_g}, {"", NULL}};
2389 for (int i = 0; '\0' != g_strings[i].name[0]; ++i) {
2390 tmp = get_sv(g_strings[i].name, 1);
2391 sv_magicext(tmp, NULL, PERL_MAGIC_ext, &g_pv_vtbl, g_strings[i].var, 0);
2394 tmp = get_sv("Collectd::interval_g", /* create = */ 1);
2395 sv_magicext(tmp, NULL, /* how = */ PERL_MAGIC_ext,
2396 /* vtbl = */ &g_interval_vtbl,
2397 /* name = */ NULL, /* namelen = */ 0);
2400 } /* static void xs_init (pTHX) */
2402 /* Initialize the global Perl interpreter. */
2403 static int init_pi(int argc, char **argv) {
2406 if (NULL != perl_threads)
2409 log_info("Initializing Perl interpreter...");
2412 for (int i = 0; i < argc; ++i)
2413 log_debug("argv[%i] = \"%s\"", i, argv[i]);
2415 #endif /* COLLECT_DEBUG */
2417 if (0 != pthread_key_create(&perl_thr_key, c_ithread_destructor)) {
2418 log_err("init_pi: pthread_key_create failed");
2420 /* this must not happen - cowardly giving up if it does */
2425 /* On FreeBSD, PERL_SYS_INIT3 expands to some expression which
2426 * triggers a "value computed is not used" warning by gcc. */
2429 PERL_SYS_INIT3(&argc, &argv, &environ);
2431 perl_threads = smalloc(sizeof(*perl_threads));
2432 memset(perl_threads, 0, sizeof(c_ithread_list_t));
2434 pthread_mutexattr_init(&perl_threads->mutexattr);
2435 pthread_mutexattr_settype(&perl_threads->mutexattr, PTHREAD_MUTEX_RECURSIVE);
2436 pthread_mutex_init(&perl_threads->mutex, &perl_threads->mutexattr);
2437 /* locking the mutex should not be necessary at this point
2438 * but let's just do it for the sake of completeness */
2439 pthread_mutex_lock(&perl_threads->mutex);
2441 perl_threads->head = c_ithread_create(NULL);
2442 perl_threads->tail = perl_threads->head;
2444 if (NULL == (perl_threads->head->interp = perl_alloc())) {
2445 log_err("init_pi: Not enough memory.");
2449 aTHX = perl_threads->head->interp;
2450 pthread_mutex_unlock(&perl_threads->mutex);
2452 perl_construct(aTHX);
2454 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
2456 if (0 != perl_parse(aTHX_ xs_init, argc, argv, NULL)) {
2457 SV *err = get_sv("@", 1);
2458 log_err("init_pi: Unable to bootstrap Collectd: %s", SvPV_nolen(err));
2460 perl_destruct(perl_threads->head->interp);
2461 perl_free(perl_threads->head->interp);
2462 sfree(perl_threads);
2464 pthread_key_delete(perl_thr_key);
2468 /* Set $0 to "collectd" because perl_parse() has to set it to "-e". */
2469 sv_setpv(get_sv("0", 0), "collectd");
2473 plugin_register_init("perl", perl_init);
2474 plugin_register_shutdown("perl", perl_shutdown);
2476 } /* static int init_pi (const char **, const int) */
2479 * LoadPlugin "<Plugin>"
2481 static int perl_config_loadplugin(pTHX_ oconfig_item_t *ci) {
2482 char module_name[DATA_MAX_NAME_LEN];
2486 if ((0 != ci->children_num) || (1 != ci->values_num) ||
2487 (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2488 log_err("LoadPlugin expects a single string argument.");
2492 value = ci->values[0].value.string;
2494 if (NULL == get_module_name(module_name, sizeof(module_name), value)) {
2495 log_err("Invalid module name %s", value);
2499 if (0 != init_pi(perl_argc, perl_argv))
2502 assert(NULL != perl_threads);
2503 assert(NULL != perl_threads->head);
2505 aTHX = perl_threads->head->interp;
2507 log_debug("perl_config: Loading Perl plugin \"%s\"", value);
2508 load_module(PERL_LOADMOD_NOIMPORT, newSVpv(module_name, strlen(module_name)),
2511 } /* static int perl_config_loadplugin (oconfig_item_it *) */
2516 static int perl_config_basename(pTHX_ oconfig_item_t *ci) {
2519 if ((0 != ci->children_num) || (1 != ci->values_num) ||
2520 (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2521 log_err("BaseName expects a single string argument.");
2525 value = ci->values[0].value.string;
2527 log_debug("perl_config: Setting plugin basename to \"%s\"", value);
2528 sstrncpy(base_name, value, sizeof(base_name));
2530 } /* static int perl_config_basename (oconfig_item_it *) */
2533 * EnableDebugger "<Package>"|""
2535 static int perl_config_enabledebugger(pTHX_ oconfig_item_t *ci) {
2538 if ((0 != ci->children_num) || (1 != ci->values_num) ||
2539 (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2540 log_err("EnableDebugger expects a single string argument.");
2544 if (NULL != perl_threads) {
2545 log_warn("EnableDebugger has no effects if used after LoadPlugin.");
2549 value = ci->values[0].value.string;
2551 perl_argv = realloc(perl_argv, (++perl_argc + 1) * sizeof(char *));
2553 if (NULL == perl_argv) {
2554 log_err("perl_config: Not enough memory.");
2558 if ('\0' == value[0]) {
2559 perl_argv[perl_argc - 1] = "-d";
2561 perl_argv[perl_argc - 1] = smalloc(strlen(value) + 4);
2562 sstrncpy(perl_argv[perl_argc - 1], "-d:", 4);
2563 sstrncpy(perl_argv[perl_argc - 1] + 3, value, strlen(value) + 1);
2566 perl_argv[perl_argc] = NULL;
2568 } /* static int perl_config_enabledebugger (oconfig_item_it *) */
2571 * IncludeDir "<Dir>"
2573 static int perl_config_includedir(pTHX_ oconfig_item_t *ci) {
2576 if ((0 != ci->children_num) || (1 != ci->values_num) ||
2577 (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2578 log_err("IncludeDir expects a single string argument.");
2582 value = ci->values[0].value.string;
2585 perl_argv = realloc(perl_argv, (++perl_argc + 1) * sizeof(char *));
2587 if (NULL == perl_argv) {
2588 log_err("perl_config: Not enough memory.");
2592 perl_argv[perl_argc - 1] = smalloc(strlen(value) + 3);
2593 sstrncpy(perl_argv[perl_argc - 1], "-I", 3);
2594 sstrncpy(perl_argv[perl_argc - 1] + 2, value, strlen(value) + 1);
2596 perl_argv[perl_argc] = NULL;
2598 /* prepend the directory to @INC */
2599 av_unshift(GvAVn(PL_incgv), 1);
2600 av_store(GvAVn(PL_incgv), 0, newSVpv(value, strlen(value)));
2603 } /* static int perl_config_includedir (oconfig_item_it *) */
2608 static int perl_config_plugin(pTHX_ oconfig_item_t *ci) {
2615 if (NULL == perl_threads) {
2616 log_err("A `Plugin' block was encountered but no plugin was loaded yet. "
2617 "Put the appropriate `LoadPlugin' option in front of it.");
2623 if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2624 log_err("LoadPlugin expects a single string argument.");
2628 plugin = ci->values[0].value.string;
2631 if (0 != oconfig_item2hv(aTHX_ ci, config)) {
2635 log_err("Unable to convert configuration to a Perl hash value.");
2636 config = (HV *)&PL_sv_undef;
2644 XPUSHs(sv_2mortal(newSVpv(plugin, 0)));
2645 XPUSHs(sv_2mortal(newRV_noinc((SV *)config)));
2649 retvals = call_pv("Collectd::_plugin_dispatch_config", G_SCALAR);
2663 } /* static int perl_config_plugin (oconfig_item_it *) */
2665 static int perl_config(oconfig_item_t *ci) {
2670 for (int i = 0; i < ci->children_num; ++i) {
2671 oconfig_item_t *c = ci->children + i;
2672 int current_status = 0;
2674 if (NULL != perl_threads) {
2675 if ((aTHX = PERL_GET_CONTEXT) == NULL)
2679 if (0 == strcasecmp(c->key, "LoadPlugin"))
2680 current_status = perl_config_loadplugin(aTHX_ c);
2681 else if (0 == strcasecmp(c->key, "BaseName"))
2682 current_status = perl_config_basename(aTHX_ c);
2683 else if (0 == strcasecmp(c->key, "EnableDebugger"))
2684 current_status = perl_config_enabledebugger(aTHX_ c);
2685 else if (0 == strcasecmp(c->key, "IncludeDir"))
2686 current_status = perl_config_includedir(aTHX_ c);
2687 else if (0 == strcasecmp(c->key, "Plugin"))
2688 current_status = perl_config_plugin(aTHX_ c);
2689 else if (0 == strcasecmp(c->key, "RegisterLegacyFlush"))
2690 cf_util_get_boolean(c, ®ister_legacy_flush);
2692 log_warn("Ignoring unknown config key \"%s\".", c->key);
2696 /* fatal error - it's up to perl_config_* to clean up */
2697 if (0 > current_status) {
2698 log_err("Configuration failed with a fatal error - "
2699 "plugin disabled!");
2700 return current_status;
2703 status += current_status;
2706 } /* static int perl_config (oconfig_item_t *) */
2708 void module_register(void) {
2710 perl_argv = smalloc((perl_argc + 1) * sizeof(*perl_argv));
2712 /* default options for the Perl interpreter */
2714 perl_argv[1] = "-MCollectd";
2715 perl_argv[2] = "-e";
2717 perl_argv[4] = NULL;
2719 plugin_register_complex_config("perl", perl_config);
2721 } /* void module_register (void) */