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
44 /* Some versions of Perl define their own version of DEBUG... :-/ */
49 /* ... while we want the definition found in plugin.h. */
51 #include "utils/common/common.h"
53 #include "filter_chain.h"
55 #if !defined(USE_ITHREADS)
56 #error "Perl does not support ithreads!"
57 #endif /* !defined(USE_ITHREADS) */
59 /* clear the Perl sub's stack frame
60 * (this should only be used inside an XSUB) */
61 #define CLEAR_STACK_FRAME PL_stack_sp = PL_stack_base + *PL_markstack_ptr
65 #define PLUGIN_WRITE 2
66 #define PLUGIN_SHUTDOWN 3
68 #define PLUGIN_NOTIF 5
69 #define PLUGIN_FLUSH 6
70 #define PLUGIN_FLUSH_ALL 7 /* For collectd-5.6 only */
72 #define PLUGIN_TYPES 8
74 #define PLUGIN_CONFIG 254
75 #define PLUGIN_DATASET 255
82 #define FC_CB_CREATE 0
83 #define FC_CB_DESTROY 1
88 #define log_debug(...) DEBUG("perl: " __VA_ARGS__)
89 #define log_info(...) INFO("perl: " __VA_ARGS__)
90 #define log_warn(...) WARNING("perl: " __VA_ARGS__)
91 #define log_err(...) ERROR("perl: " __VA_ARGS__)
93 /* this is defined in DynaLoader.a */
94 void boot_DynaLoader(PerlInterpreter *, CV *);
96 static XS(Collectd_plugin_register_read);
97 static XS(Collectd_plugin_register_write);
98 static XS(Collectd_plugin_register_log);
99 static XS(Collectd_plugin_register_notification);
100 static XS(Collectd_plugin_register_flush);
101 static XS(Collectd_plugin_unregister_read);
102 static XS(Collectd_plugin_unregister_write);
103 static XS(Collectd_plugin_unregister_log);
104 static XS(Collectd_plugin_unregister_notification);
105 static XS(Collectd_plugin_unregister_flush);
106 static XS(Collectd_plugin_register_ds);
107 static XS(Collectd_plugin_unregister_ds);
108 static XS(Collectd_plugin_dispatch_values);
109 static XS(Collectd_plugin_get_interval);
110 static XS(Collectd__plugin_write);
111 static XS(Collectd__plugin_flush);
112 static XS(Collectd_plugin_dispatch_notification);
113 static XS(Collectd_plugin_log);
114 static XS(Collectd__fc_register);
115 static XS(Collectd_call_by_name);
117 static int perl_read(user_data_t *ud);
118 static int perl_write(const data_set_t *ds, const value_list_t *vl,
119 user_data_t *user_data);
120 static void perl_log(int level, const char *msg, user_data_t *user_data);
121 static int perl_notify(const notification_t *notif, user_data_t *user_data);
122 static int perl_flush(cdtime_t timeout, const char *identifier,
123 user_data_t *user_data);
129 typedef struct c_ithread_s {
130 /* the thread's Perl interpreter */
131 PerlInterpreter *interp;
132 bool running; /* thread is inside Perl interpreter */
136 /* double linked list of threads */
137 struct c_ithread_s *prev;
138 struct c_ithread_s *next;
146 /* some usage stats */
147 int number_of_threads;
148 #endif /* COLLECT_DEBUG */
150 pthread_mutex_t mutex;
151 pthread_mutexattr_t mutexattr;
154 /* name / user_data for Perl matches / targets */
160 #define PFC_USER_DATA_FREE(data) \
162 sfree((data)->name); \
163 if (NULL != (data)->user_data) \
164 sv_free((data)->user_data); \
171 extern char **environ;
177 static bool register_legacy_flush = true;
179 /* if perl_threads != NULL perl_threads->head must
180 * point to the "base" thread */
181 static c_ithread_list_t *perl_threads;
183 /* the key used to store each pthread's ithread */
184 static pthread_key_t perl_thr_key;
186 static int perl_argc;
187 static char **perl_argv;
189 static char base_name[DATA_MAX_NAME_LEN] = "";
195 {"Collectd::plugin_register_read", Collectd_plugin_register_read},
196 {"Collectd::plugin_register_write", Collectd_plugin_register_write},
197 {"Collectd::plugin_register_log", Collectd_plugin_register_log},
198 {"Collectd::plugin_register_notification",
199 Collectd_plugin_register_notification},
200 {"Collectd::plugin_register_flush", Collectd_plugin_register_flush},
201 {"Collectd::plugin_unregister_read", Collectd_plugin_unregister_read},
202 {"Collectd::plugin_unregister_write", Collectd_plugin_unregister_write},
203 {"Collectd::plugin_unregister_log", Collectd_plugin_unregister_log},
204 {"Collectd::plugin_unregister_notification",
205 Collectd_plugin_unregister_notification},
206 {"Collectd::plugin_unregister_flush", Collectd_plugin_unregister_flush},
207 {"Collectd::plugin_register_data_set", Collectd_plugin_register_ds},
208 {"Collectd::plugin_unregister_data_set", Collectd_plugin_unregister_ds},
209 {"Collectd::plugin_dispatch_values", Collectd_plugin_dispatch_values},
210 {"Collectd::plugin_get_interval", Collectd_plugin_get_interval},
211 {"Collectd::_plugin_write", Collectd__plugin_write},
212 {"Collectd::_plugin_flush", Collectd__plugin_flush},
213 {"Collectd::plugin_dispatch_notification",
214 Collectd_plugin_dispatch_notification},
215 {"Collectd::plugin_log", Collectd_plugin_log},
216 {"Collectd::_fc_register", Collectd__fc_register},
217 {"Collectd::call_by_name", Collectd_call_by_name},
223 } constants[] = {{"Collectd::TYPE_INIT", PLUGIN_INIT},
224 {"Collectd::TYPE_READ", PLUGIN_READ},
225 {"Collectd::TYPE_WRITE", PLUGIN_WRITE},
226 {"Collectd::TYPE_SHUTDOWN", PLUGIN_SHUTDOWN},
227 {"Collectd::TYPE_LOG", PLUGIN_LOG},
228 {"Collectd::TYPE_NOTIF", PLUGIN_NOTIF},
229 {"Collectd::TYPE_FLUSH", PLUGIN_FLUSH},
230 {"Collectd::TYPE_CONFIG", PLUGIN_CONFIG},
231 {"Collectd::TYPE_DATASET", PLUGIN_DATASET},
232 {"Collectd::DS_TYPE_COUNTER", DS_TYPE_COUNTER},
233 {"Collectd::DS_TYPE_GAUGE", DS_TYPE_GAUGE},
234 {"Collectd::DS_TYPE_DERIVE", DS_TYPE_DERIVE},
235 {"Collectd::DS_TYPE_ABSOLUTE", DS_TYPE_ABSOLUTE},
236 {"Collectd::LOG_ERR", LOG_ERR},
237 {"Collectd::LOG_WARNING", LOG_WARNING},
238 {"Collectd::LOG_NOTICE", LOG_NOTICE},
239 {"Collectd::LOG_INFO", LOG_INFO},
240 {"Collectd::LOG_DEBUG", LOG_DEBUG},
241 {"Collectd::FC_MATCH", FC_MATCH},
242 {"Collectd::FC_TARGET", FC_TARGET},
243 {"Collectd::FC_CB_CREATE", FC_CB_CREATE},
244 {"Collectd::FC_CB_DESTROY", FC_CB_DESTROY},
245 {"Collectd::FC_CB_EXEC", FC_CB_EXEC},
246 {"Collectd::FC_MATCH_NO_MATCH", FC_MATCH_NO_MATCH},
247 {"Collectd::FC_MATCH_MATCHES", FC_MATCH_MATCHES},
248 {"Collectd::FC_TARGET_CONTINUE", FC_TARGET_CONTINUE},
249 {"Collectd::FC_TARGET_STOP", FC_TARGET_STOP},
250 {"Collectd::FC_TARGET_RETURN", FC_TARGET_RETURN},
251 {"Collectd::NOTIF_FAILURE", NOTIF_FAILURE},
252 {"Collectd::NOTIF_WARNING", NOTIF_WARNING},
253 {"Collectd::NOTIF_OKAY", NOTIF_OKAY},
256 * Helper functions for data type conversion.
271 static int hv2data_source(pTHX_ HV *hash, data_source_t *ds) {
274 if ((NULL == hash) || (NULL == ds))
277 if (NULL != (tmp = hv_fetch(hash, "name", 4, 0))) {
278 sstrncpy(ds->name, SvPV_nolen(*tmp), sizeof(ds->name));
280 log_err("hv2data_source: No DS name given.");
284 if (NULL != (tmp = hv_fetch(hash, "type", 4, 0))) {
285 ds->type = SvIV(*tmp);
287 if ((DS_TYPE_COUNTER != ds->type) && (DS_TYPE_GAUGE != ds->type) &&
288 (DS_TYPE_DERIVE != ds->type) && (DS_TYPE_ABSOLUTE != ds->type)) {
289 log_err("hv2data_source: Invalid DS type.");
293 ds->type = DS_TYPE_COUNTER;
296 if (NULL != (tmp = hv_fetch(hash, "min", 3, 0)))
297 ds->min = SvNV(*tmp);
301 if (NULL != (tmp = hv_fetch(hash, "max", 3, 0)))
302 ds->max = SvNV(*tmp);
306 } /* static int hv2data_source (HV *, data_source_t *) */
308 /* av2value converts at most "len" elements from "array" to "value". Returns the
309 * number of elements converted or zero on error. */
310 static size_t av2value(pTHX_ char *name, AV *array, value_t *value,
312 const data_set_t *ds;
314 if ((NULL == name) || (NULL == array) || (NULL == value) || (array_len == 0))
317 ds = plugin_get_ds(name);
319 log_err("av2value: Unknown dataset \"%s\"", name);
323 if (array_len < ds->ds_num) {
324 log_warn("av2value: array does not contain enough elements for type "
325 "\"%s\": got %" PRIsz ", want %" PRIsz,
326 name, array_len, ds->ds_num);
328 } else if (array_len > ds->ds_num) {
329 log_warn("av2value: array contains excess elements for type \"%s\": got "
330 "%" PRIsz ", want %" PRIsz,
331 name, array_len, ds->ds_num);
334 for (size_t i = 0; i < ds->ds_num; ++i) {
335 SV **tmp = av_fetch(array, i, 0);
338 if (DS_TYPE_COUNTER == ds->ds[i].type)
339 value[i].counter = SvIV(*tmp);
340 else if (DS_TYPE_GAUGE == ds->ds[i].type)
341 value[i].gauge = SvNV(*tmp);
342 else if (DS_TYPE_DERIVE == ds->ds[i].type)
343 value[i].derive = SvIV(*tmp);
344 else if (DS_TYPE_ABSOLUTE == ds->ds[i].type)
345 value[i].absolute = SvIV(*tmp);
352 } /* static size_t av2value (char *, AV *, value_t *, size_t) */
357 * values => [ @values ],
361 * plugin_instance => $pinstance,
362 * type_instance => $tinstance,
365 static int hv2value_list(pTHX_ HV *hash, value_list_t *vl) {
368 if ((NULL == hash) || (NULL == vl))
371 if (NULL == (tmp = hv_fetch(hash, "type", 4, 0))) {
372 log_err("hv2value_list: No type given.");
376 sstrncpy(vl->type, SvPV_nolen(*tmp), sizeof(vl->type));
378 if ((NULL == (tmp = hv_fetch(hash, "values", 6, 0))) ||
379 (!(SvROK(*tmp) && (SVt_PVAV == SvTYPE(SvRV(*tmp)))))) {
380 log_err("hv2value_list: No valid values given.");
385 AV *array = (AV *)SvRV(*tmp);
386 /* av_len returns the highest index, not the actual length. */
387 size_t array_len = (size_t)(av_len(array) + 1);
391 vl->values = calloc(array_len, sizeof(*vl->values));
393 av2value(aTHX_ vl->type, (AV *)SvRV(*tmp), vl->values, array_len);
394 if (vl->values_len == 0) {
400 if (NULL != (tmp = hv_fetch(hash, "time", 4, 0))) {
401 double t = SvNV(*tmp);
402 vl->time = DOUBLE_TO_CDTIME_T(t);
405 if (NULL != (tmp = hv_fetch(hash, "interval", 8, 0))) {
406 double t = SvNV(*tmp);
407 vl->interval = DOUBLE_TO_CDTIME_T(t);
410 if (NULL != (tmp = hv_fetch(hash, "host", 4, 0)))
411 sstrncpy(vl->host, SvPV_nolen(*tmp), sizeof(vl->host));
413 if (NULL != (tmp = hv_fetch(hash, "plugin", 6, 0)))
414 sstrncpy(vl->plugin, SvPV_nolen(*tmp), sizeof(vl->plugin));
416 if (NULL != (tmp = hv_fetch(hash, "plugin_instance", 15, 0)))
417 sstrncpy(vl->plugin_instance, SvPV_nolen(*tmp),
418 sizeof(vl->plugin_instance));
420 if (NULL != (tmp = hv_fetch(hash, "type_instance", 13, 0)))
421 sstrncpy(vl->type_instance, SvPV_nolen(*tmp), sizeof(vl->type_instance));
423 } /* static int hv2value_list (pTHX_ HV *, value_list_t *) */
425 static int av2data_set(pTHX_ AV *array, char *name, data_set_t *ds) {
428 if ((NULL == array) || (NULL == name) || (NULL == ds))
434 log_err("av2data_set: Invalid data set.");
438 ds->ds = smalloc((len + 1) * sizeof(*ds->ds));
439 ds->ds_num = len + 1;
441 for (int i = 0; i <= len; ++i) {
442 SV **elem = av_fetch(array, i, 0);
445 log_err("av2data_set: Failed to fetch data source %i.", i);
449 if (!(SvROK(*elem) && (SVt_PVHV == SvTYPE(SvRV(*elem))))) {
450 log_err("av2data_set: Invalid data source.");
454 if (-1 == hv2data_source(aTHX_(HV *) SvRV(*elem), &ds->ds[i]))
457 log_debug("av2data_set: "
458 "DS.name = \"%s\", DS.type = %i, DS.min = %f, DS.max = %f",
459 ds->ds[i].name, ds->ds[i].type, ds->ds[i].min, ds->ds[i].max);
462 sstrncpy(ds->type, name, sizeof(ds->type));
464 } /* static int av2data_set (pTHX_ AV *, data_set_t *) */
469 * severity => $severity,
475 * plugin_instance => $instance,
476 * type_instance => $type_instance,
477 * meta => [ { name => <name>, value => <value> }, ... ]
480 static int av2notification_meta(pTHX_ AV *array,
481 notification_meta_t **ret_meta) {
482 notification_meta_t *tail = NULL;
484 int len = av_len(array);
486 for (int i = 0; i <= len; ++i) {
487 SV **tmp = av_fetch(array, i, 0);
492 if (!(SvROK(*tmp) && (SVt_PVHV == SvTYPE(SvRV(*tmp))))) {
493 log_warn("av2notification_meta: Skipping invalid "
494 "meta information.");
498 HV *hash = (HV *)SvRV(*tmp);
500 notification_meta_t *m = calloc(1, sizeof(*m));
504 SV **name = hv_fetch(hash, "name", strlen("name"), 0);
506 log_warn("av2notification_meta: Skipping invalid "
507 "meta information.");
511 sstrncpy(m->name, SvPV_nolen(*name), sizeof(m->name));
513 SV **value = hv_fetch(hash, "value", strlen("value"), 0);
515 log_warn("av2notification_meta: Skipping invalid "
516 "meta information.");
522 m->nm_value.nm_double = SvNVX(*value);
523 m->type = NM_TYPE_DOUBLE;
524 } else if (SvUOK(*value)) {
525 m->nm_value.nm_unsigned_int = SvUVX(*value);
526 m->type = NM_TYPE_UNSIGNED_INT;
527 } else if (SvIOK(*value)) {
528 m->nm_value.nm_signed_int = SvIVX(*value);
529 m->type = NM_TYPE_SIGNED_INT;
531 m->nm_value.nm_string = sstrdup(SvPV_nolen(*value));
532 m->type = NM_TYPE_STRING;
544 } /* static int av2notification_meta (AV *, notification_meta_t *) */
546 static int hv2notification(pTHX_ HV *hash, notification_t *n) {
549 if ((NULL == hash) || (NULL == n))
552 if (NULL != (tmp = hv_fetch(hash, "severity", 8, 0)))
553 n->severity = SvIV(*tmp);
555 n->severity = NOTIF_FAILURE;
557 if (NULL != (tmp = hv_fetch(hash, "time", 4, 0))) {
558 double t = SvNV(*tmp);
559 n->time = DOUBLE_TO_CDTIME_T(t);
563 if (NULL != (tmp = hv_fetch(hash, "message", 7, 0)))
564 sstrncpy(n->message, SvPV_nolen(*tmp), sizeof(n->message));
566 if (NULL != (tmp = hv_fetch(hash, "host", 4, 0)))
567 sstrncpy(n->host, SvPV_nolen(*tmp), sizeof(n->host));
569 sstrncpy(n->host, hostname_g, sizeof(n->host));
571 if (NULL != (tmp = hv_fetch(hash, "plugin", 6, 0)))
572 sstrncpy(n->plugin, SvPV_nolen(*tmp), sizeof(n->plugin));
574 if (NULL != (tmp = hv_fetch(hash, "plugin_instance", 15, 0)))
575 sstrncpy(n->plugin_instance, SvPV_nolen(*tmp), sizeof(n->plugin_instance));
577 if (NULL != (tmp = hv_fetch(hash, "type", 4, 0)))
578 sstrncpy(n->type, SvPV_nolen(*tmp), sizeof(n->type));
580 if (NULL != (tmp = hv_fetch(hash, "type_instance", 13, 0)))
581 sstrncpy(n->type_instance, SvPV_nolen(*tmp), sizeof(n->type_instance));
584 while (NULL != (tmp = hv_fetch(hash, "meta", 4, 0))) {
585 if (!(SvROK(*tmp) && (SVt_PVAV == SvTYPE(SvRV(*tmp))))) {
586 log_warn("hv2notification: Ignoring invalid meta information.");
590 if (0 != av2notification_meta(aTHX_(AV *) SvRV(*tmp), &n->meta)) {
591 plugin_notification_meta_free(n->meta);
598 } /* static int hv2notification (pTHX_ HV *, notification_t *) */
600 static int data_set2av(pTHX_ data_set_t *ds, AV *array) {
601 if ((NULL == ds) || (NULL == array))
604 av_extend(array, ds->ds_num);
606 for (size_t i = 0; i < ds->ds_num; ++i) {
607 HV *source = newHV();
609 if (NULL == hv_store(source, "name", 4, newSVpv(ds->ds[i].name, 0), 0))
612 if (NULL == hv_store(source, "type", 4, newSViv(ds->ds[i].type), 0))
615 if (!isnan(ds->ds[i].min))
616 if (NULL == hv_store(source, "min", 3, newSVnv(ds->ds[i].min), 0))
619 if (!isnan(ds->ds[i].max))
620 if (NULL == hv_store(source, "max", 3, newSVnv(ds->ds[i].max), 0))
623 if (NULL == av_store(array, i, newRV_noinc((SV *)source)))
627 } /* static int data_set2av (data_set_t *, AV *) */
629 static int value_list2hv(pTHX_ value_list_t *vl, data_set_t *ds, HV *hash) {
633 if ((NULL == vl) || (NULL == ds) || (NULL == hash))
637 /* av_extend takes the last *index* to which the array should be extended. */
638 av_extend(values, vl->values_len - 1);
640 assert(ds->ds_num == vl->values_len);
641 for (i = 0; i < vl->values_len; ++i) {
644 if (DS_TYPE_COUNTER == ds->ds[i].type)
645 val = newSViv(vl->values[i].counter);
646 else if (DS_TYPE_GAUGE == ds->ds[i].type)
647 val = newSVnv(vl->values[i].gauge);
648 else if (DS_TYPE_DERIVE == ds->ds[i].type)
649 val = newSViv(vl->values[i].derive);
650 else if (DS_TYPE_ABSOLUTE == ds->ds[i].type)
651 val = newSViv(vl->values[i].absolute);
653 if (NULL == av_store(values, i, val)) {
659 if (NULL == hv_store(hash, "values", 6, newRV_noinc((SV *)values), 0))
663 double t = CDTIME_T_TO_DOUBLE(vl->time);
664 if (NULL == hv_store(hash, "time", 4, newSVnv(t), 0))
669 double t = CDTIME_T_TO_DOUBLE(vl->interval);
670 if (NULL == hv_store(hash, "interval", 8, newSVnv(t), 0))
674 if ('\0' != vl->host[0])
675 if (NULL == hv_store(hash, "host", 4, newSVpv(vl->host, 0), 0))
678 if ('\0' != vl->plugin[0])
679 if (NULL == hv_store(hash, "plugin", 6, newSVpv(vl->plugin, 0), 0))
682 if ('\0' != vl->plugin_instance[0])
683 if (NULL == hv_store(hash, "plugin_instance", 15,
684 newSVpv(vl->plugin_instance, 0), 0))
687 if ('\0' != vl->type[0])
688 if (NULL == hv_store(hash, "type", 4, newSVpv(vl->type, 0), 0))
691 if ('\0' != vl->type_instance[0])
693 hv_store(hash, "type_instance", 13, newSVpv(vl->type_instance, 0), 0))
696 } /* static int value2av (value_list_t *, data_set_t *, HV *) */
698 static int notification_meta2av(pTHX_ notification_meta_t *meta, AV *array) {
700 for (notification_meta_t *m = meta; m != NULL; m = m->next) {
704 av_extend(array, meta_num);
706 for (int i = 0; NULL != meta; meta = meta->next, ++i) {
710 if (NULL == hv_store(m, "name", 4, newSVpv(meta->name, 0), 0))
713 if (NM_TYPE_STRING == meta->type)
714 value = newSVpv(meta->nm_value.nm_string, 0);
715 else if (NM_TYPE_SIGNED_INT == meta->type)
716 value = newSViv(meta->nm_value.nm_signed_int);
717 else if (NM_TYPE_UNSIGNED_INT == meta->type)
718 value = newSVuv(meta->nm_value.nm_unsigned_int);
719 else if (NM_TYPE_DOUBLE == meta->type)
720 value = newSVnv(meta->nm_value.nm_double);
721 else if (NM_TYPE_BOOLEAN == meta->type)
722 value = meta->nm_value.nm_boolean ? &PL_sv_yes : &PL_sv_no;
726 if (NULL == hv_store(m, "value", 5, value, 0)) {
731 if (NULL == av_store(array, i, newRV_noinc((SV *)m))) {
738 } /* static int notification_meta2av (notification_meta_t *, AV *) */
740 static int notification2hv(pTHX_ notification_t *n, HV *hash) {
741 if (NULL == hv_store(hash, "severity", 8, newSViv(n->severity), 0))
745 double t = CDTIME_T_TO_DOUBLE(n->time);
746 if (NULL == hv_store(hash, "time", 4, newSVnv(t), 0))
750 if ('\0' != *n->message)
751 if (NULL == hv_store(hash, "message", 7, newSVpv(n->message, 0), 0))
754 if ('\0' != *n->host)
755 if (NULL == hv_store(hash, "host", 4, newSVpv(n->host, 0), 0))
758 if ('\0' != *n->plugin)
759 if (NULL == hv_store(hash, "plugin", 6, newSVpv(n->plugin, 0), 0))
762 if ('\0' != *n->plugin_instance)
763 if (NULL == hv_store(hash, "plugin_instance", 15,
764 newSVpv(n->plugin_instance, 0), 0))
767 if ('\0' != *n->type)
768 if (NULL == hv_store(hash, "type", 4, newSVpv(n->type, 0), 0))
771 if ('\0' != *n->type_instance)
773 hv_store(hash, "type_instance", 13, newSVpv(n->type_instance, 0), 0))
776 if (NULL != n->meta) {
778 if ((0 != notification_meta2av(aTHX_ n->meta, meta)) ||
779 (NULL == hv_store(hash, "meta", 4, newRV_noinc((SV *)meta), 0))) {
786 } /* static int notification2hv (notification_t *, HV *) */
788 static int oconfig_item2hv(pTHX_ oconfig_item_t *ci, HV *hash) {
792 if (NULL == hv_store(hash, "key", 3, newSVpv(ci->key, 0), 0))
796 if (0 < ci->values_num)
797 av_extend(values, ci->values_num);
799 if (NULL == hv_store(hash, "values", 6, newRV_noinc((SV *)values), 0)) {
805 for (int i = 0; i < ci->values_num; ++i) {
808 switch (ci->values[i].type) {
809 case OCONFIG_TYPE_STRING:
810 value = newSVpv(ci->values[i].value.string, 0);
812 case OCONFIG_TYPE_NUMBER:
813 value = newSVnv((NV)ci->values[i].value.number);
815 case OCONFIG_TYPE_BOOLEAN:
816 value = ci->values[i].value.boolean ? &PL_sv_yes : &PL_sv_no;
819 log_err("oconfig_item2hv: Invalid value type %i.", ci->values[i].type);
820 value = &PL_sv_undef;
823 if (NULL == av_store(values, i, value)) {
829 /* ignoring 'parent' member which is uninteresting in this case */
832 if (0 < ci->children_num)
833 av_extend(children, ci->children_num);
835 if (NULL == hv_store(hash, "children", 8, newRV_noinc((SV *)children), 0)) {
841 for (int i = 0; i < ci->children_num; ++i) {
844 if (0 != oconfig_item2hv(aTHX_ ci->children + i, child)) {
850 if (NULL == av_store(children, i, newRV_noinc((SV *)child))) {
857 } /* static int oconfig_item2hv (pTHX_ oconfig_item_t *, HV *) */
860 * Internal functions.
863 static char *get_module_name(char *buf, size_t buf_len, const char *module) {
865 if (base_name[0] == '\0')
866 status = snprintf(buf, buf_len, "%s", module);
868 status = snprintf(buf, buf_len, "%s::%s", base_name, module);
869 if ((status < 0) || ((unsigned int)status >= buf_len))
872 } /* char *get_module_name */
875 * Add a plugin's data set definition.
877 static int pplugin_register_data_set(pTHX_ char *name, AV *dataset) {
882 if ((NULL == name) || (NULL == dataset))
885 if (0 != av2data_set(aTHX_ dataset, name, &ds))
888 ret = plugin_register_data_set(&ds);
892 } /* static int pplugin_register_data_set (char *, SV *) */
895 * Remove a plugin's data set definition.
897 static int pplugin_unregister_data_set(char *name) {
900 return plugin_unregister_data_set(name);
901 } /* static int pplugin_unregister_data_set (char *) */
904 * Submit the values to the write functions.
906 static int pplugin_dispatch_values(pTHX_ HV *values) {
907 value_list_t vl = VALUE_LIST_INIT;
914 if (0 != hv2value_list(aTHX_ values, &vl))
917 ret = plugin_dispatch_values(&vl);
921 } /* static int pplugin_dispatch_values (char *, HV *) */
924 * Submit the values to a single write function.
926 static int pplugin_write(pTHX_ const char *plugin, AV *data_set, HV *values) {
928 value_list_t vl = VALUE_LIST_INIT;
935 if (0 != hv2value_list(aTHX_ values, &vl))
938 if ((NULL != data_set) && (0 != av2data_set(aTHX_ data_set, vl.type, &ds)))
941 ret = plugin_write(plugin, NULL == data_set ? NULL : &ds, &vl);
943 log_warn("Dispatching value to plugin \"%s\" failed with status %i.",
944 NULL == plugin ? "<any>" : plugin, ret);
946 if (NULL != data_set)
950 } /* static int pplugin_write (const char *plugin, HV *, HV *) */
953 * Dispatch a notification.
955 static int pplugin_dispatch_notification(pTHX_ HV *notif) {
956 notification_t n = {0};
963 if (0 != hv2notification(aTHX_ notif, &n))
966 ret = plugin_dispatch_notification(&n);
967 plugin_notification_meta_free(n.meta);
969 } /* static int pplugin_dispatch_notification (HV *) */
972 * Call perl sub with thread locking flags handled.
974 static int call_pv_locked(pTHX_ const char *sub_name) {
978 c_ithread_t *t = (c_ithread_t *)pthread_getspecific(perl_thr_key);
979 if (t == NULL) /* thread destroyed */
982 old_running = t->running;
986 t->running = old_running;
990 ret = call_pv(sub_name, G_SCALAR | G_EVAL);
992 t->running = old_running;
994 } /* static int call_pv_locked (pTHX, *sub_name) */
997 * Call all working functions of the given type.
999 static int pplugin_call(pTHX_ int type, ...) {
1008 if ((type < 0) || (type >= PLUGIN_TYPES))
1018 if (PLUGIN_READ == type) {
1019 subname = va_arg(ap, char *);
1020 } else if (PLUGIN_WRITE == type) {
1027 subname = va_arg(ap, char *);
1029 * $_[0] = $plugin_type;
1044 * values => [ $v1, ... ],
1046 * host => $hostname,
1047 * plugin => $plugin,
1049 * plugin_instance => $instance,
1050 * type_instance => $type_instance
1053 ds = va_arg(ap, data_set_t *);
1054 vl = va_arg(ap, value_list_t *);
1056 if (-1 == data_set2av(aTHX_ ds, pds)) {
1059 pds = (AV *)&PL_sv_undef;
1063 if (-1 == value_list2hv(aTHX_ vl, ds, pvl)) {
1066 pvl = (HV *)&PL_sv_undef;
1070 XPUSHs(sv_2mortal(newSVpv(ds->type, 0)));
1071 XPUSHs(sv_2mortal(newRV_noinc((SV *)pds)));
1072 XPUSHs(sv_2mortal(newRV_noinc((SV *)pvl)));
1073 } else if (PLUGIN_LOG == type) {
1074 subname = va_arg(ap, char *);
1080 XPUSHs(sv_2mortal(newSViv(va_arg(ap, int))));
1081 XPUSHs(sv_2mortal(newSVpv(va_arg(ap, char *), 0)));
1082 } else if (PLUGIN_NOTIF == type) {
1084 HV *notif = newHV();
1086 subname = va_arg(ap, char *);
1090 * severity => $severity,
1094 * plugin => $plugin,
1096 * plugin_instance => $instance,
1097 * type_instance => $type_instance
1100 n = va_arg(ap, notification_t *);
1102 if (-1 == notification2hv(aTHX_ n, notif)) {
1105 notif = (HV *)&PL_sv_undef;
1109 XPUSHs(sv_2mortal(newRV_noinc((SV *)notif)));
1110 } else if (PLUGIN_FLUSH == type) {
1112 subname = va_arg(ap, char *);
1115 * $_[1] = $identifier;
1117 timeout = va_arg(ap, cdtime_t);
1119 XPUSHs(sv_2mortal(newSVnv(CDTIME_T_TO_DOUBLE(timeout))));
1120 XPUSHs(sv_2mortal(newSVpv(va_arg(ap, char *), 0)));
1121 } else if (PLUGIN_FLUSH_ALL == type) {
1123 subname = "Collectd::plugin_call_all";
1126 * $_[1] = $identifier;
1128 timeout = va_arg(ap, cdtime_t);
1130 XPUSHs(sv_2mortal(newSViv((IV)PLUGIN_FLUSH)));
1131 XPUSHs(sv_2mortal(newSVnv(CDTIME_T_TO_DOUBLE(timeout))));
1132 XPUSHs(sv_2mortal(newSVpv(va_arg(ap, char *), 0)));
1133 } else if (PLUGIN_INIT == type) {
1134 subname = "Collectd::plugin_call_all";
1135 XPUSHs(sv_2mortal(newSViv((IV)type)));
1136 } else if (PLUGIN_SHUTDOWN == type) {
1137 subname = "Collectd::plugin_call_all";
1138 XPUSHs(sv_2mortal(newSViv((IV)type)));
1139 } else { /* Unknown type. Run 'plugin_call_all' and make compiler happy */
1140 subname = "Collectd::plugin_call_all";
1141 XPUSHs(sv_2mortal(newSViv((IV)type)));
1146 retvals = call_pv_locked(aTHX_ subname);
1149 if (SvTRUE(ERRSV)) {
1150 if (PLUGIN_LOG != type)
1151 ERROR("perl: %s error: %s", subname, SvPV_nolen(ERRSV));
1153 } else if (0 < retvals) {
1165 } /* static int pplugin_call (int, ...) */
1168 * collectd's Perl interpreter based thread implementation.
1170 * This has been inspired by Perl's ithreads introduced in version 5.6.0.
1173 /* must be called with perl_threads->mutex locked */
1174 static void c_ithread_destroy(c_ithread_t *ithread) {
1175 dTHXa(ithread->interp);
1177 assert(NULL != perl_threads);
1179 PERL_SET_CONTEXT(aTHX);
1180 /* Mark as running to avoid deadlock:
1181 c_ithread_destroy -> log_debug -> perl_log()
1183 ithread->running = true;
1184 log_debug("Shutting down Perl interpreter %p...", aTHX);
1189 --perl_threads->number_of_threads;
1190 #endif /* COLLECT_DEBUG */
1192 perl_destruct(aTHX);
1195 if (NULL == ithread->prev)
1196 perl_threads->head = ithread->next;
1198 ithread->prev->next = ithread->next;
1200 if (NULL == ithread->next)
1201 perl_threads->tail = ithread->prev;
1203 ithread->next->prev = ithread->prev;
1207 } /* static void c_ithread_destroy (c_ithread_t *) */
1209 static void c_ithread_destructor(void *arg) {
1210 c_ithread_t *ithread = (c_ithread_t *)arg;
1211 c_ithread_t *t = NULL;
1213 if (NULL == perl_threads)
1216 pthread_mutex_lock(&perl_threads->mutex);
1218 for (t = perl_threads->head; NULL != t; t = t->next)
1222 /* the ithread no longer exists */
1224 pthread_mutex_unlock(&perl_threads->mutex);
1228 c_ithread_destroy(ithread);
1230 pthread_mutex_unlock(&perl_threads->mutex);
1232 } /* static void c_ithread_destructor (void *) */
1234 /* must be called with perl_threads->mutex locked */
1235 static c_ithread_t *c_ithread_create(PerlInterpreter *base) {
1236 c_ithread_t *t = NULL;
1239 assert(NULL != perl_threads);
1241 t = smalloc(sizeof(*t));
1242 memset(t, 0, sizeof(c_ithread_t));
1244 t->interp = (NULL == base) ? NULL : perl_clone(base, CLONEf_KEEP_PTR_TABLE);
1248 if ((NULL != base) && (NULL != PL_endav)) {
1255 ++perl_threads->number_of_threads;
1256 #endif /* COLLECT_DEBUG */
1260 if (NULL == perl_threads->tail) {
1261 perl_threads->head = t;
1264 perl_threads->tail->next = t;
1265 t->prev = perl_threads->tail;
1268 t->pthread = pthread_self();
1270 t->shutdown = false;
1271 perl_threads->tail = t;
1273 pthread_setspecific(perl_thr_key, (const void *)t);
1275 } /* static c_ithread_t *c_ithread_create (PerlInterpreter *) */
1278 * Filter chains implementation.
1281 static int fc_call(pTHX_ int type, int cb_type, pfc_user_data_t *data, ...) {
1287 notification_meta_t **meta = NULL;
1292 if ((type < 0) || (type >= FC_TYPES))
1295 if ((cb_type < 0) || (cb_type >= FC_CB_TYPES))
1305 XPUSHs(sv_2mortal(newSViv((IV)type)));
1306 XPUSHs(sv_2mortal(newSVpv(data->name, 0)));
1307 XPUSHs(sv_2mortal(newSViv((IV)cb_type)));
1309 if (FC_CB_CREATE == cb_type) {
1312 * $_[1] = $user_data;
1315 HV *config = newHV();
1317 ci = va_arg(ap, oconfig_item_t *);
1319 if (0 != oconfig_item2hv(aTHX_ ci, config)) {
1322 config = (HV *)&PL_sv_undef;
1326 XPUSHs(sv_2mortal(newRV_noinc((SV *)config)));
1327 } else if (FC_CB_DESTROY == cb_type) {
1329 * $_[1] = $user_data;
1332 /* nothing to be done - the user data pointer
1333 * is pushed onto the stack later */
1334 } else if (FC_CB_EXEC == cb_type) {
1339 * $_[3] = $user_data;
1347 ds = va_arg(ap, data_set_t *);
1348 vl = va_arg(ap, value_list_t *);
1349 meta = va_arg(ap, notification_meta_t **);
1351 if (0 != data_set2av(aTHX_ ds, pds)) {
1354 pds = (AV *)&PL_sv_undef;
1358 if (0 != value_list2hv(aTHX_ vl, ds, pvl)) {
1361 pvl = (HV *)&PL_sv_undef;
1368 if (0 != notification_meta2av(aTHX_ * meta, pmeta)) {
1371 pmeta = (AV *)&PL_sv_undef;
1375 pmeta = (AV *)&PL_sv_undef;
1378 XPUSHs(sv_2mortal(newRV_noinc((SV *)pds)));
1379 XPUSHs(sv_2mortal(newRV_noinc((SV *)pvl)));
1380 XPUSHs(sv_2mortal(newRV_noinc((SV *)pmeta)));
1383 XPUSHs(sv_2mortal(newRV_inc(data->user_data)));
1387 retvals = call_pv_locked(aTHX_ "Collectd::fc_call");
1389 if ((FC_CB_EXEC == cb_type) && (meta != NULL)) {
1390 assert(pmeta != NULL);
1392 plugin_notification_meta_free(*meta);
1393 av2notification_meta(aTHX_ pmeta, meta);
1397 if (SvTRUE(ERRSV)) {
1398 ERROR("perl: Collectd::fc_call error: %s", SvPV_nolen(ERRSV));
1400 } else if (0 < retvals) {
1403 /* the exec callbacks return a status, while
1404 * the others return a boolean value */
1405 if (FC_CB_EXEC == cb_type)
1407 else if (!SvTRUE(tmp))
1417 } /* static int fc_call (int, int, pfc_user_data_t *, ...) */
1419 static int fc_create(int type, const oconfig_item_t *ci, void **user_data) {
1420 pfc_user_data_t *data;
1426 if (NULL == perl_threads)
1430 c_ithread_t *t = NULL;
1432 pthread_mutex_lock(&perl_threads->mutex);
1433 t = c_ithread_create(perl_threads->head->interp);
1434 pthread_mutex_unlock(&perl_threads->mutex);
1439 log_debug("fc_create: c_ithread: interp = %p (active threads: %i)", aTHX,
1440 perl_threads->number_of_threads);
1442 if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
1443 log_warn("A \"%s\" block expects a single string argument.",
1444 (FC_MATCH == type) ? "Match" : "Target");
1448 data = smalloc(sizeof(*data));
1449 data->name = sstrdup(ci->values[0].value.string);
1450 data->user_data = newSV(0);
1452 ret = fc_call(aTHX_ type, FC_CB_CREATE, data, ci);
1455 PFC_USER_DATA_FREE(data);
1459 } /* static int fc_create (int, const oconfig_item_t *, void **) */
1461 static int fc_destroy(int type, void **user_data) {
1462 pfc_user_data_t *data = *(pfc_user_data_t **)user_data;
1468 if ((NULL == perl_threads) || (NULL == data))
1472 c_ithread_t *t = NULL;
1474 pthread_mutex_lock(&perl_threads->mutex);
1475 t = c_ithread_create(perl_threads->head->interp);
1476 pthread_mutex_unlock(&perl_threads->mutex);
1481 log_debug("fc_destroy: c_ithread: interp = %p (active threads: %i)", aTHX,
1482 perl_threads->number_of_threads);
1484 ret = fc_call(aTHX_ type, FC_CB_DESTROY, data);
1486 PFC_USER_DATA_FREE(data);
1489 } /* static int fc_destroy (int, void **) */
1491 static int fc_exec(int type, const data_set_t *ds, const value_list_t *vl,
1492 notification_meta_t **meta, void **user_data) {
1493 pfc_user_data_t *data = *(pfc_user_data_t **)user_data;
1497 if (NULL == perl_threads)
1500 assert(NULL != data);
1503 c_ithread_t *t = NULL;
1505 pthread_mutex_lock(&perl_threads->mutex);
1506 t = c_ithread_create(perl_threads->head->interp);
1507 pthread_mutex_unlock(&perl_threads->mutex);
1512 log_debug("fc_exec: c_ithread: interp = %p (active threads: %i)", aTHX,
1513 perl_threads->number_of_threads);
1515 return fc_call(aTHX_ type, FC_CB_EXEC, data, ds, vl, meta);
1516 } /* static int fc_exec (int, const data_set_t *, const value_list_t *,
1517 notification_meta_t **, void **) */
1519 static int pmatch_create(const oconfig_item_t *ci, void **user_data) {
1520 return fc_create(FC_MATCH, ci, user_data);
1521 } /* static int pmatch_create (const oconfig_item_t *, void **) */
1523 static int pmatch_destroy(void **user_data) {
1524 return fc_destroy(FC_MATCH, user_data);
1525 } /* static int pmatch_destroy (void **) */
1527 static int pmatch_match(const data_set_t *ds, const value_list_t *vl,
1528 notification_meta_t **meta, void **user_data) {
1529 return fc_exec(FC_MATCH, ds, vl, meta, user_data);
1530 } /* static int pmatch_match (const data_set_t *, const value_list_t *,
1531 notification_meta_t **, void **) */
1533 static match_proc_t pmatch = {pmatch_create, pmatch_destroy, pmatch_match};
1535 static int ptarget_create(const oconfig_item_t *ci, void **user_data) {
1536 return fc_create(FC_TARGET, ci, user_data);
1537 } /* static int ptarget_create (const oconfig_item_t *, void **) */
1539 static int ptarget_destroy(void **user_data) {
1540 return fc_destroy(FC_TARGET, user_data);
1541 } /* static int ptarget_destroy (void **) */
1543 static int ptarget_invoke(const data_set_t *ds, value_list_t *vl,
1544 notification_meta_t **meta, void **user_data) {
1545 return fc_exec(FC_TARGET, ds, vl, meta, user_data);
1546 } /* static int ptarget_invoke (const data_set_t *, value_list_t *,
1547 notification_meta_t **, void **) */
1549 static target_proc_t ptarget = {ptarget_create, ptarget_destroy,
1553 * Exported Perl API.
1556 static void _plugin_register_generic_userdata(pTHX, int type,
1559 user_data_t userdata;
1565 log_err("Usage: Collectd::plugin_register_%s(pluginname, subname)", desc);
1570 log_err("Collectd::plugin_register_%s(pluginname, subname): "
1571 "Invalid pluginname",
1576 log_err("Collectd::plugin_register_%s(pluginname, subname): "
1582 /* Use pluginname as-is to allow flush a single perl plugin */
1583 pluginname = SvPV_nolen(ST(0));
1585 log_debug("Collectd::plugin_register_%s: "
1586 "plugin = \"%s\", sub = \"%s\"",
1587 desc, pluginname, SvPV_nolen(ST(1)));
1589 memset(&userdata, 0, sizeof(userdata));
1590 userdata.data = strdup(SvPV_nolen(ST(1)));
1591 userdata.free_func = free;
1593 if (PLUGIN_READ == type) {
1594 ret = plugin_register_complex_read(
1596 pluginname, perl_read, plugin_get_interval(), /* Default interval */
1598 } else if (PLUGIN_WRITE == type) {
1599 ret = plugin_register_write(pluginname, perl_write, &userdata);
1600 } else if (PLUGIN_LOG == type) {
1601 ret = plugin_register_log(pluginname, perl_log, &userdata);
1602 } else if (PLUGIN_NOTIF == type) {
1603 ret = plugin_register_notification(pluginname, perl_notify, &userdata);
1604 } else if (PLUGIN_FLUSH == type) {
1605 if (1 == register_legacy_flush) { /* For collectd-5.7 only, #1731 */
1606 register_legacy_flush = 0;
1607 ret = plugin_register_flush("perl", perl_flush, /* user_data = */ NULL);
1611 ret = plugin_register_flush(pluginname, perl_flush, &userdata);
1613 free(userdata.data);
1623 } /* static void _plugin_register_generic_userdata ( ... ) */
1626 * Collectd::plugin_register_TYPE (pluginname, subname).
1629 * name of the perl plugin
1632 * name of the plugin's subroutine that does the work
1635 static XS(Collectd_plugin_register_read) {
1636 _plugin_register_generic_userdata(aTHX, PLUGIN_READ, "read");
1639 static XS(Collectd_plugin_register_write) {
1640 _plugin_register_generic_userdata(aTHX, PLUGIN_WRITE, "write");
1643 static XS(Collectd_plugin_register_log) {
1644 _plugin_register_generic_userdata(aTHX, PLUGIN_LOG, "log");
1647 static XS(Collectd_plugin_register_notification) {
1648 _plugin_register_generic_userdata(aTHX, PLUGIN_NOTIF, "notification");
1651 static XS(Collectd_plugin_register_flush) {
1652 _plugin_register_generic_userdata(aTHX, PLUGIN_FLUSH, "flush");
1655 typedef int perl_unregister_function_t(const char *name);
1657 static void _plugin_unregister_generic(pTHX, perl_unregister_function_t *unreg,
1662 log_err("Usage: Collectd::plugin_unregister_%s(pluginname)", desc);
1667 log_err("Collectd::plugin_unregister_%s(pluginname): "
1668 "Invalid pluginname",
1673 log_debug("Collectd::plugin_unregister_%s: plugin = \"%s\"", desc,
1676 unreg(SvPV_nolen(ST(0)));
1679 } /* static void _plugin_unregister_generic ( ... ) */
1682 * Collectd::plugin_unregister_TYPE (pluginname).
1685 * type of callback to be unregistered: read, write, log, notification, flush
1688 * name of the perl plugin
1691 static XS(Collectd_plugin_unregister_read) {
1692 _plugin_unregister_generic(aTHX, plugin_unregister_read, "read");
1695 static XS(Collectd_plugin_unregister_write) {
1696 _plugin_unregister_generic(aTHX, plugin_unregister_write, "write");
1699 static XS(Collectd_plugin_unregister_log) {
1700 _plugin_unregister_generic(aTHX, plugin_unregister_log, "log");
1703 static XS(Collectd_plugin_unregister_notification) {
1704 _plugin_unregister_generic(aTHX, plugin_unregister_notification,
1708 static XS(Collectd_plugin_unregister_flush) {
1709 _plugin_unregister_generic(aTHX, plugin_unregister_flush, "flush");
1713 * Collectd::plugin_register_data_set (type, dataset).
1716 * type of the dataset
1719 * dataset to be registered
1721 static XS(Collectd_plugin_register_ds) {
1727 log_warn("Using plugin_register() to register new data-sets is "
1728 "deprecated - add new entries to a custom types.db instead.");
1731 log_err("Usage: Collectd::plugin_register_data_set(type, dataset)");
1735 log_debug("Collectd::plugin_register_data_set: "
1736 "type = \"%s\", dataset = \"%s\"",
1737 SvPV_nolen(ST(0)), SvPV_nolen(ST(1)));
1741 if (SvROK(data) && (SVt_PVAV == SvTYPE(SvRV(data)))) {
1742 ret = pplugin_register_data_set(aTHX_ SvPV_nolen(ST(0)), (AV *)SvRV(data));
1744 log_err("Collectd::plugin_register_data_set: Invalid data.");
1752 } /* static XS (Collectd_plugin_register_ds) */
1755 * Collectd::plugin_unregister_data_set (type).
1758 * type of the dataset
1760 static XS(Collectd_plugin_unregister_ds) {
1764 log_err("Usage: Collectd::plugin_unregister_data_set(type)");
1768 log_debug("Collectd::plugin_unregister_data_set: type = \"%s\"",
1771 if (0 == pplugin_unregister_data_set(SvPV_nolen(ST(0))))
1775 } /* static XS (Collectd_plugin_register_ds) */
1778 * Collectd::plugin_dispatch_values (name, values).
1781 * name of the plugin
1784 * value list to submit
1786 static XS(Collectd_plugin_dispatch_values) {
1794 log_err("Usage: Collectd::plugin_dispatch_values(values)");
1798 log_debug("Collectd::plugin_dispatch_values: values=\"%s\"",
1799 SvPV_nolen(ST(/* stack index = */ 0)));
1801 values = ST(/* stack index = */ 0);
1806 /* Make sure the argument is a hash reference. */
1807 if (!(SvROK(values) && (SVt_PVHV == SvTYPE(SvRV(values))))) {
1808 log_err("Collectd::plugin_dispatch_values: Invalid values.");
1812 ret = pplugin_dispatch_values(aTHX_(HV *) SvRV(values));
1818 } /* static XS (Collectd_plugin_dispatch_values) */
1821 * Collectd::plugin_get_interval ().
1823 static XS(Collectd_plugin_get_interval) {
1826 /* make sure we don't get any unused variable warnings for 'items';
1827 * don't abort, though */
1829 log_err("Usage: Collectd::plugin_get_interval()");
1831 XSRETURN_NV((NV)CDTIME_T_TO_DOUBLE(plugin_get_interval()));
1832 } /* static XS (Collectd_plugin_get_interval) */
1834 /* Collectd::plugin_write (plugin, ds, vl).
1837 * name of the plugin to call, may be 'undef'
1840 * data-set that describes the submitted values, may be 'undef'
1843 * value-list to be written
1845 static XS(Collectd__plugin_write) {
1855 log_err("Usage: Collectd::plugin_write(plugin, ds, vl)");
1859 log_debug("Collectd::plugin_write: plugin=\"%s\", ds=\"%s\", vl=\"%s\"",
1860 SvPV_nolen(ST(0)), SvOK(ST(1)) ? SvPV_nolen(ST(1)) : "",
1866 plugin = SvPV_nolen(ST(0));
1869 if (SvROK(ds) && (SVt_PVAV == SvTYPE(SvRV(ds))))
1870 ds_array = (AV *)SvRV(ds);
1874 log_err("Collectd::plugin_write: Invalid data-set.");
1879 if (!(SvROK(vl) && (SVt_PVHV == SvTYPE(SvRV(vl))))) {
1880 log_err("Collectd::plugin_write: Invalid value-list.");
1884 ret = pplugin_write(aTHX_ plugin, ds_array, (HV *)SvRV(vl));
1890 } /* static XS (Collectd__plugin_write) */
1893 * Collectd::_plugin_flush (plugin, timeout, identifier).
1896 * name of the plugin to flush
1899 * timeout to use when flushing the data
1902 * data-set identifier to flush
1904 static XS(Collectd__plugin_flush) {
1905 char *plugin = NULL;
1912 log_err("Usage: Collectd::_plugin_flush(plugin, timeout, id)");
1917 plugin = SvPV_nolen(ST(0));
1920 timeout = (int)SvIV(ST(1));
1923 id = SvPV_nolen(ST(2));
1925 log_debug("Collectd::_plugin_flush: plugin = \"%s\", timeout = %i, "
1927 plugin, timeout, id);
1929 if (0 == plugin_flush(plugin, timeout, id))
1933 } /* static XS (Collectd__plugin_flush) */
1936 * Collectd::plugin_dispatch_notification (notif).
1939 * notification to dispatch
1941 static XS(Collectd_plugin_dispatch_notification) {
1949 log_err("Usage: Collectd::plugin_dispatch_notification(notif)");
1953 log_debug("Collectd::plugin_dispatch_notification: notif = \"%s\"",
1958 if (!(SvROK(notif) && (SVt_PVHV == SvTYPE(SvRV(notif))))) {
1959 log_err("Collectd::plugin_dispatch_notification: Invalid notif.");
1963 ret = pplugin_dispatch_notification(aTHX_(HV *) SvRV(notif));
1969 } /* static XS (Collectd_plugin_dispatch_notification) */
1972 * Collectd::plugin_log (level, message).
1975 * log level (LOG_DEBUG, ... LOG_ERR)
1980 static XS(Collectd_plugin_log) {
1984 log_err("Usage: Collectd::plugin_log(level, message)");
1988 plugin_log(SvIV(ST(0)), "%s", SvPV_nolen(ST(1)));
1990 } /* static XS (Collectd_plugin_log) */
1993 * Collectd::_fc_register (type, name)
2001 static XS(Collectd__fc_register) {
2010 log_err("Usage: Collectd::_fc_register(type, name)");
2015 name = SvPV_nolen(ST(1));
2017 if (FC_MATCH == type)
2018 ret = fc_register_match(name, pmatch);
2019 else if (FC_TARGET == type)
2020 ret = fc_register_target(name, ptarget);
2026 } /* static XS (Collectd_fc_register) */
2029 * Collectd::call_by_name (...).
2031 * Call a Perl sub identified by its name passed through $Collectd::cb_name.
2033 static XS(Collectd_call_by_name) {
2037 if (NULL == (tmp = get_sv("Collectd::cb_name", 0))) {
2038 sv_setpv(get_sv("@", 1), "cb_name has not been set");
2043 name = SvPV_nolen(tmp);
2045 if (NULL == get_cv(name, 0)) {
2046 sv_setpvf(get_sv("@", 1), "unknown callback \"%s\"", name);
2051 /* simply pass on the subroutine call without touching the stack,
2052 * thus leaving any arguments and return values in place */
2054 } /* static XS (Collectd_call_by_name) */
2057 * Interface to collectd.
2060 static int perl_init(void) {
2064 if (NULL == perl_threads)
2068 c_ithread_t *t = NULL;
2070 pthread_mutex_lock(&perl_threads->mutex);
2071 t = c_ithread_create(perl_threads->head->interp);
2072 pthread_mutex_unlock(&perl_threads->mutex);
2077 log_debug("perl_init: c_ithread: interp = %p (active threads: %i)", aTHX,
2078 perl_threads->number_of_threads);
2080 /* Lock the base thread to avoid race conditions with c_ithread_create().
2081 * See https://github.com/collectd/collectd/issues/9 and
2082 * https://github.com/collectd/collectd/issues/1706 for details.
2084 assert(aTHX == perl_threads->head->interp);
2085 pthread_mutex_lock(&perl_threads->mutex);
2087 status = pplugin_call(aTHX_ PLUGIN_INIT);
2089 pthread_mutex_unlock(&perl_threads->mutex);
2092 } /* static int perl_init (void) */
2094 static int perl_read(user_data_t *user_data) {
2097 if (NULL == perl_threads)
2101 c_ithread_t *t = NULL;
2103 pthread_mutex_lock(&perl_threads->mutex);
2104 t = c_ithread_create(perl_threads->head->interp);
2105 pthread_mutex_unlock(&perl_threads->mutex);
2110 /* Assert that we're not running as the base thread. Otherwise, we might
2111 * run into concurrency issues with c_ithread_create(). See
2112 * https://github.com/collectd/collectd/issues/9 for details. */
2113 assert(aTHX != perl_threads->head->interp);
2115 log_debug("perl_read: c_ithread: interp = %p (active threads: %i)", aTHX,
2116 perl_threads->number_of_threads);
2118 return pplugin_call(aTHX_ PLUGIN_READ, user_data->data);
2119 } /* static int perl_read (user_data_t *user_data) */
2121 static int perl_write(const data_set_t *ds, const value_list_t *vl,
2122 user_data_t *user_data) {
2126 if (NULL == perl_threads)
2130 c_ithread_t *t = NULL;
2132 pthread_mutex_lock(&perl_threads->mutex);
2133 t = c_ithread_create(perl_threads->head->interp);
2134 pthread_mutex_unlock(&perl_threads->mutex);
2139 /* Lock the base thread if this is not called from one of the read threads
2140 * to avoid race conditions with c_ithread_create(). See
2141 * https://github.com/collectd/collectd/issues/9 for details. */
2142 if (aTHX == perl_threads->head->interp)
2143 pthread_mutex_lock(&perl_threads->mutex);
2145 log_debug("perl_write: c_ithread: interp = %p (active threads: %i)", aTHX,
2146 perl_threads->number_of_threads);
2147 status = pplugin_call(aTHX_ PLUGIN_WRITE, user_data->data, ds, vl);
2149 if (aTHX == perl_threads->head->interp)
2150 pthread_mutex_unlock(&perl_threads->mutex);
2153 } /* static int perl_write (const data_set_t *, const value_list_t *) */
2155 static void perl_log(int level, const char *msg, user_data_t *user_data) {
2158 if (NULL == perl_threads)
2162 c_ithread_t *t = NULL;
2164 pthread_mutex_lock(&perl_threads->mutex);
2165 t = c_ithread_create(perl_threads->head->interp);
2166 pthread_mutex_unlock(&perl_threads->mutex);
2171 /* Lock the base thread if this is not called from one of the read threads
2172 * to avoid race conditions with c_ithread_create(). See
2173 * https://github.com/collectd/collectd/issues/9 for details.
2176 if (aTHX == perl_threads->head->interp)
2177 pthread_mutex_lock(&perl_threads->mutex);
2179 pplugin_call(aTHX_ PLUGIN_LOG, user_data->data, level, msg);
2181 if (aTHX == perl_threads->head->interp)
2182 pthread_mutex_unlock(&perl_threads->mutex);
2185 } /* static void perl_log (int, const char *) */
2187 static int perl_notify(const notification_t *notif, user_data_t *user_data) {
2190 if (NULL == perl_threads)
2194 c_ithread_t *t = NULL;
2196 pthread_mutex_lock(&perl_threads->mutex);
2197 t = c_ithread_create(perl_threads->head->interp);
2198 pthread_mutex_unlock(&perl_threads->mutex);
2202 return pplugin_call(aTHX_ PLUGIN_NOTIF, user_data->data, notif);
2203 } /* static int perl_notify (const notification_t *) */
2205 static int perl_flush(cdtime_t timeout, const char *identifier,
2206 user_data_t *user_data) {
2209 if (NULL == perl_threads)
2213 c_ithread_t *t = NULL;
2215 pthread_mutex_lock(&perl_threads->mutex);
2216 t = c_ithread_create(perl_threads->head->interp);
2217 pthread_mutex_unlock(&perl_threads->mutex);
2222 /* For collectd-5.6 only, #1731 */
2223 if (user_data == NULL || user_data->data == NULL)
2224 return pplugin_call(aTHX_ PLUGIN_FLUSH_ALL, timeout, identifier);
2226 return pplugin_call(aTHX_ PLUGIN_FLUSH, user_data->data, timeout, identifier);
2227 } /* static int perl_flush (const int) */
2229 static int perl_shutdown(void) {
2235 plugin_unregister_complex_config("perl");
2236 plugin_unregister_read_group("perl");
2238 if (NULL == perl_threads)
2242 pthread_mutex_lock(&perl_threads->mutex);
2243 t = c_ithread_create(perl_threads->head->interp);
2244 pthread_mutex_unlock(&perl_threads->mutex);
2249 log_debug("perl_shutdown: c_ithread: interp = %p (active threads: %i)", aTHX,
2250 perl_threads->number_of_threads);
2252 plugin_unregister_init("perl");
2253 plugin_unregister_flush("perl"); /* For collectd-5.6 only, #1731 */
2255 ret = pplugin_call(aTHX_ PLUGIN_SHUTDOWN);
2257 pthread_mutex_lock(&perl_threads->mutex);
2258 t = perl_threads->tail;
2261 struct timespec ts_wait;
2262 c_ithread_t *thr = t;
2264 /* the pointer has to be advanced before destroying
2265 * the thread as this will free the memory */
2268 thr->shutdown = true;
2270 /* Give some time to thread to exit from Perl interpreter */
2271 WARNING("perl shutdown: Thread is running inside Perl. Waiting.");
2273 ts_wait.tv_nsec = 500000;
2274 nanosleep(&ts_wait, NULL);
2277 pthread_kill(thr->pthread, SIGTERM);
2278 ERROR("perl shutdown: Thread hangs inside Perl. Thread killed.");
2280 c_ithread_destroy(thr);
2283 pthread_mutex_unlock(&perl_threads->mutex);
2284 pthread_mutex_destroy(&perl_threads->mutex);
2285 pthread_mutexattr_destroy(&perl_threads->mutexattr);
2287 sfree(perl_threads);
2289 pthread_key_delete(perl_thr_key);
2293 plugin_unregister_shutdown("perl");
2295 } /* static void perl_shutdown (void) */
2298 * Access functions for global variables.
2300 * These functions implement the "magic" used to access
2301 * the global variables from Perl.
2304 static int g_pv_get(pTHX_ SV *var, MAGIC *mg) {
2305 char *pv = mg->mg_ptr;
2308 } /* static int g_pv_get (pTHX_ SV *, MAGIC *) */
2310 static int g_pv_set(pTHX_ SV *var, MAGIC *mg) {
2311 char *pv = mg->mg_ptr;
2312 sstrncpy(pv, SvPV_nolen(var), DATA_MAX_NAME_LEN);
2314 } /* static int g_pv_set (pTHX_ SV *, MAGIC *) */
2316 static int g_interval_get(pTHX_ SV *var, MAGIC *mg) {
2317 log_warn("Accessing $interval_g is deprecated (and might not "
2318 "give the desired results) - plugin_get_interval() should "
2319 "be used instead.");
2320 sv_setnv(var, CDTIME_T_TO_DOUBLE(interval_g));
2322 } /* static int g_interval_get (pTHX_ SV *, MAGIC *) */
2324 static int g_interval_set(pTHX_ SV *var, MAGIC *mg) {
2325 double nv = (double)SvNV(var);
2326 log_warn("Accessing $interval_g is deprecated (and might not "
2327 "give the desired results) - plugin_get_interval() should "
2328 "be used instead.");
2329 interval_g = DOUBLE_TO_CDTIME_T(nv);
2331 } /* static int g_interval_set (pTHX_ SV *, MAGIC *) */
2333 static MGVTBL g_pv_vtbl = {g_pv_get,
2340 #if HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL
2345 static MGVTBL g_interval_vtbl = {g_interval_get,
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 */
2388 } g_strings[] = {{"Collectd::hostname_g", hostname_g}, {"", NULL}};
2390 for (int i = 0; '\0' != g_strings[i].name[0]; ++i) {
2391 tmp = get_sv(g_strings[i].name, 1);
2392 sv_magicext(tmp, NULL, PERL_MAGIC_ext, &g_pv_vtbl, g_strings[i].var, 0);
2395 tmp = get_sv("Collectd::interval_g", /* create = */ 1);
2396 sv_magicext(tmp, NULL, /* how = */ PERL_MAGIC_ext,
2397 /* vtbl = */ &g_interval_vtbl,
2398 /* name = */ NULL, /* namelen = */ 0);
2401 } /* static void xs_init (pTHX) */
2403 /* Initialize the global Perl interpreter. */
2404 static int init_pi(int argc, char **argv) {
2407 if (NULL != perl_threads)
2410 log_info("Initializing Perl interpreter...");
2413 for (int i = 0; i < argc; ++i)
2414 log_debug("argv[%i] = \"%s\"", i, argv[i]);
2416 #endif /* COLLECT_DEBUG */
2418 if (0 != pthread_key_create(&perl_thr_key, c_ithread_destructor)) {
2419 log_err("init_pi: pthread_key_create failed");
2421 /* this must not happen - cowardly giving up if it does */
2426 /* On FreeBSD, PERL_SYS_INIT3 expands to some expression which
2427 * triggers a "value computed is not used" warning by gcc. */
2430 PERL_SYS_INIT3(&argc, &argv, &environ);
2432 perl_threads = smalloc(sizeof(*perl_threads));
2433 memset(perl_threads, 0, sizeof(c_ithread_list_t));
2435 pthread_mutexattr_init(&perl_threads->mutexattr);
2436 pthread_mutexattr_settype(&perl_threads->mutexattr, PTHREAD_MUTEX_RECURSIVE);
2437 pthread_mutex_init(&perl_threads->mutex, &perl_threads->mutexattr);
2438 /* locking the mutex should not be necessary at this point
2439 * but let's just do it for the sake of completeness */
2440 pthread_mutex_lock(&perl_threads->mutex);
2442 perl_threads->head = c_ithread_create(NULL);
2443 perl_threads->tail = perl_threads->head;
2445 if (NULL == (perl_threads->head->interp = perl_alloc())) {
2446 log_err("init_pi: Not enough memory.");
2450 aTHX = perl_threads->head->interp;
2451 pthread_mutex_unlock(&perl_threads->mutex);
2453 perl_construct(aTHX);
2455 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
2457 if (0 != perl_parse(aTHX_ xs_init, argc, argv, NULL)) {
2458 SV *err = get_sv("@", 1);
2459 log_err("init_pi: Unable to bootstrap Collectd: %s", SvPV_nolen(err));
2461 perl_destruct(perl_threads->head->interp);
2462 perl_free(perl_threads->head->interp);
2463 sfree(perl_threads);
2465 pthread_key_delete(perl_thr_key);
2469 /* Set $0 to "collectd" because perl_parse() has to set it to "-e". */
2470 sv_setpv(get_sv("0", 0), "collectd");
2474 plugin_register_init("perl", perl_init);
2475 plugin_register_shutdown("perl", perl_shutdown);
2477 } /* static int init_pi (const char **, const int) */
2480 * LoadPlugin "<Plugin>"
2482 static int perl_config_loadplugin(pTHX_ oconfig_item_t *ci) {
2483 char module_name[DATA_MAX_NAME_LEN];
2487 if ((0 != ci->children_num) || (1 != ci->values_num) ||
2488 (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2489 log_err("LoadPlugin expects a single string argument.");
2493 value = ci->values[0].value.string;
2495 if (NULL == get_module_name(module_name, sizeof(module_name), value)) {
2496 log_err("Invalid module name %s", value);
2500 if (0 != init_pi(perl_argc, perl_argv))
2503 assert(NULL != perl_threads);
2504 assert(NULL != perl_threads->head);
2506 aTHX = perl_threads->head->interp;
2508 log_debug("perl_config: Loading Perl plugin \"%s\"", value);
2509 load_module(PERL_LOADMOD_NOIMPORT, newSVpv(module_name, strlen(module_name)),
2512 } /* static int perl_config_loadplugin (oconfig_item_it *) */
2517 static int perl_config_basename(pTHX_ oconfig_item_t *ci) {
2520 if ((0 != ci->children_num) || (1 != ci->values_num) ||
2521 (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2522 log_err("BaseName expects a single string argument.");
2526 value = ci->values[0].value.string;
2528 log_debug("perl_config: Setting plugin basename to \"%s\"", value);
2529 sstrncpy(base_name, value, sizeof(base_name));
2531 } /* static int perl_config_basename (oconfig_item_it *) */
2534 * EnableDebugger "<Package>"|""
2536 static int perl_config_enabledebugger(pTHX_ oconfig_item_t *ci) {
2539 if ((0 != ci->children_num) || (1 != ci->values_num) ||
2540 (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2541 log_err("EnableDebugger expects a single string argument.");
2545 if (NULL != perl_threads) {
2546 log_warn("EnableDebugger has no effects if used after LoadPlugin.");
2550 value = ci->values[0].value.string;
2552 perl_argv = realloc(perl_argv, (++perl_argc + 1) * sizeof(char *));
2554 if (NULL == perl_argv) {
2555 log_err("perl_config: Not enough memory.");
2559 if ('\0' == value[0]) {
2560 perl_argv[perl_argc - 1] = "-d";
2562 perl_argv[perl_argc - 1] = smalloc(strlen(value) + 4);
2563 sstrncpy(perl_argv[perl_argc - 1], "-d:", 4);
2564 sstrncpy(perl_argv[perl_argc - 1] + 3, value, strlen(value) + 1);
2567 perl_argv[perl_argc] = NULL;
2569 } /* static int perl_config_enabledebugger (oconfig_item_it *) */
2572 * IncludeDir "<Dir>"
2574 static int perl_config_includedir(pTHX_ oconfig_item_t *ci) {
2577 if ((0 != ci->children_num) || (1 != ci->values_num) ||
2578 (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2579 log_err("IncludeDir expects a single string argument.");
2583 value = ci->values[0].value.string;
2586 perl_argv = realloc(perl_argv, (++perl_argc + 1) * sizeof(char *));
2588 if (NULL == perl_argv) {
2589 log_err("perl_config: Not enough memory.");
2593 perl_argv[perl_argc - 1] = smalloc(strlen(value) + 3);
2594 sstrncpy(perl_argv[perl_argc - 1], "-I", 3);
2595 sstrncpy(perl_argv[perl_argc - 1] + 2, value, strlen(value) + 1);
2597 perl_argv[perl_argc] = NULL;
2599 /* prepend the directory to @INC */
2600 av_unshift(GvAVn(PL_incgv), 1);
2601 av_store(GvAVn(PL_incgv), 0, newSVpv(value, strlen(value)));
2604 } /* static int perl_config_includedir (oconfig_item_it *) */
2609 static int perl_config_plugin(pTHX_ oconfig_item_t *ci) {
2616 if (NULL == perl_threads) {
2617 log_err("A `Plugin' block was encountered but no plugin was loaded yet. "
2618 "Put the appropriate `LoadPlugin' option in front of it.");
2624 if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2625 log_err("LoadPlugin expects a single string argument.");
2629 plugin = ci->values[0].value.string;
2632 if (0 != oconfig_item2hv(aTHX_ ci, config)) {
2636 log_err("Unable to convert configuration to a Perl hash value.");
2637 config = (HV *)&PL_sv_undef;
2645 XPUSHs(sv_2mortal(newSVpv(plugin, 0)));
2646 XPUSHs(sv_2mortal(newRV_noinc((SV *)config)));
2650 retvals = call_pv("Collectd::_plugin_dispatch_config", G_SCALAR);
2664 } /* static int perl_config_plugin (oconfig_item_it *) */
2666 static int perl_config(oconfig_item_t *ci) {
2671 for (int i = 0; i < ci->children_num; ++i) {
2672 oconfig_item_t *c = ci->children + i;
2673 int current_status = 0;
2675 if (NULL != perl_threads) {
2676 if ((aTHX = PERL_GET_CONTEXT) == NULL)
2680 if (0 == strcasecmp(c->key, "LoadPlugin"))
2681 current_status = perl_config_loadplugin(aTHX_ c);
2682 else if (0 == strcasecmp(c->key, "BaseName"))
2683 current_status = perl_config_basename(aTHX_ c);
2684 else if (0 == strcasecmp(c->key, "EnableDebugger"))
2685 current_status = perl_config_enabledebugger(aTHX_ c);
2686 else if (0 == strcasecmp(c->key, "IncludeDir"))
2687 current_status = perl_config_includedir(aTHX_ c);
2688 else if (0 == strcasecmp(c->key, "Plugin"))
2689 current_status = perl_config_plugin(aTHX_ c);
2690 else if (0 == strcasecmp(c->key, "RegisterLegacyFlush"))
2691 cf_util_get_boolean(c, ®ister_legacy_flush);
2693 log_warn("Ignoring unknown config key \"%s\".", c->key);
2697 /* fatal error - it's up to perl_config_* to clean up */
2698 if (0 > current_status) {
2699 log_err("Configuration failed with a fatal error - "
2700 "plugin disabled!");
2701 return current_status;
2704 status += current_status;
2707 } /* static int perl_config (oconfig_item_t *) */
2709 void module_register(void) {
2711 perl_argv = smalloc((perl_argc + 1) * sizeof(*perl_argv));
2713 /* default options for the Perl interpreter */
2715 perl_argv[1] = "-MCollectd";
2716 perl_argv[2] = "-e";
2718 perl_argv[4] = NULL;
2720 plugin_register_complex_config("perl", perl_config);
2722 } /* void module_register (void) */