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},
268 } g_strings[] = {{"Collectd::hostname_g", hostname_g}, {"", NULL}};
271 * Helper functions for data type conversion.
286 static int hv2data_source(pTHX_ HV *hash, data_source_t *ds) {
289 if ((NULL == hash) || (NULL == ds))
292 if (NULL != (tmp = hv_fetch(hash, "name", 4, 0))) {
293 sstrncpy(ds->name, SvPV_nolen(*tmp), sizeof(ds->name));
295 log_err("hv2data_source: No DS name given.");
299 if (NULL != (tmp = hv_fetch(hash, "type", 4, 0))) {
300 ds->type = SvIV(*tmp);
302 if ((DS_TYPE_COUNTER != ds->type) && (DS_TYPE_GAUGE != ds->type) &&
303 (DS_TYPE_DERIVE != ds->type) && (DS_TYPE_ABSOLUTE != ds->type)) {
304 log_err("hv2data_source: Invalid DS type.");
308 ds->type = DS_TYPE_COUNTER;
311 if (NULL != (tmp = hv_fetch(hash, "min", 3, 0)))
312 ds->min = SvNV(*tmp);
316 if (NULL != (tmp = hv_fetch(hash, "max", 3, 0)))
317 ds->max = SvNV(*tmp);
321 } /* static int hv2data_source (HV *, data_source_t *) */
323 /* av2value converts at most "len" elements from "array" to "value". Returns the
324 * number of elements converted or zero on error. */
325 static size_t av2value(pTHX_ char *name, AV *array, value_t *value,
327 const data_set_t *ds;
329 if ((NULL == name) || (NULL == array) || (NULL == value) || (array_len == 0))
332 ds = plugin_get_ds(name);
334 log_err("av2value: Unknown dataset \"%s\"", name);
338 if (array_len < ds->ds_num) {
339 log_warn("av2value: array does not contain enough elements for type "
340 "\"%s\": got %zu, want %zu",
341 name, array_len, ds->ds_num);
343 } else if (array_len > ds->ds_num) {
344 log_warn("av2value: array contains excess elements for type \"%s\": got "
346 name, array_len, ds->ds_num);
349 for (size_t i = 0; i < ds->ds_num; ++i) {
350 SV **tmp = av_fetch(array, i, 0);
353 if (DS_TYPE_COUNTER == ds->ds[i].type)
354 value[i].counter = SvIV(*tmp);
355 else if (DS_TYPE_GAUGE == ds->ds[i].type)
356 value[i].gauge = SvNV(*tmp);
357 else if (DS_TYPE_DERIVE == ds->ds[i].type)
358 value[i].derive = SvIV(*tmp);
359 else if (DS_TYPE_ABSOLUTE == ds->ds[i].type)
360 value[i].absolute = SvIV(*tmp);
367 } /* static size_t av2value (char *, AV *, value_t *, size_t) */
372 * values => [ @values ],
376 * plugin_instance => $pinstance,
377 * type_instance => $tinstance,
380 static int hv2value_list(pTHX_ HV *hash, value_list_t *vl) {
383 if ((NULL == hash) || (NULL == vl))
386 if (NULL == (tmp = hv_fetch(hash, "type", 4, 0))) {
387 log_err("hv2value_list: No type given.");
391 sstrncpy(vl->type, SvPV_nolen(*tmp), sizeof(vl->type));
393 if ((NULL == (tmp = hv_fetch(hash, "values", 6, 0))) ||
394 (!(SvROK(*tmp) && (SVt_PVAV == SvTYPE(SvRV(*tmp)))))) {
395 log_err("hv2value_list: No valid values given.");
400 AV *array = (AV *)SvRV(*tmp);
401 /* av_len returns the highest index, not the actual length. */
402 size_t array_len = (size_t)(av_len(array) + 1);
406 vl->values = calloc(array_len, sizeof(*vl->values));
408 av2value(aTHX_ vl->type, (AV *)SvRV(*tmp), vl->values, array_len);
409 if (vl->values_len == 0) {
415 if (NULL != (tmp = hv_fetch(hash, "time", 4, 0))) {
416 double t = SvNV(*tmp);
417 vl->time = DOUBLE_TO_CDTIME_T(t);
420 if (NULL != (tmp = hv_fetch(hash, "interval", 8, 0))) {
421 double t = SvNV(*tmp);
422 vl->interval = DOUBLE_TO_CDTIME_T(t);
425 if (NULL != (tmp = hv_fetch(hash, "host", 4, 0)))
426 sstrncpy(vl->host, SvPV_nolen(*tmp), sizeof(vl->host));
428 sstrncpy(vl->host, hostname_g, sizeof(vl->host));
430 if (NULL != (tmp = hv_fetch(hash, "plugin", 6, 0)))
431 sstrncpy(vl->plugin, SvPV_nolen(*tmp), sizeof(vl->plugin));
433 if (NULL != (tmp = hv_fetch(hash, "plugin_instance", 15, 0)))
434 sstrncpy(vl->plugin_instance, SvPV_nolen(*tmp),
435 sizeof(vl->plugin_instance));
437 if (NULL != (tmp = hv_fetch(hash, "type_instance", 13, 0)))
438 sstrncpy(vl->type_instance, SvPV_nolen(*tmp), sizeof(vl->type_instance));
440 } /* static int hv2value_list (pTHX_ HV *, value_list_t *) */
442 static int av2data_set(pTHX_ AV *array, char *name, data_set_t *ds) {
445 if ((NULL == array) || (NULL == name) || (NULL == ds))
451 log_err("av2data_set: Invalid data set.");
455 ds->ds = smalloc((len + 1) * sizeof(*ds->ds));
456 ds->ds_num = len + 1;
458 for (int i = 0; i <= len; ++i) {
459 SV **elem = av_fetch(array, i, 0);
462 log_err("av2data_set: Failed to fetch data source %i.", i);
466 if (!(SvROK(*elem) && (SVt_PVHV == SvTYPE(SvRV(*elem))))) {
467 log_err("av2data_set: Invalid data source.");
471 if (-1 == hv2data_source(aTHX_(HV *) SvRV(*elem), &ds->ds[i]))
474 log_debug("av2data_set: "
475 "DS.name = \"%s\", DS.type = %i, DS.min = %f, DS.max = %f",
476 ds->ds[i].name, ds->ds[i].type, ds->ds[i].min, ds->ds[i].max);
479 sstrncpy(ds->type, name, sizeof(ds->type));
481 } /* static int av2data_set (pTHX_ AV *, data_set_t *) */
486 * severity => $severity,
492 * plugin_instance => $instance,
493 * type_instance => $type_instance,
494 * meta => [ { name => <name>, value => <value> }, ... ]
497 static int av2notification_meta(pTHX_ AV *array, notification_meta_t **meta) {
498 notification_meta_t **m = meta;
500 int len = av_len(array);
502 for (int i = 0; i <= len; ++i) {
503 SV **tmp = av_fetch(array, i, 0);
509 if (!(SvROK(*tmp) && (SVt_PVHV == SvTYPE(SvRV(*tmp))))) {
510 log_warn("av2notification_meta: Skipping invalid "
511 "meta information.");
515 hash = (HV *)SvRV(*tmp);
517 *m = smalloc(sizeof(**m));
519 if (NULL == (tmp = hv_fetch(hash, "name", 4, 0))) {
520 log_warn("av2notification_meta: Skipping invalid "
521 "meta information.");
525 sstrncpy((*m)->name, SvPV_nolen(*tmp), sizeof((*m)->name));
527 if (NULL == (tmp = hv_fetch(hash, "value", 5, 0))) {
528 log_warn("av2notification_meta: Skipping invalid "
529 "meta information.");
535 (*m)->nm_value.nm_double = SvNVX(*tmp);
536 (*m)->type = NM_TYPE_DOUBLE;
537 } else if (SvUOK(*tmp)) {
538 (*m)->nm_value.nm_unsigned_int = SvUVX(*tmp);
539 (*m)->type = NM_TYPE_UNSIGNED_INT;
540 } else if (SvIOK(*tmp)) {
541 (*m)->nm_value.nm_signed_int = SvIVX(*tmp);
542 (*m)->type = NM_TYPE_SIGNED_INT;
544 (*m)->nm_value.nm_string = sstrdup(SvPV_nolen(*tmp));
545 (*m)->type = NM_TYPE_STRING;
552 } /* static int av2notification_meta (AV *, notification_meta_t *) */
554 static int hv2notification(pTHX_ HV *hash, notification_t *n) {
557 if ((NULL == hash) || (NULL == n))
560 if (NULL != (tmp = hv_fetch(hash, "severity", 8, 0)))
561 n->severity = SvIV(*tmp);
563 n->severity = NOTIF_FAILURE;
565 if (NULL != (tmp = hv_fetch(hash, "time", 4, 0))) {
566 double t = SvNV(*tmp);
567 n->time = DOUBLE_TO_CDTIME_T(t);
571 if (NULL != (tmp = hv_fetch(hash, "message", 7, 0)))
572 sstrncpy(n->message, SvPV_nolen(*tmp), sizeof(n->message));
574 if (NULL != (tmp = hv_fetch(hash, "host", 4, 0)))
575 sstrncpy(n->host, SvPV_nolen(*tmp), sizeof(n->host));
577 sstrncpy(n->host, hostname_g, sizeof(n->host));
579 if (NULL != (tmp = hv_fetch(hash, "plugin", 6, 0)))
580 sstrncpy(n->plugin, SvPV_nolen(*tmp), sizeof(n->plugin));
582 if (NULL != (tmp = hv_fetch(hash, "plugin_instance", 15, 0)))
583 sstrncpy(n->plugin_instance, SvPV_nolen(*tmp), sizeof(n->plugin_instance));
585 if (NULL != (tmp = hv_fetch(hash, "type", 4, 0)))
586 sstrncpy(n->type, SvPV_nolen(*tmp), sizeof(n->type));
588 if (NULL != (tmp = hv_fetch(hash, "type_instance", 13, 0)))
589 sstrncpy(n->type_instance, SvPV_nolen(*tmp), sizeof(n->type_instance));
592 while (NULL != (tmp = hv_fetch(hash, "meta", 4, 0))) {
593 if (!(SvROK(*tmp) && (SVt_PVAV == SvTYPE(SvRV(*tmp))))) {
594 log_warn("hv2notification: Ignoring invalid meta information.");
598 if (0 != av2notification_meta(aTHX_(AV *) SvRV(*tmp), &n->meta)) {
599 plugin_notification_meta_free(n->meta);
606 } /* static int hv2notification (pTHX_ HV *, notification_t *) */
608 static int data_set2av(pTHX_ data_set_t *ds, AV *array) {
609 if ((NULL == ds) || (NULL == array))
612 av_extend(array, ds->ds_num);
614 for (size_t i = 0; i < ds->ds_num; ++i) {
615 HV *source = newHV();
617 if (NULL == hv_store(source, "name", 4, newSVpv(ds->ds[i].name, 0), 0))
620 if (NULL == hv_store(source, "type", 4, newSViv(ds->ds[i].type), 0))
623 if (!isnan(ds->ds[i].min))
624 if (NULL == hv_store(source, "min", 3, newSVnv(ds->ds[i].min), 0))
627 if (!isnan(ds->ds[i].max))
628 if (NULL == hv_store(source, "max", 3, newSVnv(ds->ds[i].max), 0))
631 if (NULL == av_store(array, i, newRV_noinc((SV *)source)))
635 } /* static int data_set2av (data_set_t *, AV *) */
637 static int value_list2hv(pTHX_ value_list_t *vl, data_set_t *ds, HV *hash) {
641 if ((NULL == vl) || (NULL == ds) || (NULL == hash))
645 /* av_extend takes the last *index* to which the array should be extended. */
646 av_extend(values, vl->values_len - 1);
648 assert(ds->ds_num == vl->values_len);
649 for (i = 0; i < vl->values_len; ++i) {
652 if (DS_TYPE_COUNTER == ds->ds[i].type)
653 val = newSViv(vl->values[i].counter);
654 else if (DS_TYPE_GAUGE == ds->ds[i].type)
655 val = newSVnv(vl->values[i].gauge);
656 else if (DS_TYPE_DERIVE == ds->ds[i].type)
657 val = newSViv(vl->values[i].derive);
658 else if (DS_TYPE_ABSOLUTE == ds->ds[i].type)
659 val = newSViv(vl->values[i].absolute);
661 if (NULL == av_store(values, i, val)) {
667 if (NULL == hv_store(hash, "values", 6, newRV_noinc((SV *)values), 0))
671 double t = CDTIME_T_TO_DOUBLE(vl->time);
672 if (NULL == hv_store(hash, "time", 4, newSVnv(t), 0))
677 double t = CDTIME_T_TO_DOUBLE(vl->interval);
678 if (NULL == hv_store(hash, "interval", 8, newSVnv(t), 0))
682 if ('\0' != vl->host[0])
683 if (NULL == hv_store(hash, "host", 4, newSVpv(vl->host, 0), 0))
686 if ('\0' != vl->plugin[0])
687 if (NULL == hv_store(hash, "plugin", 6, newSVpv(vl->plugin, 0), 0))
690 if ('\0' != vl->plugin_instance[0])
691 if (NULL == hv_store(hash, "plugin_instance", 15,
692 newSVpv(vl->plugin_instance, 0), 0))
695 if ('\0' != vl->type[0])
696 if (NULL == hv_store(hash, "type", 4, newSVpv(vl->type, 0), 0))
699 if ('\0' != vl->type_instance[0])
701 hv_store(hash, "type_instance", 13, newSVpv(vl->type_instance, 0), 0))
704 } /* static int value2av (value_list_t *, data_set_t *, HV *) */
706 static int notification_meta2av(pTHX_ notification_meta_t *meta, AV *array) {
714 av_extend(array, meta_num);
716 for (int i = 0; NULL != meta; meta = meta->next, ++i) {
720 if (NULL == hv_store(m, "name", 4, newSVpv(meta->name, 0), 0))
723 if (NM_TYPE_STRING == meta->type)
724 value = newSVpv(meta->nm_value.nm_string, 0);
725 else if (NM_TYPE_SIGNED_INT == meta->type)
726 value = newSViv(meta->nm_value.nm_signed_int);
727 else if (NM_TYPE_UNSIGNED_INT == meta->type)
728 value = newSVuv(meta->nm_value.nm_unsigned_int);
729 else if (NM_TYPE_DOUBLE == meta->type)
730 value = newSVnv(meta->nm_value.nm_double);
731 else if (NM_TYPE_BOOLEAN == meta->type)
732 value = meta->nm_value.nm_boolean ? &PL_sv_yes : &PL_sv_no;
736 if (NULL == hv_store(m, "value", 5, value, 0)) {
741 if (NULL == av_store(array, i, newRV_noinc((SV *)m))) {
748 } /* static int notification_meta2av (notification_meta_t *, AV *) */
750 static int notification2hv(pTHX_ notification_t *n, HV *hash) {
751 if (NULL == hv_store(hash, "severity", 8, newSViv(n->severity), 0))
755 double t = CDTIME_T_TO_DOUBLE(n->time);
756 if (NULL == hv_store(hash, "time", 4, newSVnv(t), 0))
760 if ('\0' != *n->message)
761 if (NULL == hv_store(hash, "message", 7, newSVpv(n->message, 0), 0))
764 if ('\0' != *n->host)
765 if (NULL == hv_store(hash, "host", 4, newSVpv(n->host, 0), 0))
768 if ('\0' != *n->plugin)
769 if (NULL == hv_store(hash, "plugin", 6, newSVpv(n->plugin, 0), 0))
772 if ('\0' != *n->plugin_instance)
773 if (NULL == hv_store(hash, "plugin_instance", 15,
774 newSVpv(n->plugin_instance, 0), 0))
777 if ('\0' != *n->type)
778 if (NULL == hv_store(hash, "type", 4, newSVpv(n->type, 0), 0))
781 if ('\0' != *n->type_instance)
783 hv_store(hash, "type_instance", 13, newSVpv(n->type_instance, 0), 0))
786 if (NULL != n->meta) {
788 if ((0 != notification_meta2av(aTHX_ n->meta, meta)) ||
789 (NULL == hv_store(hash, "meta", 4, newRV_noinc((SV *)meta), 0))) {
796 } /* static int notification2hv (notification_t *, HV *) */
798 static int oconfig_item2hv(pTHX_ oconfig_item_t *ci, HV *hash) {
802 if (NULL == hv_store(hash, "key", 3, newSVpv(ci->key, 0), 0))
806 if (0 < ci->values_num)
807 av_extend(values, ci->values_num);
809 if (NULL == hv_store(hash, "values", 6, newRV_noinc((SV *)values), 0)) {
815 for (int i = 0; i < ci->values_num; ++i) {
818 switch (ci->values[i].type) {
819 case OCONFIG_TYPE_STRING:
820 value = newSVpv(ci->values[i].value.string, 0);
822 case OCONFIG_TYPE_NUMBER:
823 value = newSVnv((NV)ci->values[i].value.number);
825 case OCONFIG_TYPE_BOOLEAN:
826 value = ci->values[i].value.boolean ? &PL_sv_yes : &PL_sv_no;
829 log_err("oconfig_item2hv: Invalid value type %i.", ci->values[i].type);
830 value = &PL_sv_undef;
833 if (NULL == av_store(values, i, value)) {
839 /* ignoring 'parent' member which is uninteresting in this case */
842 if (0 < ci->children_num)
843 av_extend(children, ci->children_num);
845 if (NULL == hv_store(hash, "children", 8, newRV_noinc((SV *)children), 0)) {
851 for (int i = 0; i < ci->children_num; ++i) {
854 if (0 != oconfig_item2hv(aTHX_ ci->children + i, child)) {
860 if (NULL == av_store(children, i, newRV_noinc((SV *)child))) {
867 } /* static int oconfig_item2hv (pTHX_ oconfig_item_t *, HV *) */
870 * Internal functions.
873 static char *get_module_name(char *buf, size_t buf_len, const char *module) {
875 if (base_name[0] == '\0')
876 status = ssnprintf(buf, buf_len, "%s", module);
878 status = ssnprintf(buf, buf_len, "%s::%s", base_name, module);
879 if ((status < 0) || ((unsigned int)status >= buf_len))
882 } /* char *get_module_name */
885 * Add a plugin's data set definition.
887 static int pplugin_register_data_set(pTHX_ char *name, AV *dataset) {
892 if ((NULL == name) || (NULL == dataset))
895 if (0 != av2data_set(aTHX_ dataset, name, &ds))
898 ret = plugin_register_data_set(&ds);
902 } /* static int pplugin_register_data_set (char *, SV *) */
905 * Remove a plugin's data set definition.
907 static int pplugin_unregister_data_set(char *name) {
910 return plugin_unregister_data_set(name);
911 } /* static int pplugin_unregister_data_set (char *) */
914 * Submit the values to the write functions.
916 static int pplugin_dispatch_values(pTHX_ HV *values) {
917 value_list_t vl = VALUE_LIST_INIT;
924 if (0 != hv2value_list(aTHX_ values, &vl))
927 ret = plugin_dispatch_values(&vl);
931 } /* static int pplugin_dispatch_values (char *, HV *) */
934 * Submit the values to a single write function.
936 static int pplugin_write(pTHX_ const char *plugin, AV *data_set, HV *values) {
938 value_list_t vl = VALUE_LIST_INIT;
945 if (0 != hv2value_list(aTHX_ values, &vl))
948 if ((NULL != data_set) && (0 != av2data_set(aTHX_ data_set, vl.type, &ds)))
951 ret = plugin_write(plugin, NULL == data_set ? NULL : &ds, &vl);
953 log_warn("Dispatching value to plugin \"%s\" failed with status %i.",
954 NULL == plugin ? "<any>" : plugin, ret);
956 if (NULL != data_set)
960 } /* static int pplugin_write (const char *plugin, HV *, HV *) */
963 * Dispatch a notification.
965 static int pplugin_dispatch_notification(pTHX_ HV *notif) {
966 notification_t n = {0};
973 if (0 != hv2notification(aTHX_ notif, &n))
976 ret = plugin_dispatch_notification(&n);
977 plugin_notification_meta_free(n.meta);
979 } /* static int pplugin_dispatch_notification (HV *) */
982 * Call perl sub with thread locking flags handled.
984 static int call_pv_locked(pTHX_ const char *sub_name) {
988 c_ithread_t *t = (c_ithread_t *)pthread_getspecific(perl_thr_key);
989 if (t == NULL) /* thread destroyed */
992 old_running = t->running;
996 t->running = old_running;
1000 ret = call_pv(sub_name, G_SCALAR | G_EVAL);
1002 t->running = old_running;
1004 } /* static int call_pv_locked (pTHX, *sub_name) */
1007 * Call all working functions of the given type.
1009 static int pplugin_call(pTHX_ int type, ...) {
1018 if ((type < 0) || (type >= PLUGIN_TYPES))
1028 if (PLUGIN_READ == type) {
1029 subname = va_arg(ap, char *);
1030 } else if (PLUGIN_WRITE == type) {
1037 subname = va_arg(ap, char *);
1039 * $_[0] = $plugin_type;
1054 * values => [ $v1, ... ],
1056 * host => $hostname,
1057 * plugin => $plugin,
1059 * plugin_instance => $instance,
1060 * type_instance => $type_instance
1063 ds = va_arg(ap, data_set_t *);
1064 vl = va_arg(ap, value_list_t *);
1066 if (-1 == data_set2av(aTHX_ ds, pds)) {
1069 pds = (AV *)&PL_sv_undef;
1073 if (-1 == value_list2hv(aTHX_ vl, ds, pvl)) {
1076 pvl = (HV *)&PL_sv_undef;
1080 XPUSHs(sv_2mortal(newSVpv(ds->type, 0)));
1081 XPUSHs(sv_2mortal(newRV_noinc((SV *)pds)));
1082 XPUSHs(sv_2mortal(newRV_noinc((SV *)pvl)));
1083 } else if (PLUGIN_LOG == type) {
1084 subname = va_arg(ap, char *);
1090 XPUSHs(sv_2mortal(newSViv(va_arg(ap, int))));
1091 XPUSHs(sv_2mortal(newSVpv(va_arg(ap, char *), 0)));
1092 } else if (PLUGIN_NOTIF == type) {
1094 HV *notif = newHV();
1096 subname = va_arg(ap, char *);
1100 * severity => $severity,
1104 * plugin => $plugin,
1106 * plugin_instance => $instance,
1107 * type_instance => $type_instance
1110 n = va_arg(ap, notification_t *);
1112 if (-1 == notification2hv(aTHX_ n, notif)) {
1115 notif = (HV *)&PL_sv_undef;
1119 XPUSHs(sv_2mortal(newRV_noinc((SV *)notif)));
1120 } else if (PLUGIN_FLUSH == type) {
1122 subname = va_arg(ap, char *);
1125 * $_[1] = $identifier;
1127 timeout = va_arg(ap, cdtime_t);
1129 XPUSHs(sv_2mortal(newSVnv(CDTIME_T_TO_DOUBLE(timeout))));
1130 XPUSHs(sv_2mortal(newSVpv(va_arg(ap, char *), 0)));
1131 } else if (PLUGIN_FLUSH_ALL == type) {
1133 subname = "Collectd::plugin_call_all";
1136 * $_[1] = $identifier;
1138 timeout = va_arg(ap, cdtime_t);
1140 XPUSHs(sv_2mortal(newSViv((IV)PLUGIN_FLUSH)));
1141 XPUSHs(sv_2mortal(newSVnv(CDTIME_T_TO_DOUBLE(timeout))));
1142 XPUSHs(sv_2mortal(newSVpv(va_arg(ap, char *), 0)));
1143 } else if (PLUGIN_INIT == type) {
1144 subname = "Collectd::plugin_call_all";
1145 XPUSHs(sv_2mortal(newSViv((IV)type)));
1146 } else if (PLUGIN_SHUTDOWN == type) {
1147 subname = "Collectd::plugin_call_all";
1148 XPUSHs(sv_2mortal(newSViv((IV)type)));
1149 } else { /* Unknown type. Run 'plugin_call_all' and make compiler happy */
1150 subname = "Collectd::plugin_call_all";
1151 XPUSHs(sv_2mortal(newSViv((IV)type)));
1156 retvals = call_pv_locked(aTHX_ subname);
1159 if (SvTRUE(ERRSV)) {
1160 if (PLUGIN_LOG != type)
1161 ERROR("perl: %s error: %s", subname, SvPV_nolen(ERRSV));
1163 } else if (0 < retvals) {
1175 } /* static int pplugin_call (int, ...) */
1178 * collectd's Perl interpreter based thread implementation.
1180 * This has been inspired by Perl's ithreads introduced in version 5.6.0.
1183 /* must be called with perl_threads->mutex locked */
1184 static void c_ithread_destroy(c_ithread_t *ithread) {
1185 dTHXa(ithread->interp);
1187 assert(NULL != perl_threads);
1189 PERL_SET_CONTEXT(aTHX);
1190 /* Mark as running to avoid deadlock:
1191 c_ithread_destroy -> log_debug -> perl_log()
1193 ithread->running = 1;
1194 log_debug("Shutting down Perl interpreter %p...", aTHX);
1199 --perl_threads->number_of_threads;
1200 #endif /* COLLECT_DEBUG */
1202 perl_destruct(aTHX);
1205 if (NULL == ithread->prev)
1206 perl_threads->head = ithread->next;
1208 ithread->prev->next = ithread->next;
1210 if (NULL == ithread->next)
1211 perl_threads->tail = ithread->prev;
1213 ithread->next->prev = ithread->prev;
1217 } /* static void c_ithread_destroy (c_ithread_t *) */
1219 static void c_ithread_destructor(void *arg) {
1220 c_ithread_t *ithread = (c_ithread_t *)arg;
1221 c_ithread_t *t = NULL;
1223 if (NULL == perl_threads)
1226 pthread_mutex_lock(&perl_threads->mutex);
1228 for (t = perl_threads->head; NULL != t; t = t->next)
1232 /* the ithread no longer exists */
1234 pthread_mutex_unlock(&perl_threads->mutex);
1238 c_ithread_destroy(ithread);
1240 pthread_mutex_unlock(&perl_threads->mutex);
1242 } /* static void c_ithread_destructor (void *) */
1244 /* must be called with perl_threads->mutex locked */
1245 static c_ithread_t *c_ithread_create(PerlInterpreter *base) {
1246 c_ithread_t *t = NULL;
1249 assert(NULL != perl_threads);
1251 t = smalloc(sizeof(*t));
1252 memset(t, 0, sizeof(c_ithread_t));
1254 t->interp = (NULL == base) ? NULL : perl_clone(base, CLONEf_KEEP_PTR_TABLE);
1258 if ((NULL != base) && (NULL != PL_endav)) {
1265 ++perl_threads->number_of_threads;
1266 #endif /* COLLECT_DEBUG */
1270 if (NULL == perl_threads->tail) {
1271 perl_threads->head = t;
1274 perl_threads->tail->next = t;
1275 t->prev = perl_threads->tail;
1278 t->pthread = pthread_self();
1281 perl_threads->tail = t;
1283 pthread_setspecific(perl_thr_key, (const void *)t);
1285 } /* static c_ithread_t *c_ithread_create (PerlInterpreter *) */
1288 * Filter chains implementation.
1291 static int fc_call(pTHX_ int type, int cb_type, pfc_user_data_t *data, ...) {
1297 notification_meta_t **meta = NULL;
1302 if ((type < 0) || (type >= FC_TYPES))
1305 if ((cb_type < 0) || (cb_type >= FC_CB_TYPES))
1315 XPUSHs(sv_2mortal(newSViv((IV)type)));
1316 XPUSHs(sv_2mortal(newSVpv(data->name, 0)));
1317 XPUSHs(sv_2mortal(newSViv((IV)cb_type)));
1319 if (FC_CB_CREATE == cb_type) {
1322 * $_[1] = $user_data;
1325 HV *config = newHV();
1327 ci = va_arg(ap, oconfig_item_t *);
1329 if (0 != oconfig_item2hv(aTHX_ ci, config)) {
1332 config = (HV *)&PL_sv_undef;
1336 XPUSHs(sv_2mortal(newRV_noinc((SV *)config)));
1337 } else if (FC_CB_DESTROY == cb_type) {
1339 * $_[1] = $user_data;
1342 /* nothing to be done - the user data pointer
1343 * is pushed onto the stack later */
1344 } else if (FC_CB_EXEC == cb_type) {
1349 * $_[3] = $user_data;
1357 ds = va_arg(ap, data_set_t *);
1358 vl = va_arg(ap, value_list_t *);
1359 meta = va_arg(ap, notification_meta_t **);
1361 if (0 != data_set2av(aTHX_ ds, pds)) {
1364 pds = (AV *)&PL_sv_undef;
1368 if (0 != value_list2hv(aTHX_ vl, ds, pvl)) {
1371 pvl = (HV *)&PL_sv_undef;
1378 if (0 != notification_meta2av(aTHX_ * meta, pmeta)) {
1381 pmeta = (AV *)&PL_sv_undef;
1385 pmeta = (AV *)&PL_sv_undef;
1388 XPUSHs(sv_2mortal(newRV_noinc((SV *)pds)));
1389 XPUSHs(sv_2mortal(newRV_noinc((SV *)pvl)));
1390 XPUSHs(sv_2mortal(newRV_noinc((SV *)pmeta)));
1393 XPUSHs(sv_2mortal(newRV_inc(data->user_data)));
1397 retvals = call_pv_locked(aTHX_ "Collectd::fc_call");
1399 if ((FC_CB_EXEC == cb_type) && (meta != NULL)) {
1400 assert(pmeta != NULL);
1402 plugin_notification_meta_free(*meta);
1403 av2notification_meta(aTHX_ pmeta, meta);
1407 if (SvTRUE(ERRSV)) {
1408 ERROR("perl: Collectd::fc_call error: %s", SvPV_nolen(ERRSV));
1410 } else if (0 < retvals) {
1413 /* the exec callbacks return a status, while
1414 * the others return a boolean value */
1415 if (FC_CB_EXEC == cb_type)
1417 else if (!SvTRUE(tmp))
1427 } /* static int fc_call (int, int, pfc_user_data_t *, ...) */
1429 static int fc_create(int type, const oconfig_item_t *ci, void **user_data) {
1430 pfc_user_data_t *data;
1436 if (NULL == perl_threads)
1440 c_ithread_t *t = NULL;
1442 pthread_mutex_lock(&perl_threads->mutex);
1443 t = c_ithread_create(perl_threads->head->interp);
1444 pthread_mutex_unlock(&perl_threads->mutex);
1449 log_debug("fc_create: c_ithread: interp = %p (active threads: %i)", aTHX,
1450 perl_threads->number_of_threads);
1452 if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
1453 log_warn("A \"%s\" block expects a single string argument.",
1454 (FC_MATCH == type) ? "Match" : "Target");
1458 data = smalloc(sizeof(*data));
1459 data->name = sstrdup(ci->values[0].value.string);
1460 data->user_data = newSV(0);
1462 ret = fc_call(aTHX_ type, FC_CB_CREATE, data, ci);
1465 PFC_USER_DATA_FREE(data);
1469 } /* static int fc_create (int, const oconfig_item_t *, void **) */
1471 static int fc_destroy(int type, void **user_data) {
1472 pfc_user_data_t *data = *(pfc_user_data_t **)user_data;
1478 if ((NULL == perl_threads) || (NULL == data))
1482 c_ithread_t *t = NULL;
1484 pthread_mutex_lock(&perl_threads->mutex);
1485 t = c_ithread_create(perl_threads->head->interp);
1486 pthread_mutex_unlock(&perl_threads->mutex);
1491 log_debug("fc_destroy: c_ithread: interp = %p (active threads: %i)", aTHX,
1492 perl_threads->number_of_threads);
1494 ret = fc_call(aTHX_ type, FC_CB_DESTROY, data);
1496 PFC_USER_DATA_FREE(data);
1499 } /* static int fc_destroy (int, void **) */
1501 static int fc_exec(int type, const data_set_t *ds, const value_list_t *vl,
1502 notification_meta_t **meta, void **user_data) {
1503 pfc_user_data_t *data = *(pfc_user_data_t **)user_data;
1507 if (NULL == perl_threads)
1510 assert(NULL != data);
1513 c_ithread_t *t = NULL;
1515 pthread_mutex_lock(&perl_threads->mutex);
1516 t = c_ithread_create(perl_threads->head->interp);
1517 pthread_mutex_unlock(&perl_threads->mutex);
1522 log_debug("fc_exec: c_ithread: interp = %p (active threads: %i)", aTHX,
1523 perl_threads->number_of_threads);
1525 return fc_call(aTHX_ type, FC_CB_EXEC, data, ds, vl, meta);
1526 } /* static int fc_exec (int, const data_set_t *, const value_list_t *,
1527 notification_meta_t **, void **) */
1529 static int pmatch_create(const oconfig_item_t *ci, void **user_data) {
1530 return fc_create(FC_MATCH, ci, user_data);
1531 } /* static int pmatch_create (const oconfig_item_t *, void **) */
1533 static int pmatch_destroy(void **user_data) {
1534 return fc_destroy(FC_MATCH, user_data);
1535 } /* static int pmatch_destroy (void **) */
1537 static int pmatch_match(const data_set_t *ds, const value_list_t *vl,
1538 notification_meta_t **meta, void **user_data) {
1539 return fc_exec(FC_MATCH, ds, vl, meta, user_data);
1540 } /* static int pmatch_match (const data_set_t *, const value_list_t *,
1541 notification_meta_t **, void **) */
1543 static match_proc_t pmatch = {pmatch_create, pmatch_destroy, pmatch_match};
1545 static int ptarget_create(const oconfig_item_t *ci, void **user_data) {
1546 return fc_create(FC_TARGET, ci, user_data);
1547 } /* static int ptarget_create (const oconfig_item_t *, void **) */
1549 static int ptarget_destroy(void **user_data) {
1550 return fc_destroy(FC_TARGET, user_data);
1551 } /* static int ptarget_destroy (void **) */
1553 static int ptarget_invoke(const data_set_t *ds, value_list_t *vl,
1554 notification_meta_t **meta, void **user_data) {
1555 return fc_exec(FC_TARGET, ds, vl, meta, user_data);
1556 } /* static int ptarget_invoke (const data_set_t *, value_list_t *,
1557 notification_meta_t **, void **) */
1559 static target_proc_t ptarget = {ptarget_create, ptarget_destroy,
1563 * Exported Perl API.
1566 static void _plugin_register_generic_userdata(pTHX, int type,
1569 user_data_t userdata;
1575 log_err("Usage: Collectd::plugin_register_%s(pluginname, subname)", desc);
1580 log_err("Collectd::plugin_register_%s(pluginname, subname): "
1581 "Invalid pluginname",
1586 log_err("Collectd::plugin_register_%s(pluginname, subname): "
1592 /* Use pluginname as-is to allow flush a single perl plugin */
1593 pluginname = SvPV_nolen(ST(0));
1595 log_debug("Collectd::plugin_register_%s: "
1596 "plugin = \"%s\", sub = \"%s\"",
1597 desc, pluginname, SvPV_nolen(ST(1)));
1599 memset(&userdata, 0, sizeof(userdata));
1600 userdata.data = strdup(SvPV_nolen(ST(1)));
1601 userdata.free_func = free;
1603 if (PLUGIN_READ == type) {
1604 ret = plugin_register_complex_read(
1606 pluginname, perl_read, plugin_get_interval(), /* Default interval */
1608 } else if (PLUGIN_WRITE == type) {
1609 ret = plugin_register_write(pluginname, perl_write, &userdata);
1610 } else if (PLUGIN_LOG == type) {
1611 ret = plugin_register_log(pluginname, perl_log, &userdata);
1612 } else if (PLUGIN_NOTIF == type) {
1613 ret = plugin_register_notification(pluginname, perl_notify, &userdata);
1614 } else if (PLUGIN_FLUSH == type) {
1615 if (1 == register_legacy_flush) { /* For collectd-5.7 only, #1731 */
1616 register_legacy_flush = 0;
1617 ret = plugin_register_flush("perl", perl_flush, /* user_data = */ NULL);
1621 ret = plugin_register_flush(pluginname, perl_flush, &userdata);
1629 free(userdata.data);
1632 } /* static void _plugin_register_generic_userdata ( ... ) */
1635 * Collectd::plugin_register_TYPE (pluginname, subname).
1638 * name of the perl plugin
1641 * name of the plugin's subroutine that does the work
1644 static XS(Collectd_plugin_register_read) {
1645 return _plugin_register_generic_userdata(aTHX, PLUGIN_READ, "read");
1648 static XS(Collectd_plugin_register_write) {
1649 return _plugin_register_generic_userdata(aTHX, PLUGIN_WRITE, "write");
1652 static XS(Collectd_plugin_register_log) {
1653 return _plugin_register_generic_userdata(aTHX, PLUGIN_LOG, "log");
1656 static XS(Collectd_plugin_register_notification) {
1657 return _plugin_register_generic_userdata(aTHX, PLUGIN_NOTIF, "notification");
1660 static XS(Collectd_plugin_register_flush) {
1661 return _plugin_register_generic_userdata(aTHX, PLUGIN_FLUSH, "flush");
1664 typedef int perl_unregister_function_t(const char *name);
1666 static void _plugin_unregister_generic(pTHX, perl_unregister_function_t *unreg,
1671 log_err("Usage: Collectd::plugin_unregister_%s(pluginname)", desc);
1676 log_err("Collectd::plugin_unregister_%s(pluginname): "
1677 "Invalid pluginname",
1682 log_debug("Collectd::plugin_unregister_%s: plugin = \"%s\"", desc,
1685 unreg(SvPV_nolen(ST(0)));
1690 } /* static void _plugin_unregister_generic ( ... ) */
1693 * Collectd::plugin_unregister_TYPE (pluginname).
1696 * type of callback to be unregistered: read, write, log, notification, flush
1699 * name of the perl plugin
1702 static XS(Collectd_plugin_unregister_read) {
1703 return _plugin_unregister_generic(aTHX, plugin_unregister_read, "read");
1706 static XS(Collectd_plugin_unregister_write) {
1707 return _plugin_unregister_generic(aTHX, plugin_unregister_write, "write");
1710 static XS(Collectd_plugin_unregister_log) {
1711 return _plugin_unregister_generic(aTHX, plugin_unregister_log, "log");
1714 static XS(Collectd_plugin_unregister_notification) {
1715 return _plugin_unregister_generic(aTHX, plugin_unregister_notification,
1719 static XS(Collectd_plugin_unregister_flush) {
1720 return _plugin_unregister_generic(aTHX, plugin_unregister_flush, "flush");
1724 * Collectd::plugin_register_data_set (type, dataset).
1727 * type of the dataset
1730 * dataset to be registered
1732 static XS(Collectd_plugin_register_ds) {
1738 log_warn("Using plugin_register() to register new data-sets is "
1739 "deprecated - add new entries to a custom types.db instead.");
1742 log_err("Usage: Collectd::plugin_register_data_set(type, dataset)");
1746 log_debug("Collectd::plugin_register_data_set: "
1747 "type = \"%s\", dataset = \"%s\"",
1748 SvPV_nolen(ST(0)), SvPV_nolen(ST(1)));
1752 if (SvROK(data) && (SVt_PVAV == SvTYPE(SvRV(data)))) {
1753 ret = pplugin_register_data_set(aTHX_ SvPV_nolen(ST(0)), (AV *)SvRV(data));
1755 log_err("Collectd::plugin_register_data_set: Invalid data.");
1763 } /* static XS (Collectd_plugin_register_ds) */
1766 * Collectd::plugin_unregister_data_set (type).
1769 * type of the dataset
1771 static XS(Collectd_plugin_unregister_ds) {
1775 log_err("Usage: Collectd::plugin_unregister_data_set(type)");
1779 log_debug("Collectd::plugin_unregister_data_set: type = \"%s\"",
1782 if (0 == pplugin_unregister_data_set(SvPV_nolen(ST(0))))
1786 } /* static XS (Collectd_plugin_register_ds) */
1789 * Collectd::plugin_dispatch_values (name, values).
1792 * name of the plugin
1795 * value list to submit
1797 static XS(Collectd_plugin_dispatch_values) {
1805 log_err("Usage: Collectd::plugin_dispatch_values(values)");
1809 log_debug("Collectd::plugin_dispatch_values: values=\"%s\"",
1810 SvPV_nolen(ST(/* stack index = */ 0)));
1812 values = ST(/* stack index = */ 0);
1817 /* Make sure the argument is a hash reference. */
1818 if (!(SvROK(values) && (SVt_PVHV == SvTYPE(SvRV(values))))) {
1819 log_err("Collectd::plugin_dispatch_values: Invalid values.");
1823 ret = pplugin_dispatch_values(aTHX_(HV *) SvRV(values));
1829 } /* static XS (Collectd_plugin_dispatch_values) */
1832 * Collectd::plugin_get_interval ().
1834 static XS(Collectd_plugin_get_interval) {
1837 /* make sure we don't get any unused variable warnings for 'items';
1838 * don't abort, though */
1840 log_err("Usage: Collectd::plugin_get_interval()");
1842 XSRETURN_NV((NV)CDTIME_T_TO_DOUBLE(plugin_get_interval()));
1843 } /* static XS (Collectd_plugin_get_interval) */
1845 /* Collectd::plugin_write (plugin, ds, vl).
1848 * name of the plugin to call, may be 'undef'
1851 * data-set that describes the submitted values, may be 'undef'
1854 * value-list to be written
1856 static XS(Collectd__plugin_write) {
1866 log_err("Usage: Collectd::plugin_write(plugin, ds, vl)");
1870 log_debug("Collectd::plugin_write: plugin=\"%s\", ds=\"%s\", vl=\"%s\"",
1871 SvPV_nolen(ST(0)), SvOK(ST(1)) ? SvPV_nolen(ST(1)) : "",
1877 plugin = SvPV_nolen(ST(0));
1880 if (SvROK(ds) && (SVt_PVAV == SvTYPE(SvRV(ds))))
1881 ds_array = (AV *)SvRV(ds);
1885 log_err("Collectd::plugin_write: Invalid data-set.");
1890 if (!(SvROK(vl) && (SVt_PVHV == SvTYPE(SvRV(vl))))) {
1891 log_err("Collectd::plugin_write: Invalid value-list.");
1895 ret = pplugin_write(aTHX_ plugin, ds_array, (HV *)SvRV(vl));
1901 } /* static XS (Collectd__plugin_write) */
1904 * Collectd::_plugin_flush (plugin, timeout, identifier).
1907 * name of the plugin to flush
1910 * timeout to use when flushing the data
1913 * data-set identifier to flush
1915 static XS(Collectd__plugin_flush) {
1916 char *plugin = NULL;
1923 log_err("Usage: Collectd::_plugin_flush(plugin, timeout, id)");
1928 plugin = SvPV_nolen(ST(0));
1931 timeout = (int)SvIV(ST(1));
1934 id = SvPV_nolen(ST(2));
1936 log_debug("Collectd::_plugin_flush: plugin = \"%s\", timeout = %i, "
1938 plugin, timeout, id);
1940 if (0 == plugin_flush(plugin, timeout, id))
1944 } /* static XS (Collectd__plugin_flush) */
1947 * Collectd::plugin_dispatch_notification (notif).
1950 * notification to dispatch
1952 static XS(Collectd_plugin_dispatch_notification) {
1960 log_err("Usage: Collectd::plugin_dispatch_notification(notif)");
1964 log_debug("Collectd::plugin_dispatch_notification: notif = \"%s\"",
1969 if (!(SvROK(notif) && (SVt_PVHV == SvTYPE(SvRV(notif))))) {
1970 log_err("Collectd::plugin_dispatch_notification: Invalid notif.");
1974 ret = pplugin_dispatch_notification(aTHX_(HV *) SvRV(notif));
1980 } /* static XS (Collectd_plugin_dispatch_notification) */
1983 * Collectd::plugin_log (level, message).
1986 * log level (LOG_DEBUG, ... LOG_ERR)
1991 static XS(Collectd_plugin_log) {
1995 log_err("Usage: Collectd::plugin_log(level, message)");
1999 plugin_log(SvIV(ST(0)), "%s", SvPV_nolen(ST(1)));
2001 } /* static XS (Collectd_plugin_log) */
2004 * Collectd::_fc_register (type, name)
2012 static XS(Collectd__fc_register) {
2021 log_err("Usage: Collectd::_fc_register(type, name)");
2026 name = SvPV_nolen(ST(1));
2028 if (FC_MATCH == type)
2029 ret = fc_register_match(name, pmatch);
2030 else if (FC_TARGET == type)
2031 ret = fc_register_target(name, ptarget);
2037 } /* static XS (Collectd_fc_register) */
2040 * Collectd::call_by_name (...).
2042 * Call a Perl sub identified by its name passed through $Collectd::cb_name.
2044 static XS(Collectd_call_by_name) {
2048 if (NULL == (tmp = get_sv("Collectd::cb_name", 0))) {
2049 sv_setpv(get_sv("@", 1), "cb_name has not been set");
2054 name = SvPV_nolen(tmp);
2056 if (NULL == get_cv(name, 0)) {
2057 sv_setpvf(get_sv("@", 1), "unknown callback \"%s\"", name);
2062 /* simply pass on the subroutine call without touching the stack,
2063 * thus leaving any arguments and return values in place */
2065 } /* static XS (Collectd_call_by_name) */
2068 * Interface to collectd.
2071 static int perl_init(void) {
2075 if (NULL == perl_threads)
2079 c_ithread_t *t = NULL;
2081 pthread_mutex_lock(&perl_threads->mutex);
2082 t = c_ithread_create(perl_threads->head->interp);
2083 pthread_mutex_unlock(&perl_threads->mutex);
2088 log_debug("perl_init: c_ithread: interp = %p (active threads: %i)", aTHX,
2089 perl_threads->number_of_threads);
2091 /* Lock the base thread to avoid race conditions with c_ithread_create().
2092 * See https://github.com/collectd/collectd/issues/9 and
2093 * https://github.com/collectd/collectd/issues/1706 for details.
2095 assert(aTHX == perl_threads->head->interp);
2096 pthread_mutex_lock(&perl_threads->mutex);
2098 status = pplugin_call(aTHX_ PLUGIN_INIT);
2100 pthread_mutex_unlock(&perl_threads->mutex);
2103 } /* static int perl_init (void) */
2105 static int perl_read(user_data_t *user_data) {
2108 if (NULL == perl_threads)
2112 c_ithread_t *t = NULL;
2114 pthread_mutex_lock(&perl_threads->mutex);
2115 t = c_ithread_create(perl_threads->head->interp);
2116 pthread_mutex_unlock(&perl_threads->mutex);
2121 /* Assert that we're not running as the base thread. Otherwise, we might
2122 * run into concurrency issues with c_ithread_create(). See
2123 * https://github.com/collectd/collectd/issues/9 for details. */
2124 assert(aTHX != perl_threads->head->interp);
2126 log_debug("perl_read: c_ithread: interp = %p (active threads: %i)", aTHX,
2127 perl_threads->number_of_threads);
2129 return pplugin_call(aTHX_ PLUGIN_READ, user_data->data);
2130 } /* static int perl_read (user_data_t *user_data) */
2132 static int perl_write(const data_set_t *ds, const value_list_t *vl,
2133 user_data_t *user_data) {
2137 if (NULL == perl_threads)
2141 c_ithread_t *t = NULL;
2143 pthread_mutex_lock(&perl_threads->mutex);
2144 t = c_ithread_create(perl_threads->head->interp);
2145 pthread_mutex_unlock(&perl_threads->mutex);
2150 /* Lock the base thread if this is not called from one of the read threads
2151 * to avoid race conditions with c_ithread_create(). See
2152 * https://github.com/collectd/collectd/issues/9 for details. */
2153 if (aTHX == perl_threads->head->interp)
2154 pthread_mutex_lock(&perl_threads->mutex);
2156 log_debug("perl_write: c_ithread: interp = %p (active threads: %i)", aTHX,
2157 perl_threads->number_of_threads);
2158 status = pplugin_call(aTHX_ PLUGIN_WRITE, user_data->data, ds, vl);
2160 if (aTHX == perl_threads->head->interp)
2161 pthread_mutex_unlock(&perl_threads->mutex);
2164 } /* static int perl_write (const data_set_t *, const value_list_t *) */
2166 static void perl_log(int level, const char *msg, user_data_t *user_data) {
2169 if (NULL == perl_threads)
2173 c_ithread_t *t = NULL;
2175 pthread_mutex_lock(&perl_threads->mutex);
2176 t = c_ithread_create(perl_threads->head->interp);
2177 pthread_mutex_unlock(&perl_threads->mutex);
2182 /* Lock the base thread if this is not called from one of the read threads
2183 * to avoid race conditions with c_ithread_create(). See
2184 * https://github.com/collectd/collectd/issues/9 for details.
2187 if (aTHX == perl_threads->head->interp)
2188 pthread_mutex_lock(&perl_threads->mutex);
2190 pplugin_call(aTHX_ PLUGIN_LOG, user_data->data, level, msg);
2192 if (aTHX == perl_threads->head->interp)
2193 pthread_mutex_unlock(&perl_threads->mutex);
2196 } /* static void perl_log (int, const char *) */
2198 static int perl_notify(const notification_t *notif, user_data_t *user_data) {
2201 if (NULL == perl_threads)
2205 c_ithread_t *t = NULL;
2207 pthread_mutex_lock(&perl_threads->mutex);
2208 t = c_ithread_create(perl_threads->head->interp);
2209 pthread_mutex_unlock(&perl_threads->mutex);
2213 return pplugin_call(aTHX_ PLUGIN_NOTIF, user_data->data, notif);
2214 } /* static int perl_notify (const notification_t *) */
2216 static int perl_flush(cdtime_t timeout, const char *identifier,
2217 user_data_t *user_data) {
2220 if (NULL == perl_threads)
2224 c_ithread_t *t = NULL;
2226 pthread_mutex_lock(&perl_threads->mutex);
2227 t = c_ithread_create(perl_threads->head->interp);
2228 pthread_mutex_unlock(&perl_threads->mutex);
2233 /* For collectd-5.6 only, #1731 */
2234 if (user_data == NULL || user_data->data == NULL)
2235 return pplugin_call(aTHX_ PLUGIN_FLUSH_ALL, timeout, identifier);
2237 return pplugin_call(aTHX_ PLUGIN_FLUSH, user_data->data, timeout, identifier);
2238 } /* static int perl_flush (const int) */
2240 static int perl_shutdown(void) {
2246 plugin_unregister_complex_config("perl");
2247 plugin_unregister_read_group("perl");
2249 if (NULL == perl_threads)
2253 pthread_mutex_lock(&perl_threads->mutex);
2254 t = c_ithread_create(perl_threads->head->interp);
2255 pthread_mutex_unlock(&perl_threads->mutex);
2260 log_debug("perl_shutdown: c_ithread: interp = %p (active threads: %i)", aTHX,
2261 perl_threads->number_of_threads);
2263 plugin_unregister_init("perl");
2264 plugin_unregister_flush("perl"); /* For collectd-5.6 only, #1731 */
2266 ret = pplugin_call(aTHX_ PLUGIN_SHUTDOWN);
2268 pthread_mutex_lock(&perl_threads->mutex);
2269 t = perl_threads->tail;
2272 struct timespec ts_wait;
2273 c_ithread_t *thr = t;
2275 /* the pointer has to be advanced before destroying
2276 * the thread as this will free the memory */
2281 /* Give some time to thread to exit from Perl interpreter */
2282 WARNING("perl shutdown: Thread is running inside Perl. Waiting.");
2284 ts_wait.tv_nsec = 500000;
2285 nanosleep(&ts_wait, NULL);
2288 pthread_kill(thr->pthread, SIGTERM);
2289 ERROR("perl shutdown: Thread hangs inside Perl. Thread killed.");
2291 c_ithread_destroy(thr);
2294 pthread_mutex_unlock(&perl_threads->mutex);
2295 pthread_mutex_destroy(&perl_threads->mutex);
2296 pthread_mutexattr_destroy(&perl_threads->mutexattr);
2298 sfree(perl_threads);
2300 pthread_key_delete(perl_thr_key);
2304 plugin_unregister_shutdown("perl");
2306 } /* static void perl_shutdown (void) */
2309 * Access functions for global variables.
2311 * These functions implement the "magic" used to access
2312 * the global variables from Perl.
2315 static int g_pv_get(pTHX_ SV *var, MAGIC *mg) {
2316 char *pv = mg->mg_ptr;
2319 } /* static int g_pv_get (pTHX_ SV *, MAGIC *) */
2321 static int g_pv_set(pTHX_ SV *var, MAGIC *mg) {
2322 char *pv = mg->mg_ptr;
2323 sstrncpy(pv, SvPV_nolen(var), DATA_MAX_NAME_LEN);
2325 } /* static int g_pv_set (pTHX_ SV *, MAGIC *) */
2327 static int g_interval_get(pTHX_ SV *var, MAGIC *mg) {
2328 log_warn("Accessing $interval_g is deprecated (and might not "
2329 "give the desired results) - plugin_get_interval() should "
2330 "be used instead.");
2331 sv_setnv(var, CDTIME_T_TO_DOUBLE(interval_g));
2333 } /* static int g_interval_get (pTHX_ SV *, MAGIC *) */
2335 static int g_interval_set(pTHX_ SV *var, MAGIC *mg) {
2336 double nv = (double)SvNV(var);
2337 log_warn("Accessing $interval_g is deprecated (and might not "
2338 "give the desired results) - plugin_get_interval() should "
2339 "be used instead.");
2340 interval_g = DOUBLE_TO_CDTIME_T(nv);
2342 } /* static int g_interval_set (pTHX_ SV *, MAGIC *) */
2344 static MGVTBL g_pv_vtbl = {g_pv_get, g_pv_set, NULL, NULL, NULL, NULL, NULL
2345 #if HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL
2350 static MGVTBL g_interval_vtbl = {g_interval_get, g_interval_set, NULL, NULL,
2352 #if HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL
2358 /* bootstrap the Collectd module */
2359 static void xs_init(pTHX) {
2362 char *file = __FILE__;
2366 /* enable usage of Perl modules using shared libraries */
2367 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
2370 for (int i = 0; NULL != api[i].f; ++i)
2371 newXS(api[i].name, api[i].f, file);
2373 stash = gv_stashpv("Collectd", 1);
2375 /* export "constants" */
2376 for (int i = 0; '\0' != constants[i].name[0]; ++i)
2377 newCONSTSUB(stash, constants[i].name, newSViv(constants[i].value));
2379 /* export global variables
2380 * by adding "magic" to the SV's representing the globale variables
2381 * perl is able to automagically call the get/set function when
2382 * accessing any such variable (this is basically the same as using
2384 /* global strings */
2385 for (int i = 0; '\0' != g_strings[i].name[0]; ++i) {
2386 tmp = get_sv(g_strings[i].name, 1);
2387 sv_magicext(tmp, NULL, PERL_MAGIC_ext, &g_pv_vtbl, g_strings[i].var, 0);
2390 tmp = get_sv("Collectd::interval_g", /* create = */ 1);
2391 sv_magicext(tmp, NULL, /* how = */ PERL_MAGIC_ext,
2392 /* vtbl = */ &g_interval_vtbl,
2393 /* name = */ NULL, /* namelen = */ 0);
2396 } /* static void xs_init (pTHX) */
2398 /* Initialize the global Perl interpreter. */
2399 static int init_pi(int argc, char **argv) {
2402 if (NULL != perl_threads)
2405 log_info("Initializing Perl interpreter...");
2408 for (int i = 0; i < argc; ++i)
2409 log_debug("argv[%i] = \"%s\"", i, argv[i]);
2411 #endif /* COLLECT_DEBUG */
2413 if (0 != pthread_key_create(&perl_thr_key, c_ithread_destructor)) {
2414 log_err("init_pi: pthread_key_create failed");
2416 /* this must not happen - cowardly giving up if it does */
2421 /* On FreeBSD, PERL_SYS_INIT3 expands to some expression which
2422 * triggers a "value computed is not used" warning by gcc. */
2425 PERL_SYS_INIT3(&argc, &argv, &environ);
2427 perl_threads = smalloc(sizeof(*perl_threads));
2428 memset(perl_threads, 0, sizeof(c_ithread_list_t));
2430 pthread_mutexattr_init(&perl_threads->mutexattr);
2431 pthread_mutexattr_settype(&perl_threads->mutexattr, PTHREAD_MUTEX_RECURSIVE);
2432 pthread_mutex_init(&perl_threads->mutex, &perl_threads->mutexattr);
2433 /* locking the mutex should not be necessary at this point
2434 * but let's just do it for the sake of completeness */
2435 pthread_mutex_lock(&perl_threads->mutex);
2437 perl_threads->head = c_ithread_create(NULL);
2438 perl_threads->tail = perl_threads->head;
2440 if (NULL == (perl_threads->head->interp = perl_alloc())) {
2441 log_err("init_pi: Not enough memory.");
2445 aTHX = perl_threads->head->interp;
2446 pthread_mutex_unlock(&perl_threads->mutex);
2448 perl_construct(aTHX);
2450 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
2452 if (0 != perl_parse(aTHX_ xs_init, argc, argv, NULL)) {
2453 SV *err = get_sv("@", 1);
2454 log_err("init_pi: Unable to bootstrap Collectd: %s", SvPV_nolen(err));
2456 perl_destruct(perl_threads->head->interp);
2457 perl_free(perl_threads->head->interp);
2458 sfree(perl_threads);
2460 pthread_key_delete(perl_thr_key);
2464 /* Set $0 to "collectd" because perl_parse() has to set it to "-e". */
2465 sv_setpv(get_sv("0", 0), "collectd");
2469 plugin_register_init("perl", perl_init);
2470 plugin_register_shutdown("perl", perl_shutdown);
2472 } /* static int init_pi (const char **, const int) */
2475 * LoadPlugin "<Plugin>"
2477 static int perl_config_loadplugin(pTHX_ oconfig_item_t *ci) {
2478 char module_name[DATA_MAX_NAME_LEN];
2482 if ((0 != ci->children_num) || (1 != ci->values_num) ||
2483 (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2484 log_err("LoadPlugin expects a single string argument.");
2488 value = ci->values[0].value.string;
2490 if (NULL == get_module_name(module_name, sizeof(module_name), value)) {
2491 log_err("Invalid module name %s", value);
2495 if (0 != init_pi(perl_argc, perl_argv))
2498 assert(NULL != perl_threads);
2499 assert(NULL != perl_threads->head);
2501 aTHX = perl_threads->head->interp;
2503 log_debug("perl_config: Loading Perl plugin \"%s\"", value);
2504 load_module(PERL_LOADMOD_NOIMPORT, newSVpv(module_name, strlen(module_name)),
2507 } /* static int perl_config_loadplugin (oconfig_item_it *) */
2512 static int perl_config_basename(pTHX_ oconfig_item_t *ci) {
2515 if ((0 != ci->children_num) || (1 != ci->values_num) ||
2516 (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2517 log_err("BaseName expects a single string argument.");
2521 value = ci->values[0].value.string;
2523 log_debug("perl_config: Setting plugin basename to \"%s\"", value);
2524 sstrncpy(base_name, value, sizeof(base_name));
2526 } /* static int perl_config_basename (oconfig_item_it *) */
2529 * EnableDebugger "<Package>"|""
2531 static int perl_config_enabledebugger(pTHX_ oconfig_item_t *ci) {
2534 if ((0 != ci->children_num) || (1 != ci->values_num) ||
2535 (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2536 log_err("EnableDebugger expects a single string argument.");
2540 if (NULL != perl_threads) {
2541 log_warn("EnableDebugger has no effects if used after LoadPlugin.");
2545 value = ci->values[0].value.string;
2547 perl_argv = realloc(perl_argv, (++perl_argc + 1) * sizeof(char *));
2549 if (NULL == perl_argv) {
2550 log_err("perl_config: Not enough memory.");
2554 if ('\0' == value[0]) {
2555 perl_argv[perl_argc - 1] = "-d";
2557 perl_argv[perl_argc - 1] = smalloc(strlen(value) + 4);
2558 sstrncpy(perl_argv[perl_argc - 1], "-d:", 4);
2559 sstrncpy(perl_argv[perl_argc - 1] + 3, value, strlen(value) + 1);
2562 perl_argv[perl_argc] = NULL;
2564 } /* static int perl_config_enabledebugger (oconfig_item_it *) */
2567 * IncludeDir "<Dir>"
2569 static int perl_config_includedir(pTHX_ oconfig_item_t *ci) {
2572 if ((0 != ci->children_num) || (1 != ci->values_num) ||
2573 (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2574 log_err("IncludeDir expects a single string argument.");
2578 value = ci->values[0].value.string;
2581 perl_argv = realloc(perl_argv, (++perl_argc + 1) * sizeof(char *));
2583 if (NULL == perl_argv) {
2584 log_err("perl_config: Not enough memory.");
2588 perl_argv[perl_argc - 1] = smalloc(strlen(value) + 3);
2589 sstrncpy(perl_argv[perl_argc - 1], "-I", 3);
2590 sstrncpy(perl_argv[perl_argc - 1] + 2, value, strlen(value) + 1);
2592 perl_argv[perl_argc] = NULL;
2594 /* prepend the directory to @INC */
2595 av_unshift(GvAVn(PL_incgv), 1);
2596 av_store(GvAVn(PL_incgv), 0, newSVpv(value, strlen(value)));
2599 } /* static int perl_config_includedir (oconfig_item_it *) */
2604 static int perl_config_plugin(pTHX_ oconfig_item_t *ci) {
2613 if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2614 log_err("LoadPlugin expects a single string argument.");
2618 plugin = ci->values[0].value.string;
2621 if (0 != oconfig_item2hv(aTHX_ ci, config)) {
2625 log_err("Unable to convert configuration to a Perl hash value.");
2626 config = (HV *)&PL_sv_undef;
2634 XPUSHs(sv_2mortal(newSVpv(plugin, 0)));
2635 XPUSHs(sv_2mortal(newRV_noinc((SV *)config)));
2639 retvals = call_pv("Collectd::_plugin_dispatch_config", G_SCALAR);
2653 } /* static int perl_config_plugin (oconfig_item_it *) */
2655 static int perl_config(oconfig_item_t *ci) {
2660 for (int i = 0; i < ci->children_num; ++i) {
2661 oconfig_item_t *c = ci->children + i;
2662 int current_status = 0;
2664 if (NULL != perl_threads) {
2665 if ((aTHX = PERL_GET_CONTEXT) == NULL)
2669 if (0 == strcasecmp(c->key, "LoadPlugin"))
2670 current_status = perl_config_loadplugin(aTHX_ c);
2671 else if (0 == strcasecmp(c->key, "BaseName"))
2672 current_status = perl_config_basename(aTHX_ c);
2673 else if (0 == strcasecmp(c->key, "EnableDebugger"))
2674 current_status = perl_config_enabledebugger(aTHX_ c);
2675 else if (0 == strcasecmp(c->key, "IncludeDir"))
2676 current_status = perl_config_includedir(aTHX_ c);
2677 else if (0 == strcasecmp(c->key, "Plugin"))
2678 current_status = perl_config_plugin(aTHX_ c);
2679 else if (0 == strcasecmp(c->key, "RegisterLegacyFlush"))
2680 cf_util_get_boolean(c, ®ister_legacy_flush);
2682 log_warn("Ignoring unknown config key \"%s\".", c->key);
2686 /* fatal error - it's up to perl_config_* to clean up */
2687 if (0 > current_status) {
2688 log_err("Configuration failed with a fatal error - "
2689 "plugin disabled!");
2690 return current_status;
2693 status += current_status;
2696 } /* static int perl_config (oconfig_item_t *) */
2698 void module_register(void) {
2700 perl_argv = smalloc((perl_argc + 1) * sizeof(*perl_argv));
2702 /* default options for the Perl interpreter */
2704 perl_argv[1] = "-MCollectd";
2705 perl_argv[2] = "-e";
2707 perl_argv[4] = NULL;
2709 plugin_register_complex_config("perl", perl_config);
2711 } /* void module_register (void) */