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
36 #define DONT_POISON_SPRINTF_YET 1
39 #undef DONT_POISON_SPRINTF_YET
46 #if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
48 #pragma GCC poison sprintf
53 /* Some versions of Perl define their own version of DEBUG... :-/ */
58 /* ... while we want the definition found in plugin.h. */
62 #include "filter_chain.h"
64 #if !defined(USE_ITHREADS)
65 #error "Perl does not support ithreads!"
66 #endif /* !defined(USE_ITHREADS) */
68 /* clear the Perl sub's stack frame
69 * (this should only be used inside an XSUB) */
70 #define CLEAR_STACK_FRAME PL_stack_sp = PL_stack_base + *PL_markstack_ptr
74 #define PLUGIN_WRITE 2
75 #define PLUGIN_SHUTDOWN 3
77 #define PLUGIN_NOTIF 5
78 #define PLUGIN_FLUSH 6
79 #define PLUGIN_FLUSH_ALL 7 /* For collectd-5.6 only */
81 #define PLUGIN_TYPES 8
83 #define PLUGIN_CONFIG 254
84 #define PLUGIN_DATASET 255
91 #define FC_CB_CREATE 0
92 #define FC_CB_DESTROY 1
97 #define log_debug(...) DEBUG("perl: " __VA_ARGS__)
98 #define log_info(...) INFO("perl: " __VA_ARGS__)
99 #define log_warn(...) WARNING("perl: " __VA_ARGS__)
100 #define log_err(...) ERROR("perl: " __VA_ARGS__)
102 /* this is defined in DynaLoader.a */
103 void boot_DynaLoader(PerlInterpreter *, CV *);
105 static XS(Collectd_plugin_register_read);
106 static XS(Collectd_plugin_register_write);
107 static XS(Collectd_plugin_register_log);
108 static XS(Collectd_plugin_register_notification);
109 static XS(Collectd_plugin_register_flush);
110 static XS(Collectd_plugin_unregister_read);
111 static XS(Collectd_plugin_unregister_write);
112 static XS(Collectd_plugin_unregister_log);
113 static XS(Collectd_plugin_unregister_notification);
114 static XS(Collectd_plugin_unregister_flush);
115 static XS(Collectd_plugin_register_ds);
116 static XS(Collectd_plugin_unregister_ds);
117 static XS(Collectd_plugin_dispatch_values);
118 static XS(Collectd_plugin_get_interval);
119 static XS(Collectd__plugin_write);
120 static XS(Collectd__plugin_flush);
121 static XS(Collectd_plugin_dispatch_notification);
122 static XS(Collectd_plugin_log);
123 static XS(Collectd__fc_register);
124 static XS(Collectd_call_by_name);
126 static int perl_read(user_data_t *ud);
127 static int perl_write(const data_set_t *ds, const value_list_t *vl,
128 user_data_t *user_data);
129 static void perl_log(int level, const char *msg, user_data_t *user_data);
130 static int perl_notify(const notification_t *notif, user_data_t *user_data);
131 static int perl_flush(cdtime_t timeout, const char *identifier,
132 user_data_t *user_data);
138 typedef struct c_ithread_s {
139 /* the thread's Perl interpreter */
140 PerlInterpreter *interp;
141 _Bool running; /* thread is inside Perl interpreter */
145 /* double linked list of threads */
146 struct c_ithread_s *prev;
147 struct c_ithread_s *next;
155 /* some usage stats */
156 int number_of_threads;
157 #endif /* COLLECT_DEBUG */
159 pthread_mutex_t mutex;
160 pthread_mutexattr_t mutexattr;
163 /* name / user_data for Perl matches / targets */
169 #define PFC_USER_DATA_FREE(data) \
171 sfree((data)->name); \
172 if (NULL != (data)->user_data) \
173 sv_free((data)->user_data); \
180 extern char **environ;
186 static _Bool register_legacy_flush = 1;
188 /* if perl_threads != NULL perl_threads->head must
189 * point to the "base" thread */
190 static c_ithread_list_t *perl_threads = NULL;
192 /* the key used to store each pthread's ithread */
193 static pthread_key_t perl_thr_key;
195 static int perl_argc = 0;
196 static char **perl_argv = NULL;
198 static char base_name[DATA_MAX_NAME_LEN] = "";
204 {"Collectd::plugin_register_read", Collectd_plugin_register_read},
205 {"Collectd::plugin_register_write", Collectd_plugin_register_write},
206 {"Collectd::plugin_register_log", Collectd_plugin_register_log},
207 {"Collectd::plugin_register_notification",
208 Collectd_plugin_register_notification},
209 {"Collectd::plugin_register_flush", Collectd_plugin_register_flush},
210 {"Collectd::plugin_unregister_read", Collectd_plugin_unregister_read},
211 {"Collectd::plugin_unregister_write", Collectd_plugin_unregister_write},
212 {"Collectd::plugin_unregister_log", Collectd_plugin_unregister_log},
213 {"Collectd::plugin_unregister_notification",
214 Collectd_plugin_unregister_notification},
215 {"Collectd::plugin_unregister_flush", Collectd_plugin_unregister_flush},
216 {"Collectd::plugin_register_data_set", Collectd_plugin_register_ds},
217 {"Collectd::plugin_unregister_data_set", Collectd_plugin_unregister_ds},
218 {"Collectd::plugin_dispatch_values", Collectd_plugin_dispatch_values},
219 {"Collectd::plugin_get_interval", Collectd_plugin_get_interval},
220 {"Collectd::_plugin_write", Collectd__plugin_write},
221 {"Collectd::_plugin_flush", Collectd__plugin_flush},
222 {"Collectd::plugin_dispatch_notification",
223 Collectd_plugin_dispatch_notification},
224 {"Collectd::plugin_log", Collectd_plugin_log},
225 {"Collectd::_fc_register", Collectd__fc_register},
226 {"Collectd::call_by_name", Collectd_call_by_name},
232 } constants[] = {{"Collectd::TYPE_INIT", PLUGIN_INIT},
233 {"Collectd::TYPE_READ", PLUGIN_READ},
234 {"Collectd::TYPE_WRITE", PLUGIN_WRITE},
235 {"Collectd::TYPE_SHUTDOWN", PLUGIN_SHUTDOWN},
236 {"Collectd::TYPE_LOG", PLUGIN_LOG},
237 {"Collectd::TYPE_NOTIF", PLUGIN_NOTIF},
238 {"Collectd::TYPE_FLUSH", PLUGIN_FLUSH},
239 {"Collectd::TYPE_CONFIG", PLUGIN_CONFIG},
240 {"Collectd::TYPE_DATASET", PLUGIN_DATASET},
241 {"Collectd::DS_TYPE_COUNTER", DS_TYPE_COUNTER},
242 {"Collectd::DS_TYPE_GAUGE", DS_TYPE_GAUGE},
243 {"Collectd::DS_TYPE_DERIVE", DS_TYPE_DERIVE},
244 {"Collectd::DS_TYPE_ABSOLUTE", DS_TYPE_ABSOLUTE},
245 {"Collectd::LOG_ERR", LOG_ERR},
246 {"Collectd::LOG_WARNING", LOG_WARNING},
247 {"Collectd::LOG_NOTICE", LOG_NOTICE},
248 {"Collectd::LOG_INFO", LOG_INFO},
249 {"Collectd::LOG_DEBUG", LOG_DEBUG},
250 {"Collectd::FC_MATCH", FC_MATCH},
251 {"Collectd::FC_TARGET", FC_TARGET},
252 {"Collectd::FC_CB_CREATE", FC_CB_CREATE},
253 {"Collectd::FC_CB_DESTROY", FC_CB_DESTROY},
254 {"Collectd::FC_CB_EXEC", FC_CB_EXEC},
255 {"Collectd::FC_MATCH_NO_MATCH", FC_MATCH_NO_MATCH},
256 {"Collectd::FC_MATCH_MATCHES", FC_MATCH_MATCHES},
257 {"Collectd::FC_TARGET_CONTINUE", FC_TARGET_CONTINUE},
258 {"Collectd::FC_TARGET_STOP", FC_TARGET_STOP},
259 {"Collectd::FC_TARGET_RETURN", FC_TARGET_RETURN},
260 {"Collectd::NOTIF_FAILURE", NOTIF_FAILURE},
261 {"Collectd::NOTIF_WARNING", NOTIF_WARNING},
262 {"Collectd::NOTIF_OKAY", NOTIF_OKAY},
265 * Helper functions for data type conversion.
280 static int hv2data_source(pTHX_ HV *hash, data_source_t *ds) {
283 if ((NULL == hash) || (NULL == ds))
286 if (NULL != (tmp = hv_fetch(hash, "name", 4, 0))) {
287 sstrncpy(ds->name, SvPV_nolen(*tmp), sizeof(ds->name));
289 log_err("hv2data_source: No DS name given.");
293 if (NULL != (tmp = hv_fetch(hash, "type", 4, 0))) {
294 ds->type = SvIV(*tmp);
296 if ((DS_TYPE_COUNTER != ds->type) && (DS_TYPE_GAUGE != ds->type) &&
297 (DS_TYPE_DERIVE != ds->type) && (DS_TYPE_ABSOLUTE != ds->type)) {
298 log_err("hv2data_source: Invalid DS type.");
302 ds->type = DS_TYPE_COUNTER;
305 if (NULL != (tmp = hv_fetch(hash, "min", 3, 0)))
306 ds->min = SvNV(*tmp);
310 if (NULL != (tmp = hv_fetch(hash, "max", 3, 0)))
311 ds->max = SvNV(*tmp);
315 } /* static int hv2data_source (HV *, data_source_t *) */
317 /* av2value converts at most "len" elements from "array" to "value". Returns the
318 * number of elements converted or zero on error. */
319 static size_t av2value(pTHX_ char *name, AV *array, value_t *value,
321 const data_set_t *ds;
323 if ((NULL == name) || (NULL == array) || (NULL == value) || (array_len == 0))
326 ds = plugin_get_ds(name);
328 log_err("av2value: Unknown dataset \"%s\"", name);
332 if (array_len < ds->ds_num) {
333 log_warn("av2value: array does not contain enough elements for type "
334 "\"%s\": got %" PRIsz ", want %" PRIsz,
335 name, array_len, ds->ds_num);
337 } else if (array_len > ds->ds_num) {
338 log_warn("av2value: array contains excess elements for type \"%s\": got "
339 "%" PRIsz ", want %" PRIsz,
340 name, array_len, ds->ds_num);
343 for (size_t i = 0; i < ds->ds_num; ++i) {
344 SV **tmp = av_fetch(array, i, 0);
347 if (DS_TYPE_COUNTER == ds->ds[i].type)
348 value[i].counter = SvIV(*tmp);
349 else if (DS_TYPE_GAUGE == ds->ds[i].type)
350 value[i].gauge = SvNV(*tmp);
351 else if (DS_TYPE_DERIVE == ds->ds[i].type)
352 value[i].derive = SvIV(*tmp);
353 else if (DS_TYPE_ABSOLUTE == ds->ds[i].type)
354 value[i].absolute = SvIV(*tmp);
361 } /* static size_t av2value (char *, AV *, value_t *, size_t) */
366 * values => [ @values ],
370 * plugin_instance => $pinstance,
371 * type_instance => $tinstance,
374 static int hv2value_list(pTHX_ HV *hash, value_list_t *vl) {
377 if ((NULL == hash) || (NULL == vl))
380 if (NULL == (tmp = hv_fetch(hash, "type", 4, 0))) {
381 log_err("hv2value_list: No type given.");
385 sstrncpy(vl->type, SvPV_nolen(*tmp), sizeof(vl->type));
387 if ((NULL == (tmp = hv_fetch(hash, "values", 6, 0))) ||
388 (!(SvROK(*tmp) && (SVt_PVAV == SvTYPE(SvRV(*tmp)))))) {
389 log_err("hv2value_list: No valid values given.");
394 AV *array = (AV *)SvRV(*tmp);
395 /* av_len returns the highest index, not the actual length. */
396 size_t array_len = (size_t)(av_len(array) + 1);
400 vl->values = calloc(array_len, sizeof(*vl->values));
402 av2value(aTHX_ vl->type, (AV *)SvRV(*tmp), vl->values, array_len);
403 if (vl->values_len == 0) {
409 if (NULL != (tmp = hv_fetch(hash, "time", 4, 0))) {
410 double t = SvNV(*tmp);
411 vl->time = DOUBLE_TO_CDTIME_T(t);
414 if (NULL != (tmp = hv_fetch(hash, "interval", 8, 0))) {
415 double t = SvNV(*tmp);
416 vl->interval = DOUBLE_TO_CDTIME_T(t);
419 if (NULL != (tmp = hv_fetch(hash, "host", 4, 0)))
420 sstrncpy(vl->host, SvPV_nolen(*tmp), sizeof(vl->host));
422 if (NULL != (tmp = hv_fetch(hash, "plugin", 6, 0)))
423 sstrncpy(vl->plugin, SvPV_nolen(*tmp), sizeof(vl->plugin));
425 if (NULL != (tmp = hv_fetch(hash, "plugin_instance", 15, 0)))
426 sstrncpy(vl->plugin_instance, SvPV_nolen(*tmp),
427 sizeof(vl->plugin_instance));
429 if (NULL != (tmp = hv_fetch(hash, "type_instance", 13, 0)))
430 sstrncpy(vl->type_instance, SvPV_nolen(*tmp), sizeof(vl->type_instance));
432 } /* static int hv2value_list (pTHX_ HV *, value_list_t *) */
434 static int av2data_set(pTHX_ AV *array, char *name, data_set_t *ds) {
437 if ((NULL == array) || (NULL == name) || (NULL == ds))
443 log_err("av2data_set: Invalid data set.");
447 ds->ds = smalloc((len + 1) * sizeof(*ds->ds));
448 ds->ds_num = len + 1;
450 for (int i = 0; i <= len; ++i) {
451 SV **elem = av_fetch(array, i, 0);
454 log_err("av2data_set: Failed to fetch data source %i.", i);
458 if (!(SvROK(*elem) && (SVt_PVHV == SvTYPE(SvRV(*elem))))) {
459 log_err("av2data_set: Invalid data source.");
463 if (-1 == hv2data_source(aTHX_(HV *) SvRV(*elem), &ds->ds[i]))
466 log_debug("av2data_set: "
467 "DS.name = \"%s\", DS.type = %i, DS.min = %f, DS.max = %f",
468 ds->ds[i].name, ds->ds[i].type, ds->ds[i].min, ds->ds[i].max);
471 sstrncpy(ds->type, name, sizeof(ds->type));
473 } /* static int av2data_set (pTHX_ AV *, data_set_t *) */
478 * severity => $severity,
484 * plugin_instance => $instance,
485 * type_instance => $type_instance,
486 * meta => [ { name => <name>, value => <value> }, ... ]
489 static int av2notification_meta(pTHX_ AV *array,
490 notification_meta_t **ret_meta) {
491 notification_meta_t *tail = NULL;
493 int len = av_len(array);
495 for (int i = 0; i <= len; ++i) {
496 SV **tmp = av_fetch(array, i, 0);
501 if (!(SvROK(*tmp) && (SVt_PVHV == SvTYPE(SvRV(*tmp))))) {
502 log_warn("av2notification_meta: Skipping invalid "
503 "meta information.");
507 HV *hash = (HV *)SvRV(*tmp);
509 notification_meta_t *m = calloc(1, sizeof(*m));
513 SV **name = hv_fetch(hash, "name", strlen("name"), 0);
515 log_warn("av2notification_meta: Skipping invalid "
516 "meta information.");
520 sstrncpy(m->name, SvPV_nolen(*name), sizeof(m->name));
522 SV **value = hv_fetch(hash, "value", strlen("value"), 0);
524 log_warn("av2notification_meta: Skipping invalid "
525 "meta information.");
531 m->nm_value.nm_double = SvNVX(*value);
532 m->type = NM_TYPE_DOUBLE;
533 } else if (SvUOK(*value)) {
534 m->nm_value.nm_unsigned_int = SvUVX(*value);
535 m->type = NM_TYPE_UNSIGNED_INT;
536 } else if (SvIOK(*value)) {
537 m->nm_value.nm_signed_int = SvIVX(*value);
538 m->type = NM_TYPE_SIGNED_INT;
540 m->nm_value.nm_string = sstrdup(SvPV_nolen(*value));
541 m->type = NM_TYPE_STRING;
553 } /* static int av2notification_meta (AV *, notification_meta_t *) */
555 static int hv2notification(pTHX_ HV *hash, notification_t *n) {
558 if ((NULL == hash) || (NULL == n))
561 if (NULL != (tmp = hv_fetch(hash, "severity", 8, 0)))
562 n->severity = SvIV(*tmp);
564 n->severity = NOTIF_FAILURE;
566 if (NULL != (tmp = hv_fetch(hash, "time", 4, 0))) {
567 double t = SvNV(*tmp);
568 n->time = DOUBLE_TO_CDTIME_T(t);
572 if (NULL != (tmp = hv_fetch(hash, "message", 7, 0)))
573 sstrncpy(n->message, SvPV_nolen(*tmp), sizeof(n->message));
575 if (NULL != (tmp = hv_fetch(hash, "host", 4, 0)))
576 sstrncpy(n->host, SvPV_nolen(*tmp), sizeof(n->host));
578 sstrncpy(n->host, hostname_g, sizeof(n->host));
580 if (NULL != (tmp = hv_fetch(hash, "plugin", 6, 0)))
581 sstrncpy(n->plugin, SvPV_nolen(*tmp), sizeof(n->plugin));
583 if (NULL != (tmp = hv_fetch(hash, "plugin_instance", 15, 0)))
584 sstrncpy(n->plugin_instance, SvPV_nolen(*tmp), sizeof(n->plugin_instance));
586 if (NULL != (tmp = hv_fetch(hash, "type", 4, 0)))
587 sstrncpy(n->type, SvPV_nolen(*tmp), sizeof(n->type));
589 if (NULL != (tmp = hv_fetch(hash, "type_instance", 13, 0)))
590 sstrncpy(n->type_instance, SvPV_nolen(*tmp), sizeof(n->type_instance));
593 while (NULL != (tmp = hv_fetch(hash, "meta", 4, 0))) {
594 if (!(SvROK(*tmp) && (SVt_PVAV == SvTYPE(SvRV(*tmp))))) {
595 log_warn("hv2notification: Ignoring invalid meta information.");
599 if (0 != av2notification_meta(aTHX_(AV *) SvRV(*tmp), &n->meta)) {
600 plugin_notification_meta_free(n->meta);
607 } /* static int hv2notification (pTHX_ HV *, notification_t *) */
609 static int data_set2av(pTHX_ data_set_t *ds, AV *array) {
610 if ((NULL == ds) || (NULL == array))
613 av_extend(array, ds->ds_num);
615 for (size_t i = 0; i < ds->ds_num; ++i) {
616 HV *source = newHV();
618 if (NULL == hv_store(source, "name", 4, newSVpv(ds->ds[i].name, 0), 0))
621 if (NULL == hv_store(source, "type", 4, newSViv(ds->ds[i].type), 0))
624 if (!isnan(ds->ds[i].min))
625 if (NULL == hv_store(source, "min", 3, newSVnv(ds->ds[i].min), 0))
628 if (!isnan(ds->ds[i].max))
629 if (NULL == hv_store(source, "max", 3, newSVnv(ds->ds[i].max), 0))
632 if (NULL == av_store(array, i, newRV_noinc((SV *)source)))
636 } /* static int data_set2av (data_set_t *, AV *) */
638 static int value_list2hv(pTHX_ value_list_t *vl, data_set_t *ds, HV *hash) {
642 if ((NULL == vl) || (NULL == ds) || (NULL == hash))
646 /* av_extend takes the last *index* to which the array should be extended. */
647 av_extend(values, vl->values_len - 1);
649 assert(ds->ds_num == vl->values_len);
650 for (i = 0; i < vl->values_len; ++i) {
653 if (DS_TYPE_COUNTER == ds->ds[i].type)
654 val = newSViv(vl->values[i].counter);
655 else if (DS_TYPE_GAUGE == ds->ds[i].type)
656 val = newSVnv(vl->values[i].gauge);
657 else if (DS_TYPE_DERIVE == ds->ds[i].type)
658 val = newSViv(vl->values[i].derive);
659 else if (DS_TYPE_ABSOLUTE == ds->ds[i].type)
660 val = newSViv(vl->values[i].absolute);
662 if (NULL == av_store(values, i, val)) {
668 if (NULL == hv_store(hash, "values", 6, newRV_noinc((SV *)values), 0))
672 double t = CDTIME_T_TO_DOUBLE(vl->time);
673 if (NULL == hv_store(hash, "time", 4, newSVnv(t), 0))
678 double t = CDTIME_T_TO_DOUBLE(vl->interval);
679 if (NULL == hv_store(hash, "interval", 8, newSVnv(t), 0))
683 if ('\0' != vl->host[0])
684 if (NULL == hv_store(hash, "host", 4, newSVpv(vl->host, 0), 0))
687 if ('\0' != vl->plugin[0])
688 if (NULL == hv_store(hash, "plugin", 6, newSVpv(vl->plugin, 0), 0))
691 if ('\0' != vl->plugin_instance[0])
692 if (NULL == hv_store(hash, "plugin_instance", 15,
693 newSVpv(vl->plugin_instance, 0), 0))
696 if ('\0' != vl->type[0])
697 if (NULL == hv_store(hash, "type", 4, newSVpv(vl->type, 0), 0))
700 if ('\0' != vl->type_instance[0])
702 hv_store(hash, "type_instance", 13, newSVpv(vl->type_instance, 0), 0))
705 } /* static int value2av (value_list_t *, data_set_t *, HV *) */
707 static int notification_meta2av(pTHX_ notification_meta_t *meta, AV *array) {
715 av_extend(array, meta_num);
717 for (int i = 0; NULL != meta; meta = meta->next, ++i) {
721 if (NULL == hv_store(m, "name", 4, newSVpv(meta->name, 0), 0))
724 if (NM_TYPE_STRING == meta->type)
725 value = newSVpv(meta->nm_value.nm_string, 0);
726 else if (NM_TYPE_SIGNED_INT == meta->type)
727 value = newSViv(meta->nm_value.nm_signed_int);
728 else if (NM_TYPE_UNSIGNED_INT == meta->type)
729 value = newSVuv(meta->nm_value.nm_unsigned_int);
730 else if (NM_TYPE_DOUBLE == meta->type)
731 value = newSVnv(meta->nm_value.nm_double);
732 else if (NM_TYPE_BOOLEAN == meta->type)
733 value = meta->nm_value.nm_boolean ? &PL_sv_yes : &PL_sv_no;
737 if (NULL == hv_store(m, "value", 5, value, 0)) {
742 if (NULL == av_store(array, i, newRV_noinc((SV *)m))) {
749 } /* static int notification_meta2av (notification_meta_t *, AV *) */
751 static int notification2hv(pTHX_ notification_t *n, HV *hash) {
752 if (NULL == hv_store(hash, "severity", 8, newSViv(n->severity), 0))
756 double t = CDTIME_T_TO_DOUBLE(n->time);
757 if (NULL == hv_store(hash, "time", 4, newSVnv(t), 0))
761 if ('\0' != *n->message)
762 if (NULL == hv_store(hash, "message", 7, newSVpv(n->message, 0), 0))
765 if ('\0' != *n->host)
766 if (NULL == hv_store(hash, "host", 4, newSVpv(n->host, 0), 0))
769 if ('\0' != *n->plugin)
770 if (NULL == hv_store(hash, "plugin", 6, newSVpv(n->plugin, 0), 0))
773 if ('\0' != *n->plugin_instance)
774 if (NULL == hv_store(hash, "plugin_instance", 15,
775 newSVpv(n->plugin_instance, 0), 0))
778 if ('\0' != *n->type)
779 if (NULL == hv_store(hash, "type", 4, newSVpv(n->type, 0), 0))
782 if ('\0' != *n->type_instance)
784 hv_store(hash, "type_instance", 13, newSVpv(n->type_instance, 0), 0))
787 if (NULL != n->meta) {
789 if ((0 != notification_meta2av(aTHX_ n->meta, meta)) ||
790 (NULL == hv_store(hash, "meta", 4, newRV_noinc((SV *)meta), 0))) {
797 } /* static int notification2hv (notification_t *, HV *) */
799 static int oconfig_item2hv(pTHX_ oconfig_item_t *ci, HV *hash) {
803 if (NULL == hv_store(hash, "key", 3, newSVpv(ci->key, 0), 0))
807 if (0 < ci->values_num)
808 av_extend(values, ci->values_num);
810 if (NULL == hv_store(hash, "values", 6, newRV_noinc((SV *)values), 0)) {
816 for (int i = 0; i < ci->values_num; ++i) {
819 switch (ci->values[i].type) {
820 case OCONFIG_TYPE_STRING:
821 value = newSVpv(ci->values[i].value.string, 0);
823 case OCONFIG_TYPE_NUMBER:
824 value = newSVnv((NV)ci->values[i].value.number);
826 case OCONFIG_TYPE_BOOLEAN:
827 value = ci->values[i].value.boolean ? &PL_sv_yes : &PL_sv_no;
830 log_err("oconfig_item2hv: Invalid value type %i.", ci->values[i].type);
831 value = &PL_sv_undef;
834 if (NULL == av_store(values, i, value)) {
840 /* ignoring 'parent' member which is uninteresting in this case */
843 if (0 < ci->children_num)
844 av_extend(children, ci->children_num);
846 if (NULL == hv_store(hash, "children", 8, newRV_noinc((SV *)children), 0)) {
852 for (int i = 0; i < ci->children_num; ++i) {
855 if (0 != oconfig_item2hv(aTHX_ ci->children + i, child)) {
861 if (NULL == av_store(children, i, newRV_noinc((SV *)child))) {
868 } /* static int oconfig_item2hv (pTHX_ oconfig_item_t *, HV *) */
871 * Internal functions.
874 static char *get_module_name(char *buf, size_t buf_len, const char *module) {
876 if (base_name[0] == '\0')
877 status = snprintf(buf, buf_len, "%s", module);
879 status = snprintf(buf, buf_len, "%s::%s", base_name, module);
880 if ((status < 0) || ((unsigned int)status >= buf_len))
883 } /* char *get_module_name */
886 * Add a plugin's data set definition.
888 static int pplugin_register_data_set(pTHX_ char *name, AV *dataset) {
893 if ((NULL == name) || (NULL == dataset))
896 if (0 != av2data_set(aTHX_ dataset, name, &ds))
899 ret = plugin_register_data_set(&ds);
903 } /* static int pplugin_register_data_set (char *, SV *) */
906 * Remove a plugin's data set definition.
908 static int pplugin_unregister_data_set(char *name) {
911 return plugin_unregister_data_set(name);
912 } /* static int pplugin_unregister_data_set (char *) */
915 * Submit the values to the write functions.
917 static int pplugin_dispatch_values(pTHX_ HV *values) {
918 value_list_t vl = VALUE_LIST_INIT;
925 if (0 != hv2value_list(aTHX_ values, &vl))
928 ret = plugin_dispatch_values(&vl);
932 } /* static int pplugin_dispatch_values (char *, HV *) */
935 * Submit the values to a single write function.
937 static int pplugin_write(pTHX_ const char *plugin, AV *data_set, HV *values) {
939 value_list_t vl = VALUE_LIST_INIT;
946 if (0 != hv2value_list(aTHX_ values, &vl))
949 if ((NULL != data_set) && (0 != av2data_set(aTHX_ data_set, vl.type, &ds)))
952 ret = plugin_write(plugin, NULL == data_set ? NULL : &ds, &vl);
954 log_warn("Dispatching value to plugin \"%s\" failed with status %i.",
955 NULL == plugin ? "<any>" : plugin, ret);
957 if (NULL != data_set)
961 } /* static int pplugin_write (const char *plugin, HV *, HV *) */
964 * Dispatch a notification.
966 static int pplugin_dispatch_notification(pTHX_ HV *notif) {
967 notification_t n = {0};
974 if (0 != hv2notification(aTHX_ notif, &n))
977 ret = plugin_dispatch_notification(&n);
978 plugin_notification_meta_free(n.meta);
980 } /* static int pplugin_dispatch_notification (HV *) */
983 * Call perl sub with thread locking flags handled.
985 static int call_pv_locked(pTHX_ const char *sub_name) {
989 c_ithread_t *t = (c_ithread_t *)pthread_getspecific(perl_thr_key);
990 if (t == NULL) /* thread destroyed */
993 old_running = t->running;
997 t->running = old_running;
1001 ret = call_pv(sub_name, G_SCALAR | G_EVAL);
1003 t->running = old_running;
1005 } /* static int call_pv_locked (pTHX, *sub_name) */
1008 * Call all working functions of the given type.
1010 static int pplugin_call(pTHX_ int type, ...) {
1019 if ((type < 0) || (type >= PLUGIN_TYPES))
1029 if (PLUGIN_READ == type) {
1030 subname = va_arg(ap, char *);
1031 } else if (PLUGIN_WRITE == type) {
1038 subname = va_arg(ap, char *);
1040 * $_[0] = $plugin_type;
1055 * values => [ $v1, ... ],
1057 * host => $hostname,
1058 * plugin => $plugin,
1060 * plugin_instance => $instance,
1061 * type_instance => $type_instance
1064 ds = va_arg(ap, data_set_t *);
1065 vl = va_arg(ap, value_list_t *);
1067 if (-1 == data_set2av(aTHX_ ds, pds)) {
1070 pds = (AV *)&PL_sv_undef;
1074 if (-1 == value_list2hv(aTHX_ vl, ds, pvl)) {
1077 pvl = (HV *)&PL_sv_undef;
1081 XPUSHs(sv_2mortal(newSVpv(ds->type, 0)));
1082 XPUSHs(sv_2mortal(newRV_noinc((SV *)pds)));
1083 XPUSHs(sv_2mortal(newRV_noinc((SV *)pvl)));
1084 } else if (PLUGIN_LOG == type) {
1085 subname = va_arg(ap, char *);
1091 XPUSHs(sv_2mortal(newSViv(va_arg(ap, int))));
1092 XPUSHs(sv_2mortal(newSVpv(va_arg(ap, char *), 0)));
1093 } else if (PLUGIN_NOTIF == type) {
1095 HV *notif = newHV();
1097 subname = va_arg(ap, char *);
1101 * severity => $severity,
1105 * plugin => $plugin,
1107 * plugin_instance => $instance,
1108 * type_instance => $type_instance
1111 n = va_arg(ap, notification_t *);
1113 if (-1 == notification2hv(aTHX_ n, notif)) {
1116 notif = (HV *)&PL_sv_undef;
1120 XPUSHs(sv_2mortal(newRV_noinc((SV *)notif)));
1121 } else if (PLUGIN_FLUSH == type) {
1123 subname = va_arg(ap, char *);
1126 * $_[1] = $identifier;
1128 timeout = va_arg(ap, cdtime_t);
1130 XPUSHs(sv_2mortal(newSVnv(CDTIME_T_TO_DOUBLE(timeout))));
1131 XPUSHs(sv_2mortal(newSVpv(va_arg(ap, char *), 0)));
1132 } else if (PLUGIN_FLUSH_ALL == type) {
1134 subname = "Collectd::plugin_call_all";
1137 * $_[1] = $identifier;
1139 timeout = va_arg(ap, cdtime_t);
1141 XPUSHs(sv_2mortal(newSViv((IV)PLUGIN_FLUSH)));
1142 XPUSHs(sv_2mortal(newSVnv(CDTIME_T_TO_DOUBLE(timeout))));
1143 XPUSHs(sv_2mortal(newSVpv(va_arg(ap, char *), 0)));
1144 } else if (PLUGIN_INIT == type) {
1145 subname = "Collectd::plugin_call_all";
1146 XPUSHs(sv_2mortal(newSViv((IV)type)));
1147 } else if (PLUGIN_SHUTDOWN == type) {
1148 subname = "Collectd::plugin_call_all";
1149 XPUSHs(sv_2mortal(newSViv((IV)type)));
1150 } else { /* Unknown type. Run 'plugin_call_all' and make compiler happy */
1151 subname = "Collectd::plugin_call_all";
1152 XPUSHs(sv_2mortal(newSViv((IV)type)));
1157 retvals = call_pv_locked(aTHX_ subname);
1160 if (SvTRUE(ERRSV)) {
1161 if (PLUGIN_LOG != type)
1162 ERROR("perl: %s error: %s", subname, SvPV_nolen(ERRSV));
1164 } else if (0 < retvals) {
1176 } /* static int pplugin_call (int, ...) */
1179 * collectd's Perl interpreter based thread implementation.
1181 * This has been inspired by Perl's ithreads introduced in version 5.6.0.
1184 /* must be called with perl_threads->mutex locked */
1185 static void c_ithread_destroy(c_ithread_t *ithread) {
1186 dTHXa(ithread->interp);
1188 assert(NULL != perl_threads);
1190 PERL_SET_CONTEXT(aTHX);
1191 /* Mark as running to avoid deadlock:
1192 c_ithread_destroy -> log_debug -> perl_log()
1194 ithread->running = 1;
1195 log_debug("Shutting down Perl interpreter %p...", aTHX);
1200 --perl_threads->number_of_threads;
1201 #endif /* COLLECT_DEBUG */
1203 perl_destruct(aTHX);
1206 if (NULL == ithread->prev)
1207 perl_threads->head = ithread->next;
1209 ithread->prev->next = ithread->next;
1211 if (NULL == ithread->next)
1212 perl_threads->tail = ithread->prev;
1214 ithread->next->prev = ithread->prev;
1218 } /* static void c_ithread_destroy (c_ithread_t *) */
1220 static void c_ithread_destructor(void *arg) {
1221 c_ithread_t *ithread = (c_ithread_t *)arg;
1222 c_ithread_t *t = NULL;
1224 if (NULL == perl_threads)
1227 pthread_mutex_lock(&perl_threads->mutex);
1229 for (t = perl_threads->head; NULL != t; t = t->next)
1233 /* the ithread no longer exists */
1235 pthread_mutex_unlock(&perl_threads->mutex);
1239 c_ithread_destroy(ithread);
1241 pthread_mutex_unlock(&perl_threads->mutex);
1243 } /* static void c_ithread_destructor (void *) */
1245 /* must be called with perl_threads->mutex locked */
1246 static c_ithread_t *c_ithread_create(PerlInterpreter *base) {
1247 c_ithread_t *t = NULL;
1250 assert(NULL != perl_threads);
1252 t = smalloc(sizeof(*t));
1253 memset(t, 0, sizeof(c_ithread_t));
1255 t->interp = (NULL == base) ? NULL : perl_clone(base, CLONEf_KEEP_PTR_TABLE);
1259 if ((NULL != base) && (NULL != PL_endav)) {
1266 ++perl_threads->number_of_threads;
1267 #endif /* COLLECT_DEBUG */
1271 if (NULL == perl_threads->tail) {
1272 perl_threads->head = t;
1275 perl_threads->tail->next = t;
1276 t->prev = perl_threads->tail;
1279 t->pthread = pthread_self();
1282 perl_threads->tail = t;
1284 pthread_setspecific(perl_thr_key, (const void *)t);
1286 } /* static c_ithread_t *c_ithread_create (PerlInterpreter *) */
1289 * Filter chains implementation.
1292 static int fc_call(pTHX_ int type, int cb_type, pfc_user_data_t *data, ...) {
1298 notification_meta_t **meta = NULL;
1303 if ((type < 0) || (type >= FC_TYPES))
1306 if ((cb_type < 0) || (cb_type >= FC_CB_TYPES))
1316 XPUSHs(sv_2mortal(newSViv((IV)type)));
1317 XPUSHs(sv_2mortal(newSVpv(data->name, 0)));
1318 XPUSHs(sv_2mortal(newSViv((IV)cb_type)));
1320 if (FC_CB_CREATE == cb_type) {
1323 * $_[1] = $user_data;
1326 HV *config = newHV();
1328 ci = va_arg(ap, oconfig_item_t *);
1330 if (0 != oconfig_item2hv(aTHX_ ci, config)) {
1333 config = (HV *)&PL_sv_undef;
1337 XPUSHs(sv_2mortal(newRV_noinc((SV *)config)));
1338 } else if (FC_CB_DESTROY == cb_type) {
1340 * $_[1] = $user_data;
1343 /* nothing to be done - the user data pointer
1344 * is pushed onto the stack later */
1345 } else if (FC_CB_EXEC == cb_type) {
1350 * $_[3] = $user_data;
1358 ds = va_arg(ap, data_set_t *);
1359 vl = va_arg(ap, value_list_t *);
1360 meta = va_arg(ap, notification_meta_t **);
1362 if (0 != data_set2av(aTHX_ ds, pds)) {
1365 pds = (AV *)&PL_sv_undef;
1369 if (0 != value_list2hv(aTHX_ vl, ds, pvl)) {
1372 pvl = (HV *)&PL_sv_undef;
1379 if (0 != notification_meta2av(aTHX_ * meta, pmeta)) {
1382 pmeta = (AV *)&PL_sv_undef;
1386 pmeta = (AV *)&PL_sv_undef;
1389 XPUSHs(sv_2mortal(newRV_noinc((SV *)pds)));
1390 XPUSHs(sv_2mortal(newRV_noinc((SV *)pvl)));
1391 XPUSHs(sv_2mortal(newRV_noinc((SV *)pmeta)));
1394 XPUSHs(sv_2mortal(newRV_inc(data->user_data)));
1398 retvals = call_pv_locked(aTHX_ "Collectd::fc_call");
1400 if ((FC_CB_EXEC == cb_type) && (meta != NULL)) {
1401 assert(pmeta != NULL);
1403 plugin_notification_meta_free(*meta);
1404 av2notification_meta(aTHX_ pmeta, meta);
1408 if (SvTRUE(ERRSV)) {
1409 ERROR("perl: Collectd::fc_call error: %s", SvPV_nolen(ERRSV));
1411 } else if (0 < retvals) {
1414 /* the exec callbacks return a status, while
1415 * the others return a boolean value */
1416 if (FC_CB_EXEC == cb_type)
1418 else if (!SvTRUE(tmp))
1428 } /* static int fc_call (int, int, pfc_user_data_t *, ...) */
1430 static int fc_create(int type, const oconfig_item_t *ci, void **user_data) {
1431 pfc_user_data_t *data;
1437 if (NULL == perl_threads)
1441 c_ithread_t *t = NULL;
1443 pthread_mutex_lock(&perl_threads->mutex);
1444 t = c_ithread_create(perl_threads->head->interp);
1445 pthread_mutex_unlock(&perl_threads->mutex);
1450 log_debug("fc_create: c_ithread: interp = %p (active threads: %i)", aTHX,
1451 perl_threads->number_of_threads);
1453 if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
1454 log_warn("A \"%s\" block expects a single string argument.",
1455 (FC_MATCH == type) ? "Match" : "Target");
1459 data = smalloc(sizeof(*data));
1460 data->name = sstrdup(ci->values[0].value.string);
1461 data->user_data = newSV(0);
1463 ret = fc_call(aTHX_ type, FC_CB_CREATE, data, ci);
1466 PFC_USER_DATA_FREE(data);
1470 } /* static int fc_create (int, const oconfig_item_t *, void **) */
1472 static int fc_destroy(int type, void **user_data) {
1473 pfc_user_data_t *data = *(pfc_user_data_t **)user_data;
1479 if ((NULL == perl_threads) || (NULL == data))
1483 c_ithread_t *t = NULL;
1485 pthread_mutex_lock(&perl_threads->mutex);
1486 t = c_ithread_create(perl_threads->head->interp);
1487 pthread_mutex_unlock(&perl_threads->mutex);
1492 log_debug("fc_destroy: c_ithread: interp = %p (active threads: %i)", aTHX,
1493 perl_threads->number_of_threads);
1495 ret = fc_call(aTHX_ type, FC_CB_DESTROY, data);
1497 PFC_USER_DATA_FREE(data);
1500 } /* static int fc_destroy (int, void **) */
1502 static int fc_exec(int type, const data_set_t *ds, const value_list_t *vl,
1503 notification_meta_t **meta, void **user_data) {
1504 pfc_user_data_t *data = *(pfc_user_data_t **)user_data;
1508 if (NULL == perl_threads)
1511 assert(NULL != data);
1514 c_ithread_t *t = NULL;
1516 pthread_mutex_lock(&perl_threads->mutex);
1517 t = c_ithread_create(perl_threads->head->interp);
1518 pthread_mutex_unlock(&perl_threads->mutex);
1523 log_debug("fc_exec: c_ithread: interp = %p (active threads: %i)", aTHX,
1524 perl_threads->number_of_threads);
1526 return fc_call(aTHX_ type, FC_CB_EXEC, data, ds, vl, meta);
1527 } /* static int fc_exec (int, const data_set_t *, const value_list_t *,
1528 notification_meta_t **, void **) */
1530 static int pmatch_create(const oconfig_item_t *ci, void **user_data) {
1531 return fc_create(FC_MATCH, ci, user_data);
1532 } /* static int pmatch_create (const oconfig_item_t *, void **) */
1534 static int pmatch_destroy(void **user_data) {
1535 return fc_destroy(FC_MATCH, user_data);
1536 } /* static int pmatch_destroy (void **) */
1538 static int pmatch_match(const data_set_t *ds, const value_list_t *vl,
1539 notification_meta_t **meta, void **user_data) {
1540 return fc_exec(FC_MATCH, ds, vl, meta, user_data);
1541 } /* static int pmatch_match (const data_set_t *, const value_list_t *,
1542 notification_meta_t **, void **) */
1544 static match_proc_t pmatch = {pmatch_create, pmatch_destroy, pmatch_match};
1546 static int ptarget_create(const oconfig_item_t *ci, void **user_data) {
1547 return fc_create(FC_TARGET, ci, user_data);
1548 } /* static int ptarget_create (const oconfig_item_t *, void **) */
1550 static int ptarget_destroy(void **user_data) {
1551 return fc_destroy(FC_TARGET, user_data);
1552 } /* static int ptarget_destroy (void **) */
1554 static int ptarget_invoke(const data_set_t *ds, value_list_t *vl,
1555 notification_meta_t **meta, void **user_data) {
1556 return fc_exec(FC_TARGET, ds, vl, meta, user_data);
1557 } /* static int ptarget_invoke (const data_set_t *, value_list_t *,
1558 notification_meta_t **, void **) */
1560 static target_proc_t ptarget = {ptarget_create, ptarget_destroy,
1564 * Exported Perl API.
1567 static void _plugin_register_generic_userdata(pTHX, int type,
1570 user_data_t userdata;
1576 log_err("Usage: Collectd::plugin_register_%s(pluginname, subname)", desc);
1581 log_err("Collectd::plugin_register_%s(pluginname, subname): "
1582 "Invalid pluginname",
1587 log_err("Collectd::plugin_register_%s(pluginname, subname): "
1593 /* Use pluginname as-is to allow flush a single perl plugin */
1594 pluginname = SvPV_nolen(ST(0));
1596 log_debug("Collectd::plugin_register_%s: "
1597 "plugin = \"%s\", sub = \"%s\"",
1598 desc, pluginname, SvPV_nolen(ST(1)));
1600 memset(&userdata, 0, sizeof(userdata));
1601 userdata.data = strdup(SvPV_nolen(ST(1)));
1602 userdata.free_func = free;
1604 if (PLUGIN_READ == type) {
1605 ret = plugin_register_complex_read(
1607 pluginname, perl_read, plugin_get_interval(), /* Default interval */
1609 } else if (PLUGIN_WRITE == type) {
1610 ret = plugin_register_write(pluginname, perl_write, &userdata);
1611 } else if (PLUGIN_LOG == type) {
1612 ret = plugin_register_log(pluginname, perl_log, &userdata);
1613 } else if (PLUGIN_NOTIF == type) {
1614 ret = plugin_register_notification(pluginname, perl_notify, &userdata);
1615 } else if (PLUGIN_FLUSH == type) {
1616 if (1 == register_legacy_flush) { /* For collectd-5.7 only, #1731 */
1617 register_legacy_flush = 0;
1618 ret = plugin_register_flush("perl", perl_flush, /* user_data = */ NULL);
1622 ret = plugin_register_flush(pluginname, perl_flush, &userdata);
1624 free(userdata.data);
1634 } /* static void _plugin_register_generic_userdata ( ... ) */
1637 * Collectd::plugin_register_TYPE (pluginname, subname).
1640 * name of the perl plugin
1643 * name of the plugin's subroutine that does the work
1646 static XS(Collectd_plugin_register_read) {
1647 return _plugin_register_generic_userdata(aTHX, PLUGIN_READ, "read");
1650 static XS(Collectd_plugin_register_write) {
1651 return _plugin_register_generic_userdata(aTHX, PLUGIN_WRITE, "write");
1654 static XS(Collectd_plugin_register_log) {
1655 return _plugin_register_generic_userdata(aTHX, PLUGIN_LOG, "log");
1658 static XS(Collectd_plugin_register_notification) {
1659 return _plugin_register_generic_userdata(aTHX, PLUGIN_NOTIF, "notification");
1662 static XS(Collectd_plugin_register_flush) {
1663 return _plugin_register_generic_userdata(aTHX, PLUGIN_FLUSH, "flush");
1666 typedef int perl_unregister_function_t(const char *name);
1668 static void _plugin_unregister_generic(pTHX, perl_unregister_function_t *unreg,
1673 log_err("Usage: Collectd::plugin_unregister_%s(pluginname)", desc);
1678 log_err("Collectd::plugin_unregister_%s(pluginname): "
1679 "Invalid pluginname",
1684 log_debug("Collectd::plugin_unregister_%s: plugin = \"%s\"", desc,
1687 unreg(SvPV_nolen(ST(0)));
1692 } /* static void _plugin_unregister_generic ( ... ) */
1695 * Collectd::plugin_unregister_TYPE (pluginname).
1698 * type of callback to be unregistered: read, write, log, notification, flush
1701 * name of the perl plugin
1704 static XS(Collectd_plugin_unregister_read) {
1705 return _plugin_unregister_generic(aTHX, plugin_unregister_read, "read");
1708 static XS(Collectd_plugin_unregister_write) {
1709 return _plugin_unregister_generic(aTHX, plugin_unregister_write, "write");
1712 static XS(Collectd_plugin_unregister_log) {
1713 return _plugin_unregister_generic(aTHX, plugin_unregister_log, "log");
1716 static XS(Collectd_plugin_unregister_notification) {
1717 return _plugin_unregister_generic(aTHX, plugin_unregister_notification,
1721 static XS(Collectd_plugin_unregister_flush) {
1722 return _plugin_unregister_generic(aTHX, plugin_unregister_flush, "flush");
1726 * Collectd::plugin_register_data_set (type, dataset).
1729 * type of the dataset
1732 * dataset to be registered
1734 static XS(Collectd_plugin_register_ds) {
1740 log_warn("Using plugin_register() to register new data-sets is "
1741 "deprecated - add new entries to a custom types.db instead.");
1744 log_err("Usage: Collectd::plugin_register_data_set(type, dataset)");
1748 log_debug("Collectd::plugin_register_data_set: "
1749 "type = \"%s\", dataset = \"%s\"",
1750 SvPV_nolen(ST(0)), SvPV_nolen(ST(1)));
1754 if (SvROK(data) && (SVt_PVAV == SvTYPE(SvRV(data)))) {
1755 ret = pplugin_register_data_set(aTHX_ SvPV_nolen(ST(0)), (AV *)SvRV(data));
1757 log_err("Collectd::plugin_register_data_set: Invalid data.");
1765 } /* static XS (Collectd_plugin_register_ds) */
1768 * Collectd::plugin_unregister_data_set (type).
1771 * type of the dataset
1773 static XS(Collectd_plugin_unregister_ds) {
1777 log_err("Usage: Collectd::plugin_unregister_data_set(type)");
1781 log_debug("Collectd::plugin_unregister_data_set: type = \"%s\"",
1784 if (0 == pplugin_unregister_data_set(SvPV_nolen(ST(0))))
1788 } /* static XS (Collectd_plugin_register_ds) */
1791 * Collectd::plugin_dispatch_values (name, values).
1794 * name of the plugin
1797 * value list to submit
1799 static XS(Collectd_plugin_dispatch_values) {
1807 log_err("Usage: Collectd::plugin_dispatch_values(values)");
1811 log_debug("Collectd::plugin_dispatch_values: values=\"%s\"",
1812 SvPV_nolen(ST(/* stack index = */ 0)));
1814 values = ST(/* stack index = */ 0);
1819 /* Make sure the argument is a hash reference. */
1820 if (!(SvROK(values) && (SVt_PVHV == SvTYPE(SvRV(values))))) {
1821 log_err("Collectd::plugin_dispatch_values: Invalid values.");
1825 ret = pplugin_dispatch_values(aTHX_(HV *) SvRV(values));
1831 } /* static XS (Collectd_plugin_dispatch_values) */
1834 * Collectd::plugin_get_interval ().
1836 static XS(Collectd_plugin_get_interval) {
1839 /* make sure we don't get any unused variable warnings for 'items';
1840 * don't abort, though */
1842 log_err("Usage: Collectd::plugin_get_interval()");
1844 XSRETURN_NV((NV)CDTIME_T_TO_DOUBLE(plugin_get_interval()));
1845 } /* static XS (Collectd_plugin_get_interval) */
1847 /* Collectd::plugin_write (plugin, ds, vl).
1850 * name of the plugin to call, may be 'undef'
1853 * data-set that describes the submitted values, may be 'undef'
1856 * value-list to be written
1858 static XS(Collectd__plugin_write) {
1868 log_err("Usage: Collectd::plugin_write(plugin, ds, vl)");
1872 log_debug("Collectd::plugin_write: plugin=\"%s\", ds=\"%s\", vl=\"%s\"",
1873 SvPV_nolen(ST(0)), SvOK(ST(1)) ? SvPV_nolen(ST(1)) : "",
1879 plugin = SvPV_nolen(ST(0));
1882 if (SvROK(ds) && (SVt_PVAV == SvTYPE(SvRV(ds))))
1883 ds_array = (AV *)SvRV(ds);
1887 log_err("Collectd::plugin_write: Invalid data-set.");
1892 if (!(SvROK(vl) && (SVt_PVHV == SvTYPE(SvRV(vl))))) {
1893 log_err("Collectd::plugin_write: Invalid value-list.");
1897 ret = pplugin_write(aTHX_ plugin, ds_array, (HV *)SvRV(vl));
1903 } /* static XS (Collectd__plugin_write) */
1906 * Collectd::_plugin_flush (plugin, timeout, identifier).
1909 * name of the plugin to flush
1912 * timeout to use when flushing the data
1915 * data-set identifier to flush
1917 static XS(Collectd__plugin_flush) {
1918 char *plugin = NULL;
1925 log_err("Usage: Collectd::_plugin_flush(plugin, timeout, id)");
1930 plugin = SvPV_nolen(ST(0));
1933 timeout = (int)SvIV(ST(1));
1936 id = SvPV_nolen(ST(2));
1938 log_debug("Collectd::_plugin_flush: plugin = \"%s\", timeout = %i, "
1940 plugin, timeout, id);
1942 if (0 == plugin_flush(plugin, timeout, id))
1946 } /* static XS (Collectd__plugin_flush) */
1949 * Collectd::plugin_dispatch_notification (notif).
1952 * notification to dispatch
1954 static XS(Collectd_plugin_dispatch_notification) {
1962 log_err("Usage: Collectd::plugin_dispatch_notification(notif)");
1966 log_debug("Collectd::plugin_dispatch_notification: notif = \"%s\"",
1971 if (!(SvROK(notif) && (SVt_PVHV == SvTYPE(SvRV(notif))))) {
1972 log_err("Collectd::plugin_dispatch_notification: Invalid notif.");
1976 ret = pplugin_dispatch_notification(aTHX_(HV *) SvRV(notif));
1982 } /* static XS (Collectd_plugin_dispatch_notification) */
1985 * Collectd::plugin_log (level, message).
1988 * log level (LOG_DEBUG, ... LOG_ERR)
1993 static XS(Collectd_plugin_log) {
1997 log_err("Usage: Collectd::plugin_log(level, message)");
2001 plugin_log(SvIV(ST(0)), "%s", SvPV_nolen(ST(1)));
2003 } /* static XS (Collectd_plugin_log) */
2006 * Collectd::_fc_register (type, name)
2014 static XS(Collectd__fc_register) {
2023 log_err("Usage: Collectd::_fc_register(type, name)");
2028 name = SvPV_nolen(ST(1));
2030 if (FC_MATCH == type)
2031 ret = fc_register_match(name, pmatch);
2032 else if (FC_TARGET == type)
2033 ret = fc_register_target(name, ptarget);
2039 } /* static XS (Collectd_fc_register) */
2042 * Collectd::call_by_name (...).
2044 * Call a Perl sub identified by its name passed through $Collectd::cb_name.
2046 static XS(Collectd_call_by_name) {
2050 if (NULL == (tmp = get_sv("Collectd::cb_name", 0))) {
2051 sv_setpv(get_sv("@", 1), "cb_name has not been set");
2056 name = SvPV_nolen(tmp);
2058 if (NULL == get_cv(name, 0)) {
2059 sv_setpvf(get_sv("@", 1), "unknown callback \"%s\"", name);
2064 /* simply pass on the subroutine call without touching the stack,
2065 * thus leaving any arguments and return values in place */
2067 } /* static XS (Collectd_call_by_name) */
2070 * Interface to collectd.
2073 static int perl_init(void) {
2077 if (NULL == perl_threads)
2081 c_ithread_t *t = NULL;
2083 pthread_mutex_lock(&perl_threads->mutex);
2084 t = c_ithread_create(perl_threads->head->interp);
2085 pthread_mutex_unlock(&perl_threads->mutex);
2090 log_debug("perl_init: c_ithread: interp = %p (active threads: %i)", aTHX,
2091 perl_threads->number_of_threads);
2093 /* Lock the base thread to avoid race conditions with c_ithread_create().
2094 * See https://github.com/collectd/collectd/issues/9 and
2095 * https://github.com/collectd/collectd/issues/1706 for details.
2097 assert(aTHX == perl_threads->head->interp);
2098 pthread_mutex_lock(&perl_threads->mutex);
2100 status = pplugin_call(aTHX_ PLUGIN_INIT);
2102 pthread_mutex_unlock(&perl_threads->mutex);
2105 } /* static int perl_init (void) */
2107 static int perl_read(user_data_t *user_data) {
2110 if (NULL == perl_threads)
2114 c_ithread_t *t = NULL;
2116 pthread_mutex_lock(&perl_threads->mutex);
2117 t = c_ithread_create(perl_threads->head->interp);
2118 pthread_mutex_unlock(&perl_threads->mutex);
2123 /* Assert that we're not running as the base thread. Otherwise, we might
2124 * run into concurrency issues with c_ithread_create(). See
2125 * https://github.com/collectd/collectd/issues/9 for details. */
2126 assert(aTHX != perl_threads->head->interp);
2128 log_debug("perl_read: c_ithread: interp = %p (active threads: %i)", aTHX,
2129 perl_threads->number_of_threads);
2131 return pplugin_call(aTHX_ PLUGIN_READ, user_data->data);
2132 } /* static int perl_read (user_data_t *user_data) */
2134 static int perl_write(const data_set_t *ds, const value_list_t *vl,
2135 user_data_t *user_data) {
2139 if (NULL == perl_threads)
2143 c_ithread_t *t = NULL;
2145 pthread_mutex_lock(&perl_threads->mutex);
2146 t = c_ithread_create(perl_threads->head->interp);
2147 pthread_mutex_unlock(&perl_threads->mutex);
2152 /* Lock the base thread if this is not called from one of the read threads
2153 * to avoid race conditions with c_ithread_create(). See
2154 * https://github.com/collectd/collectd/issues/9 for details. */
2155 if (aTHX == perl_threads->head->interp)
2156 pthread_mutex_lock(&perl_threads->mutex);
2158 log_debug("perl_write: c_ithread: interp = %p (active threads: %i)", aTHX,
2159 perl_threads->number_of_threads);
2160 status = pplugin_call(aTHX_ PLUGIN_WRITE, user_data->data, ds, vl);
2162 if (aTHX == perl_threads->head->interp)
2163 pthread_mutex_unlock(&perl_threads->mutex);
2166 } /* static int perl_write (const data_set_t *, const value_list_t *) */
2168 static void perl_log(int level, const char *msg, user_data_t *user_data) {
2171 if (NULL == perl_threads)
2175 c_ithread_t *t = NULL;
2177 pthread_mutex_lock(&perl_threads->mutex);
2178 t = c_ithread_create(perl_threads->head->interp);
2179 pthread_mutex_unlock(&perl_threads->mutex);
2184 /* Lock the base thread if this is not called from one of the read threads
2185 * to avoid race conditions with c_ithread_create(). See
2186 * https://github.com/collectd/collectd/issues/9 for details.
2189 if (aTHX == perl_threads->head->interp)
2190 pthread_mutex_lock(&perl_threads->mutex);
2192 pplugin_call(aTHX_ PLUGIN_LOG, user_data->data, level, msg);
2194 if (aTHX == perl_threads->head->interp)
2195 pthread_mutex_unlock(&perl_threads->mutex);
2198 } /* static void perl_log (int, const char *) */
2200 static int perl_notify(const notification_t *notif, user_data_t *user_data) {
2203 if (NULL == perl_threads)
2207 c_ithread_t *t = NULL;
2209 pthread_mutex_lock(&perl_threads->mutex);
2210 t = c_ithread_create(perl_threads->head->interp);
2211 pthread_mutex_unlock(&perl_threads->mutex);
2215 return pplugin_call(aTHX_ PLUGIN_NOTIF, user_data->data, notif);
2216 } /* static int perl_notify (const notification_t *) */
2218 static int perl_flush(cdtime_t timeout, const char *identifier,
2219 user_data_t *user_data) {
2222 if (NULL == perl_threads)
2226 c_ithread_t *t = NULL;
2228 pthread_mutex_lock(&perl_threads->mutex);
2229 t = c_ithread_create(perl_threads->head->interp);
2230 pthread_mutex_unlock(&perl_threads->mutex);
2235 /* For collectd-5.6 only, #1731 */
2236 if (user_data == NULL || user_data->data == NULL)
2237 return pplugin_call(aTHX_ PLUGIN_FLUSH_ALL, timeout, identifier);
2239 return pplugin_call(aTHX_ PLUGIN_FLUSH, user_data->data, timeout, identifier);
2240 } /* static int perl_flush (const int) */
2242 static int perl_shutdown(void) {
2248 plugin_unregister_complex_config("perl");
2249 plugin_unregister_read_group("perl");
2251 if (NULL == perl_threads)
2255 pthread_mutex_lock(&perl_threads->mutex);
2256 t = c_ithread_create(perl_threads->head->interp);
2257 pthread_mutex_unlock(&perl_threads->mutex);
2262 log_debug("perl_shutdown: c_ithread: interp = %p (active threads: %i)", aTHX,
2263 perl_threads->number_of_threads);
2265 plugin_unregister_init("perl");
2266 plugin_unregister_flush("perl"); /* For collectd-5.6 only, #1731 */
2268 ret = pplugin_call(aTHX_ PLUGIN_SHUTDOWN);
2270 pthread_mutex_lock(&perl_threads->mutex);
2271 t = perl_threads->tail;
2274 struct timespec ts_wait;
2275 c_ithread_t *thr = t;
2277 /* the pointer has to be advanced before destroying
2278 * the thread as this will free the memory */
2283 /* Give some time to thread to exit from Perl interpreter */
2284 WARNING("perl shutdown: Thread is running inside Perl. Waiting.");
2286 ts_wait.tv_nsec = 500000;
2287 nanosleep(&ts_wait, NULL);
2290 pthread_kill(thr->pthread, SIGTERM);
2291 ERROR("perl shutdown: Thread hangs inside Perl. Thread killed.");
2293 c_ithread_destroy(thr);
2296 pthread_mutex_unlock(&perl_threads->mutex);
2297 pthread_mutex_destroy(&perl_threads->mutex);
2298 pthread_mutexattr_destroy(&perl_threads->mutexattr);
2300 sfree(perl_threads);
2302 pthread_key_delete(perl_thr_key);
2306 plugin_unregister_shutdown("perl");
2308 } /* static void perl_shutdown (void) */
2311 * Access functions for global variables.
2313 * These functions implement the "magic" used to access
2314 * the global variables from Perl.
2317 static int g_pv_get(pTHX_ SV *var, MAGIC *mg) {
2318 char *pv = mg->mg_ptr;
2321 } /* static int g_pv_get (pTHX_ SV *, MAGIC *) */
2323 static int g_pv_set(pTHX_ SV *var, MAGIC *mg) {
2324 char *pv = mg->mg_ptr;
2325 sstrncpy(pv, SvPV_nolen(var), DATA_MAX_NAME_LEN);
2327 } /* static int g_pv_set (pTHX_ SV *, MAGIC *) */
2329 static int g_interval_get(pTHX_ SV *var, MAGIC *mg) {
2330 log_warn("Accessing $interval_g is deprecated (and might not "
2331 "give the desired results) - plugin_get_interval() should "
2332 "be used instead.");
2333 sv_setnv(var, CDTIME_T_TO_DOUBLE(interval_g));
2335 } /* static int g_interval_get (pTHX_ SV *, MAGIC *) */
2337 static int g_interval_set(pTHX_ SV *var, MAGIC *mg) {
2338 double nv = (double)SvNV(var);
2339 log_warn("Accessing $interval_g is deprecated (and might not "
2340 "give the desired results) - plugin_get_interval() should "
2341 "be used instead.");
2342 interval_g = DOUBLE_TO_CDTIME_T(nv);
2344 } /* static int g_interval_set (pTHX_ SV *, MAGIC *) */
2346 static MGVTBL g_pv_vtbl = {g_pv_get,
2353 #if HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL
2358 static MGVTBL g_interval_vtbl = {g_interval_get,
2365 #if HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL
2371 /* bootstrap the Collectd module */
2372 static void xs_init(pTHX) {
2375 char *file = __FILE__;
2379 /* enable usage of Perl modules using shared libraries */
2380 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
2383 for (int i = 0; NULL != api[i].f; ++i)
2384 newXS(api[i].name, api[i].f, file);
2386 stash = gv_stashpv("Collectd", 1);
2388 /* export "constants" */
2389 for (int i = 0; '\0' != constants[i].name[0]; ++i)
2390 newCONSTSUB(stash, constants[i].name, newSViv(constants[i].value));
2392 /* export global variables
2393 * by adding "magic" to the SV's representing the globale variables
2394 * perl is able to automagically call the get/set function when
2395 * accessing any such variable (this is basically the same as using
2397 /* global strings */
2401 } g_strings[] = {{"Collectd::hostname_g", hostname_g}, {"", NULL}};
2403 for (int i = 0; '\0' != g_strings[i].name[0]; ++i) {
2404 tmp = get_sv(g_strings[i].name, 1);
2405 sv_magicext(tmp, NULL, PERL_MAGIC_ext, &g_pv_vtbl, g_strings[i].var, 0);
2408 tmp = get_sv("Collectd::interval_g", /* create = */ 1);
2409 sv_magicext(tmp, NULL, /* how = */ PERL_MAGIC_ext,
2410 /* vtbl = */ &g_interval_vtbl,
2411 /* name = */ NULL, /* namelen = */ 0);
2414 } /* static void xs_init (pTHX) */
2416 /* Initialize the global Perl interpreter. */
2417 static int init_pi(int argc, char **argv) {
2420 if (NULL != perl_threads)
2423 log_info("Initializing Perl interpreter...");
2426 for (int i = 0; i < argc; ++i)
2427 log_debug("argv[%i] = \"%s\"", i, argv[i]);
2429 #endif /* COLLECT_DEBUG */
2431 if (0 != pthread_key_create(&perl_thr_key, c_ithread_destructor)) {
2432 log_err("init_pi: pthread_key_create failed");
2434 /* this must not happen - cowardly giving up if it does */
2439 /* On FreeBSD, PERL_SYS_INIT3 expands to some expression which
2440 * triggers a "value computed is not used" warning by gcc. */
2443 PERL_SYS_INIT3(&argc, &argv, &environ);
2445 perl_threads = smalloc(sizeof(*perl_threads));
2446 memset(perl_threads, 0, sizeof(c_ithread_list_t));
2448 pthread_mutexattr_init(&perl_threads->mutexattr);
2449 pthread_mutexattr_settype(&perl_threads->mutexattr, PTHREAD_MUTEX_RECURSIVE);
2450 pthread_mutex_init(&perl_threads->mutex, &perl_threads->mutexattr);
2451 /* locking the mutex should not be necessary at this point
2452 * but let's just do it for the sake of completeness */
2453 pthread_mutex_lock(&perl_threads->mutex);
2455 perl_threads->head = c_ithread_create(NULL);
2456 perl_threads->tail = perl_threads->head;
2458 if (NULL == (perl_threads->head->interp = perl_alloc())) {
2459 log_err("init_pi: Not enough memory.");
2463 aTHX = perl_threads->head->interp;
2464 pthread_mutex_unlock(&perl_threads->mutex);
2466 perl_construct(aTHX);
2468 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
2470 if (0 != perl_parse(aTHX_ xs_init, argc, argv, NULL)) {
2471 SV *err = get_sv("@", 1);
2472 log_err("init_pi: Unable to bootstrap Collectd: %s", SvPV_nolen(err));
2474 perl_destruct(perl_threads->head->interp);
2475 perl_free(perl_threads->head->interp);
2476 sfree(perl_threads);
2478 pthread_key_delete(perl_thr_key);
2482 /* Set $0 to "collectd" because perl_parse() has to set it to "-e". */
2483 sv_setpv(get_sv("0", 0), "collectd");
2487 plugin_register_init("perl", perl_init);
2488 plugin_register_shutdown("perl", perl_shutdown);
2490 } /* static int init_pi (const char **, const int) */
2493 * LoadPlugin "<Plugin>"
2495 static int perl_config_loadplugin(pTHX_ oconfig_item_t *ci) {
2496 char module_name[DATA_MAX_NAME_LEN];
2500 if ((0 != ci->children_num) || (1 != ci->values_num) ||
2501 (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2502 log_err("LoadPlugin expects a single string argument.");
2506 value = ci->values[0].value.string;
2508 if (NULL == get_module_name(module_name, sizeof(module_name), value)) {
2509 log_err("Invalid module name %s", value);
2513 if (0 != init_pi(perl_argc, perl_argv))
2516 assert(NULL != perl_threads);
2517 assert(NULL != perl_threads->head);
2519 aTHX = perl_threads->head->interp;
2521 log_debug("perl_config: Loading Perl plugin \"%s\"", value);
2522 load_module(PERL_LOADMOD_NOIMPORT, newSVpv(module_name, strlen(module_name)),
2525 } /* static int perl_config_loadplugin (oconfig_item_it *) */
2530 static int perl_config_basename(pTHX_ oconfig_item_t *ci) {
2533 if ((0 != ci->children_num) || (1 != ci->values_num) ||
2534 (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2535 log_err("BaseName expects a single string argument.");
2539 value = ci->values[0].value.string;
2541 log_debug("perl_config: Setting plugin basename to \"%s\"", value);
2542 sstrncpy(base_name, value, sizeof(base_name));
2544 } /* static int perl_config_basename (oconfig_item_it *) */
2547 * EnableDebugger "<Package>"|""
2549 static int perl_config_enabledebugger(pTHX_ oconfig_item_t *ci) {
2552 if ((0 != ci->children_num) || (1 != ci->values_num) ||
2553 (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2554 log_err("EnableDebugger expects a single string argument.");
2558 if (NULL != perl_threads) {
2559 log_warn("EnableDebugger has no effects if used after LoadPlugin.");
2563 value = ci->values[0].value.string;
2565 perl_argv = realloc(perl_argv, (++perl_argc + 1) * sizeof(char *));
2567 if (NULL == perl_argv) {
2568 log_err("perl_config: Not enough memory.");
2572 if ('\0' == value[0]) {
2573 perl_argv[perl_argc - 1] = "-d";
2575 perl_argv[perl_argc - 1] = smalloc(strlen(value) + 4);
2576 sstrncpy(perl_argv[perl_argc - 1], "-d:", 4);
2577 sstrncpy(perl_argv[perl_argc - 1] + 3, value, strlen(value) + 1);
2580 perl_argv[perl_argc] = NULL;
2582 } /* static int perl_config_enabledebugger (oconfig_item_it *) */
2585 * IncludeDir "<Dir>"
2587 static int perl_config_includedir(pTHX_ oconfig_item_t *ci) {
2590 if ((0 != ci->children_num) || (1 != ci->values_num) ||
2591 (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2592 log_err("IncludeDir expects a single string argument.");
2596 value = ci->values[0].value.string;
2599 perl_argv = realloc(perl_argv, (++perl_argc + 1) * sizeof(char *));
2601 if (NULL == perl_argv) {
2602 log_err("perl_config: Not enough memory.");
2606 perl_argv[perl_argc - 1] = smalloc(strlen(value) + 3);
2607 sstrncpy(perl_argv[perl_argc - 1], "-I", 3);
2608 sstrncpy(perl_argv[perl_argc - 1] + 2, value, strlen(value) + 1);
2610 perl_argv[perl_argc] = NULL;
2612 /* prepend the directory to @INC */
2613 av_unshift(GvAVn(PL_incgv), 1);
2614 av_store(GvAVn(PL_incgv), 0, newSVpv(value, strlen(value)));
2617 } /* static int perl_config_includedir (oconfig_item_it *) */
2622 static int perl_config_plugin(pTHX_ oconfig_item_t *ci) {
2629 if (NULL == perl_threads) {
2630 log_err("A `Plugin' block was encountered but no plugin was loaded yet. "
2631 "Put the appropriate `LoadPlugin' option in front of it.");
2637 if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2638 log_err("LoadPlugin expects a single string argument.");
2642 plugin = ci->values[0].value.string;
2645 if (0 != oconfig_item2hv(aTHX_ ci, config)) {
2649 log_err("Unable to convert configuration to a Perl hash value.");
2650 config = (HV *)&PL_sv_undef;
2658 XPUSHs(sv_2mortal(newSVpv(plugin, 0)));
2659 XPUSHs(sv_2mortal(newRV_noinc((SV *)config)));
2663 retvals = call_pv("Collectd::_plugin_dispatch_config", G_SCALAR);
2677 } /* static int perl_config_plugin (oconfig_item_it *) */
2679 static int perl_config(oconfig_item_t *ci) {
2684 for (int i = 0; i < ci->children_num; ++i) {
2685 oconfig_item_t *c = ci->children + i;
2686 int current_status = 0;
2688 if (NULL != perl_threads) {
2689 if ((aTHX = PERL_GET_CONTEXT) == NULL)
2693 if (0 == strcasecmp(c->key, "LoadPlugin"))
2694 current_status = perl_config_loadplugin(aTHX_ c);
2695 else if (0 == strcasecmp(c->key, "BaseName"))
2696 current_status = perl_config_basename(aTHX_ c);
2697 else if (0 == strcasecmp(c->key, "EnableDebugger"))
2698 current_status = perl_config_enabledebugger(aTHX_ c);
2699 else if (0 == strcasecmp(c->key, "IncludeDir"))
2700 current_status = perl_config_includedir(aTHX_ c);
2701 else if (0 == strcasecmp(c->key, "Plugin"))
2702 current_status = perl_config_plugin(aTHX_ c);
2703 else if (0 == strcasecmp(c->key, "RegisterLegacyFlush"))
2704 cf_util_get_boolean(c, ®ister_legacy_flush);
2706 log_warn("Ignoring unknown config key \"%s\".", c->key);
2710 /* fatal error - it's up to perl_config_* to clean up */
2711 if (0 > current_status) {
2712 log_err("Configuration failed with a fatal error - "
2713 "plugin disabled!");
2714 return current_status;
2717 status += current_status;
2720 } /* static int perl_config (oconfig_item_t *) */
2722 void module_register(void) {
2724 perl_argv = smalloc((perl_argc + 1) * sizeof(*perl_argv));
2726 /* default options for the Perl interpreter */
2728 perl_argv[1] = "-MCollectd";
2729 perl_argv[2] = "-e";
2731 perl_argv[4] = NULL;
2733 plugin_register_complex_config("perl", perl_config);
2735 } /* void module_register (void) */