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>
28 * This plugin embeds a Perl interpreter into collectd and provides an
29 * interface for collectd plugins written in perl.
32 /* do not automatically get the thread specific Perl interpreter */
33 #define PERL_NO_GET_CONTEXT
35 #define DONT_POISON_SPRINTF_YET 1
38 #undef DONT_POISON_SPRINTF_YET
47 #if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
49 # pragma GCC poison sprintf
54 /* Some versions of Perl define their own version of DEBUG... :-/ */
59 /* ... while we want the definition found in plugin.h. */
63 #include "filter_chain.h"
65 #if !defined(USE_ITHREADS)
66 # error "Perl does not support ithreads!"
67 #endif /* !defined(USE_ITHREADS) */
69 /* clear the Perl sub's stack frame
70 * (this should only be used inside an XSUB) */
71 #define CLEAR_STACK_FRAME PL_stack_sp = PL_stack_base + *PL_markstack_ptr
75 #define PLUGIN_WRITE 2
76 #define PLUGIN_SHUTDOWN 3
78 #define PLUGIN_NOTIF 5
79 #define PLUGIN_FLUSH 6
81 #define PLUGIN_TYPES 7
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 /* if perl_threads != NULL perl_threads->head must
187 * point to the "base" thread */
188 static c_ithread_list_t *perl_threads = NULL;
190 /* the key used to store each pthread's ithread */
191 static pthread_key_t perl_thr_key;
193 static int perl_argc = 0;
194 static char **perl_argv = NULL;
196 static char base_name[DATA_MAX_NAME_LEN] = "";
203 { "Collectd::plugin_register_read", Collectd_plugin_register_read },
204 { "Collectd::plugin_register_write", Collectd_plugin_register_write },
205 { "Collectd::plugin_register_log", Collectd_plugin_register_log },
206 { "Collectd::plugin_register_notification",
207 Collectd_plugin_register_notification },
208 { "Collectd::plugin_register_flush", Collectd_plugin_register_flush },
209 { "Collectd::plugin_unregister_read", Collectd_plugin_unregister_read },
210 { "Collectd::plugin_unregister_write", Collectd_plugin_unregister_write },
211 { "Collectd::plugin_unregister_log", Collectd_plugin_unregister_log },
212 { "Collectd::plugin_unregister_notification",
213 Collectd_plugin_unregister_notification },
214 { "Collectd::plugin_unregister_flush", Collectd_plugin_unregister_flush },
215 { "Collectd::plugin_register_data_set", Collectd_plugin_register_ds },
216 { "Collectd::plugin_unregister_data_set", Collectd_plugin_unregister_ds },
217 { "Collectd::plugin_dispatch_values", Collectd_plugin_dispatch_values },
218 { "Collectd::plugin_get_interval", Collectd_plugin_get_interval },
219 { "Collectd::_plugin_write", Collectd__plugin_write },
220 { "Collectd::_plugin_flush", Collectd__plugin_flush },
221 { "Collectd::plugin_dispatch_notification",
222 Collectd_plugin_dispatch_notification },
223 { "Collectd::plugin_log", Collectd_plugin_log },
224 { "Collectd::_fc_register", Collectd__fc_register },
225 { "Collectd::call_by_name", Collectd_call_by_name },
234 { "Collectd::TYPE_INIT", PLUGIN_INIT },
235 { "Collectd::TYPE_READ", PLUGIN_READ },
236 { "Collectd::TYPE_WRITE", PLUGIN_WRITE },
237 { "Collectd::TYPE_SHUTDOWN", PLUGIN_SHUTDOWN },
238 { "Collectd::TYPE_LOG", PLUGIN_LOG },
239 { "Collectd::TYPE_NOTIF", PLUGIN_NOTIF },
240 { "Collectd::TYPE_FLUSH", PLUGIN_FLUSH },
241 { "Collectd::TYPE_CONFIG", PLUGIN_CONFIG },
242 { "Collectd::TYPE_DATASET", PLUGIN_DATASET },
243 { "Collectd::DS_TYPE_COUNTER", DS_TYPE_COUNTER },
244 { "Collectd::DS_TYPE_GAUGE", DS_TYPE_GAUGE },
245 { "Collectd::DS_TYPE_DERIVE", DS_TYPE_DERIVE },
246 { "Collectd::DS_TYPE_ABSOLUTE", DS_TYPE_ABSOLUTE },
247 { "Collectd::LOG_ERR", LOG_ERR },
248 { "Collectd::LOG_WARNING", LOG_WARNING },
249 { "Collectd::LOG_NOTICE", LOG_NOTICE },
250 { "Collectd::LOG_INFO", LOG_INFO },
251 { "Collectd::LOG_DEBUG", LOG_DEBUG },
252 { "Collectd::FC_MATCH", FC_MATCH },
253 { "Collectd::FC_TARGET", FC_TARGET },
254 { "Collectd::FC_CB_CREATE", FC_CB_CREATE },
255 { "Collectd::FC_CB_DESTROY", FC_CB_DESTROY },
256 { "Collectd::FC_CB_EXEC", FC_CB_EXEC },
257 { "Collectd::FC_MATCH_NO_MATCH", FC_MATCH_NO_MATCH },
258 { "Collectd::FC_MATCH_MATCHES", FC_MATCH_MATCHES },
259 { "Collectd::FC_TARGET_CONTINUE", FC_TARGET_CONTINUE },
260 { "Collectd::FC_TARGET_STOP", FC_TARGET_STOP },
261 { "Collectd::FC_TARGET_RETURN", FC_TARGET_RETURN },
262 { "Collectd::NOTIF_FAILURE", NOTIF_FAILURE },
263 { "Collectd::NOTIF_WARNING", NOTIF_WARNING },
264 { "Collectd::NOTIF_OKAY", NOTIF_OKAY },
273 { "Collectd::hostname_g", hostname_g },
278 * Helper functions for data type conversion.
293 static int hv2data_source (pTHX_ HV *hash, data_source_t *ds)
297 if ((NULL == hash) || (NULL == ds))
300 if (NULL != (tmp = hv_fetch (hash, "name", 4, 0))) {
301 sstrncpy (ds->name, SvPV_nolen (*tmp), sizeof (ds->name));
304 log_err ("hv2data_source: No DS name given.");
308 if (NULL != (tmp = hv_fetch (hash, "type", 4, 0))) {
309 ds->type = SvIV (*tmp);
311 if ((DS_TYPE_COUNTER != ds->type)
312 && (DS_TYPE_GAUGE != ds->type)
313 && (DS_TYPE_DERIVE != ds->type)
314 && (DS_TYPE_ABSOLUTE != ds->type)) {
315 log_err ("hv2data_source: Invalid DS type.");
320 ds->type = DS_TYPE_COUNTER;
323 if (NULL != (tmp = hv_fetch (hash, "min", 3, 0)))
324 ds->min = SvNV (*tmp);
328 if (NULL != (tmp = hv_fetch (hash, "max", 3, 0)))
329 ds->max = SvNV (*tmp);
333 } /* static int hv2data_source (HV *, data_source_t *) */
335 /* av2value converts at most "len" elements from "array" to "value". Returns the
336 * number of elements converted or zero on error. */
337 static size_t av2value (pTHX_ char *name, AV *array, value_t *value, size_t array_len)
339 const data_set_t *ds;
341 if ((NULL == name) || (NULL == array) || (NULL == value) || (array_len == 0))
344 ds = plugin_get_ds (name);
346 log_err ("av2value: Unknown dataset \"%s\"", name);
350 if (array_len < ds->ds_num) {
351 log_warn ("av2value: array does not contain enough elements for type \"%s\": got %zu, want %zu",
352 name, array_len, ds->ds_num);
354 } else if (array_len > ds->ds_num) {
355 log_warn ("av2value: array contains excess elements for type \"%s\": got %zu, want %zu",
356 name, array_len, ds->ds_num);
359 for (size_t i = 0; i < ds->ds_num; ++i) {
360 SV **tmp = av_fetch (array, i, 0);
363 if (DS_TYPE_COUNTER == ds->ds[i].type)
364 value[i].counter = SvIV (*tmp);
365 else if (DS_TYPE_GAUGE == ds->ds[i].type)
366 value[i].gauge = SvNV (*tmp);
367 else if (DS_TYPE_DERIVE == ds->ds[i].type)
368 value[i].derive = SvIV (*tmp);
369 else if (DS_TYPE_ABSOLUTE == ds->ds[i].type)
370 value[i].absolute = SvIV (*tmp);
378 } /* static size_t av2value (char *, AV *, value_t *, size_t) */
383 * values => [ @values ],
387 * plugin_instance => $pinstance,
388 * type_instance => $tinstance,
391 static int hv2value_list (pTHX_ HV *hash, value_list_t *vl)
395 if ((NULL == hash) || (NULL == vl))
398 if (NULL == (tmp = hv_fetch (hash, "type", 4, 0))) {
399 log_err ("hv2value_list: No type given.");
403 sstrncpy (vl->type, SvPV_nolen (*tmp), sizeof (vl->type));
405 if ((NULL == (tmp = hv_fetch (hash, "values", 6, 0)))
406 || (! (SvROK (*tmp) && (SVt_PVAV == SvTYPE (SvRV (*tmp)))))) {
407 log_err ("hv2value_list: No valid values given.");
412 AV *array = (AV *)SvRV (*tmp);
413 /* av_len returns the highest index, not the actual length. */
414 size_t array_len = (size_t) (av_len (array) + 1);
418 vl->values = calloc (array_len, sizeof (*vl->values));
419 vl->values_len = av2value (aTHX_ vl->type, (AV *)SvRV (*tmp), vl->values, array_len);
420 if (vl->values_len == 0) {
426 if (NULL != (tmp = hv_fetch (hash, "time", 4, 0)))
428 double t = SvNV (*tmp);
429 vl->time = DOUBLE_TO_CDTIME_T (t);
432 if (NULL != (tmp = hv_fetch (hash, "interval", 8, 0)))
434 double t = SvNV (*tmp);
435 vl->interval = DOUBLE_TO_CDTIME_T (t);
438 if (NULL != (tmp = hv_fetch (hash, "host", 4, 0)))
439 sstrncpy (vl->host, SvPV_nolen (*tmp), sizeof (vl->host));
441 sstrncpy (vl->host, hostname_g, sizeof (vl->host));
443 if (NULL != (tmp = hv_fetch (hash, "plugin", 6, 0)))
444 sstrncpy (vl->plugin, SvPV_nolen (*tmp), sizeof (vl->plugin));
446 if (NULL != (tmp = hv_fetch (hash, "plugin_instance", 15, 0)))
447 sstrncpy (vl->plugin_instance, SvPV_nolen (*tmp),
448 sizeof (vl->plugin_instance));
450 if (NULL != (tmp = hv_fetch (hash, "type_instance", 13, 0)))
451 sstrncpy (vl->type_instance, SvPV_nolen (*tmp),
452 sizeof (vl->type_instance));
454 } /* static int hv2value_list (pTHX_ HV *, value_list_t *) */
456 static int av2data_set (pTHX_ AV *array, char *name, data_set_t *ds)
460 if ((NULL == array) || (NULL == name) || (NULL == ds))
463 len = av_len (array);
466 log_err ("av2data_set: Invalid data set.");
470 ds->ds = smalloc ((len + 1) * sizeof (*ds->ds));
471 ds->ds_num = len + 1;
473 for (int i = 0; i <= len; ++i) {
474 SV **elem = av_fetch (array, i, 0);
477 log_err ("av2data_set: Failed to fetch data source %i.", i);
481 if (! (SvROK (*elem) && (SVt_PVHV == SvTYPE (SvRV (*elem))))) {
482 log_err ("av2data_set: Invalid data source.");
486 if (-1 == hv2data_source (aTHX_ (HV *)SvRV (*elem), &ds->ds[i]))
489 log_debug ("av2data_set: "
490 "DS.name = \"%s\", DS.type = %i, DS.min = %f, DS.max = %f",
491 ds->ds[i].name, ds->ds[i].type, ds->ds[i].min, ds->ds[i].max);
494 sstrncpy (ds->type, name, sizeof (ds->type));
496 } /* static int av2data_set (pTHX_ AV *, data_set_t *) */
501 * severity => $severity,
507 * plugin_instance => $instance,
508 * type_instance => $type_instance,
509 * meta => [ { name => <name>, value => <value> }, ... ]
512 static int av2notification_meta (pTHX_ AV *array, notification_meta_t **meta)
514 notification_meta_t **m = meta;
516 int len = av_len (array);
518 for (int i = 0; i <= len; ++i) {
519 SV **tmp = av_fetch (array, i, 0);
525 if (! (SvROK (*tmp) && (SVt_PVHV == SvTYPE (SvRV (*tmp))))) {
526 log_warn ("av2notification_meta: Skipping invalid "
527 "meta information.");
531 hash = (HV *)SvRV (*tmp);
533 *m = smalloc (sizeof (**m));
535 if (NULL == (tmp = hv_fetch (hash, "name", 4, 0))) {
536 log_warn ("av2notification_meta: Skipping invalid "
537 "meta information.");
541 sstrncpy ((*m)->name, SvPV_nolen (*tmp), sizeof ((*m)->name));
543 if (NULL == (tmp = hv_fetch (hash, "value", 5, 0))) {
544 log_warn ("av2notification_meta: Skipping invalid "
545 "meta information.");
551 (*m)->nm_value.nm_double = SvNVX (*tmp);
552 (*m)->type = NM_TYPE_DOUBLE;
554 else if (SvUOK (*tmp)) {
555 (*m)->nm_value.nm_unsigned_int = SvUVX (*tmp);
556 (*m)->type = NM_TYPE_UNSIGNED_INT;
558 else if (SvIOK (*tmp)) {
559 (*m)->nm_value.nm_signed_int = SvIVX (*tmp);
560 (*m)->type = NM_TYPE_SIGNED_INT;
563 (*m)->nm_value.nm_string = sstrdup (SvPV_nolen (*tmp));
564 (*m)->type = NM_TYPE_STRING;
571 } /* static int av2notification_meta (AV *, notification_meta_t *) */
573 static int hv2notification (pTHX_ HV *hash, notification_t *n)
577 if ((NULL == hash) || (NULL == n))
580 if (NULL != (tmp = hv_fetch (hash, "severity", 8, 0)))
581 n->severity = SvIV (*tmp);
583 n->severity = NOTIF_FAILURE;
585 if (NULL != (tmp = hv_fetch (hash, "time", 4, 0)))
587 double t = SvNV (*tmp);
588 n->time = DOUBLE_TO_CDTIME_T (t);
593 if (NULL != (tmp = hv_fetch (hash, "message", 7, 0)))
594 sstrncpy (n->message, SvPV_nolen (*tmp), sizeof (n->message));
596 if (NULL != (tmp = hv_fetch (hash, "host", 4, 0)))
597 sstrncpy (n->host, SvPV_nolen (*tmp), sizeof (n->host));
599 sstrncpy (n->host, hostname_g, sizeof (n->host));
601 if (NULL != (tmp = hv_fetch (hash, "plugin", 6, 0)))
602 sstrncpy (n->plugin, SvPV_nolen (*tmp), sizeof (n->plugin));
604 if (NULL != (tmp = hv_fetch (hash, "plugin_instance", 15, 0)))
605 sstrncpy (n->plugin_instance, SvPV_nolen (*tmp),
606 sizeof (n->plugin_instance));
608 if (NULL != (tmp = hv_fetch (hash, "type", 4, 0)))
609 sstrncpy (n->type, SvPV_nolen (*tmp), sizeof (n->type));
611 if (NULL != (tmp = hv_fetch (hash, "type_instance", 13, 0)))
612 sstrncpy (n->type_instance, SvPV_nolen (*tmp),
613 sizeof (n->type_instance));
616 while (NULL != (tmp = hv_fetch (hash, "meta", 4, 0))) {
617 if (! (SvROK (*tmp) && (SVt_PVAV == SvTYPE (SvRV (*tmp))))) {
618 log_warn ("hv2notification: Ignoring invalid meta information.");
622 if (0 != av2notification_meta (aTHX_ (AV *)SvRV (*tmp), &n->meta)) {
623 plugin_notification_meta_free (n->meta);
630 } /* static int hv2notification (pTHX_ HV *, notification_t *) */
632 static int data_set2av (pTHX_ data_set_t *ds, AV *array)
634 if ((NULL == ds) || (NULL == array))
637 av_extend (array, ds->ds_num);
639 for (size_t i = 0; i < ds->ds_num; ++i) {
640 HV *source = newHV ();
642 if (NULL == hv_store (source, "name", 4,
643 newSVpv (ds->ds[i].name, 0), 0))
646 if (NULL == hv_store (source, "type", 4, newSViv (ds->ds[i].type), 0))
649 if (! isnan (ds->ds[i].min))
650 if (NULL == hv_store (source, "min", 3,
651 newSVnv (ds->ds[i].min), 0))
654 if (! isnan (ds->ds[i].max))
655 if (NULL == hv_store (source, "max", 3,
656 newSVnv (ds->ds[i].max), 0))
659 if (NULL == av_store (array, i, newRV_noinc ((SV *)source)))
663 } /* static int data_set2av (data_set_t *, AV *) */
665 static int value_list2hv (pTHX_ value_list_t *vl, data_set_t *ds, HV *hash)
670 if ((NULL == vl) || (NULL == ds) || (NULL == hash))
674 /* av_extend takes the last *index* to which the array should be extended. */
675 av_extend (values, vl->values_len - 1);
677 assert (ds->ds_num == vl->values_len);
678 for (i = 0; i < vl->values_len; ++i) {
681 if (DS_TYPE_COUNTER == ds->ds[i].type)
682 val = newSViv (vl->values[i].counter);
683 else if (DS_TYPE_GAUGE == ds->ds[i].type)
684 val = newSVnv (vl->values[i].gauge);
685 else if (DS_TYPE_DERIVE == ds->ds[i].type)
686 val = newSViv (vl->values[i].derive);
687 else if (DS_TYPE_ABSOLUTE == ds->ds[i].type)
688 val = newSViv (vl->values[i].absolute);
690 if (NULL == av_store (values, i, val)) {
696 if (NULL == hv_store (hash, "values", 6, newRV_noinc ((SV *)values), 0))
701 double t = CDTIME_T_TO_DOUBLE (vl->time);
702 if (NULL == hv_store (hash, "time", 4, newSVnv (t), 0))
707 double t = CDTIME_T_TO_DOUBLE (vl->interval);
708 if (NULL == hv_store (hash, "interval", 8, newSVnv (t), 0))
712 if ('\0' != vl->host[0])
713 if (NULL == hv_store (hash, "host", 4, newSVpv (vl->host, 0), 0))
716 if ('\0' != vl->plugin[0])
717 if (NULL == hv_store (hash, "plugin", 6, newSVpv (vl->plugin, 0), 0))
720 if ('\0' != vl->plugin_instance[0])
721 if (NULL == hv_store (hash, "plugin_instance", 15,
722 newSVpv (vl->plugin_instance, 0), 0))
725 if ('\0' != vl->type[0])
726 if (NULL == hv_store (hash, "type", 4, newSVpv (vl->type, 0), 0))
729 if ('\0' != vl->type_instance[0])
730 if (NULL == hv_store (hash, "type_instance", 13,
731 newSVpv (vl->type_instance, 0), 0))
734 } /* static int value2av (value_list_t *, data_set_t *, HV *) */
736 static int notification_meta2av (pTHX_ notification_meta_t *meta, AV *array)
745 av_extend (array, meta_num);
747 for (int i = 0; NULL != meta; meta = meta->next, ++i) {
751 if (NULL == hv_store (m, "name", 4, newSVpv (meta->name, 0), 0))
754 if (NM_TYPE_STRING == meta->type)
755 value = newSVpv (meta->nm_value.nm_string, 0);
756 else if (NM_TYPE_SIGNED_INT == meta->type)
757 value = newSViv (meta->nm_value.nm_signed_int);
758 else if (NM_TYPE_UNSIGNED_INT == meta->type)
759 value = newSVuv (meta->nm_value.nm_unsigned_int);
760 else if (NM_TYPE_DOUBLE == meta->type)
761 value = newSVnv (meta->nm_value.nm_double);
762 else if (NM_TYPE_BOOLEAN == meta->type)
763 value = meta->nm_value.nm_boolean ? &PL_sv_yes : &PL_sv_no;
767 if (NULL == hv_store (m, "value", 5, value, 0)) {
772 if (NULL == av_store (array, i, newRV_noinc ((SV *)m))) {
779 } /* static int notification_meta2av (notification_meta_t *, AV *) */
781 static int notification2hv (pTHX_ notification_t *n, HV *hash)
783 if (NULL == hv_store (hash, "severity", 8, newSViv (n->severity), 0))
788 double t = CDTIME_T_TO_DOUBLE (n->time);
789 if (NULL == hv_store (hash, "time", 4, newSVnv (t), 0))
793 if ('\0' != *n->message)
794 if (NULL == hv_store (hash, "message", 7, newSVpv (n->message, 0), 0))
797 if ('\0' != *n->host)
798 if (NULL == hv_store (hash, "host", 4, newSVpv (n->host, 0), 0))
801 if ('\0' != *n->plugin)
802 if (NULL == hv_store (hash, "plugin", 6, newSVpv (n->plugin, 0), 0))
805 if ('\0' != *n->plugin_instance)
806 if (NULL == hv_store (hash, "plugin_instance", 15,
807 newSVpv (n->plugin_instance, 0), 0))
810 if ('\0' != *n->type)
811 if (NULL == hv_store (hash, "type", 4, newSVpv (n->type, 0), 0))
814 if ('\0' != *n->type_instance)
815 if (NULL == hv_store (hash, "type_instance", 13,
816 newSVpv (n->type_instance, 0), 0))
819 if (NULL != n->meta) {
821 if ((0 != notification_meta2av (aTHX_ n->meta, meta))
822 || (NULL == hv_store (hash, "meta", 4,
823 newRV_noinc ((SV *)meta), 0))) {
830 } /* static int notification2hv (notification_t *, HV *) */
832 static int oconfig_item2hv (pTHX_ oconfig_item_t *ci, HV *hash)
837 if (NULL == hv_store (hash, "key", 3, newSVpv (ci->key, 0), 0))
841 if (0 < ci->values_num)
842 av_extend (values, ci->values_num);
844 if (NULL == hv_store (hash, "values", 6, newRV_noinc ((SV *)values), 0)) {
850 for (int i = 0; i < ci->values_num; ++i) {
853 switch (ci->values[i].type) {
854 case OCONFIG_TYPE_STRING:
855 value = newSVpv (ci->values[i].value.string, 0);
857 case OCONFIG_TYPE_NUMBER:
858 value = newSVnv ((NV)ci->values[i].value.number);
860 case OCONFIG_TYPE_BOOLEAN:
861 value = ci->values[i].value.boolean ? &PL_sv_yes : &PL_sv_no;
864 log_err ("oconfig_item2hv: Invalid value type %i.",
866 value = &PL_sv_undef;
869 if (NULL == av_store (values, i, value)) {
875 /* ignoring 'parent' member which is uninteresting in this case */
878 if (0 < ci->children_num)
879 av_extend (children, ci->children_num);
881 if (NULL == hv_store (hash, "children", 8, newRV_noinc ((SV *)children), 0)) {
887 for (int i = 0; i < ci->children_num; ++i) {
888 HV *child = newHV ();
890 if (0 != oconfig_item2hv (aTHX_ ci->children + i, child)) {
896 if (NULL == av_store (children, i, newRV_noinc ((SV *)child))) {
903 } /* static int oconfig_item2hv (pTHX_ oconfig_item_t *, HV *) */
906 * Internal functions.
909 static char *get_module_name (char *buf, size_t buf_len, const char *module) {
911 if (base_name[0] == '\0')
912 status = ssnprintf (buf, buf_len, "%s", module);
914 status = ssnprintf (buf, buf_len, "%s::%s", base_name, module);
915 if ((status < 0) || ((unsigned int)status >= buf_len))
918 } /* char *get_module_name */
921 * Add a plugin's data set definition.
923 static int pplugin_register_data_set (pTHX_ char *name, AV *dataset)
929 if ((NULL == name) || (NULL == dataset))
932 if (0 != av2data_set (aTHX_ dataset, name, &ds))
935 ret = plugin_register_data_set (&ds);
939 } /* static int pplugin_register_data_set (char *, SV *) */
942 * Remove a plugin's data set definition.
944 static int pplugin_unregister_data_set (char *name)
948 return plugin_unregister_data_set (name);
949 } /* static int pplugin_unregister_data_set (char *) */
952 * Submit the values to the write functions.
954 static int pplugin_dispatch_values (pTHX_ HV *values)
956 value_list_t vl = VALUE_LIST_INIT;
963 if (0 != hv2value_list (aTHX_ values, &vl))
966 ret = plugin_dispatch_values (&vl);
970 } /* static int pplugin_dispatch_values (char *, HV *) */
973 * Submit the values to a single write function.
975 static int pplugin_write (pTHX_ const char *plugin, AV *data_set, HV *values)
978 value_list_t vl = VALUE_LIST_INIT;
985 if (0 != hv2value_list (aTHX_ values, &vl))
988 if ((NULL != data_set)
989 && (0 != av2data_set (aTHX_ data_set, vl.type, &ds)))
992 ret = plugin_write (plugin, NULL == data_set ? NULL : &ds, &vl);
994 log_warn ("Dispatching value to plugin \"%s\" failed with status %i.",
995 NULL == plugin ? "<any>" : plugin, ret);
997 if (NULL != data_set)
1001 } /* static int pplugin_write (const char *plugin, HV *, HV *) */
1004 * Dispatch a notification.
1006 static int pplugin_dispatch_notification (pTHX_ HV *notif)
1008 notification_t n = { 0 };
1015 if (0 != hv2notification (aTHX_ notif, &n))
1018 ret = plugin_dispatch_notification (&n);
1019 plugin_notification_meta_free (n.meta);
1021 } /* static int pplugin_dispatch_notification (HV *) */
1024 * Call perl sub with thread locking flags handled.
1026 static int call_pv_locked (pTHX_ const char* sub_name)
1031 c_ithread_t *t = (c_ithread_t *)pthread_getspecific(perl_thr_key);
1032 if (t == NULL) /* thread destroyed */
1035 old_running = t->running;
1039 t->running = old_running;
1043 ret = call_pv (sub_name, G_SCALAR|G_EVAL);
1045 t->running = old_running;
1047 } /* static int call_pv_locked (pTHX, *sub_name) */
1050 * Call all working functions of the given type.
1052 static int pplugin_call (pTHX_ int type, ...)
1062 if ((type < 0) || (type >= PLUGIN_TYPES))
1065 va_start (ap, type);
1072 if (PLUGIN_READ == type) {
1073 subname = va_arg(ap, char *);
1075 else if (PLUGIN_WRITE == type) {
1082 subname = va_arg(ap, char *);
1084 * $_[0] = $plugin_type;
1099 * values => [ $v1, ... ],
1101 * host => $hostname,
1102 * plugin => $plugin,
1104 * plugin_instance => $instance,
1105 * type_instance => $type_instance
1108 ds = va_arg (ap, data_set_t *);
1109 vl = va_arg (ap, value_list_t *);
1111 if (-1 == data_set2av (aTHX_ ds, pds)) {
1114 pds = (AV *)&PL_sv_undef;
1118 if (-1 == value_list2hv (aTHX_ vl, ds, pvl)) {
1121 pvl = (HV *)&PL_sv_undef;
1125 XPUSHs (sv_2mortal (newSVpv (ds->type, 0)));
1126 XPUSHs (sv_2mortal (newRV_noinc ((SV *)pds)));
1127 XPUSHs (sv_2mortal (newRV_noinc ((SV *)pvl)));
1129 else if (PLUGIN_LOG == type) {
1130 subname = va_arg(ap, char *);
1136 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
1137 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
1139 else if (PLUGIN_NOTIF == type) {
1141 HV *notif = newHV ();
1143 subname = va_arg(ap, char *);
1147 * severity => $severity,
1151 * plugin => $plugin,
1153 * plugin_instance => $instance,
1154 * type_instance => $type_instance
1157 n = va_arg (ap, notification_t *);
1159 if (-1 == notification2hv (aTHX_ n, notif)) {
1162 notif = (HV *)&PL_sv_undef;
1166 XPUSHs (sv_2mortal (newRV_noinc ((SV *)notif)));
1168 else if (PLUGIN_FLUSH == type) {
1170 subname = va_arg(ap, char *);
1173 * $_[1] = $identifier;
1175 timeout = va_arg (ap, cdtime_t);
1177 XPUSHs (sv_2mortal (newSVnv (CDTIME_T_TO_DOUBLE (timeout))));
1178 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
1180 else if (PLUGIN_INIT == type) {
1181 subname = "Collectd::plugin_call_all";
1182 XPUSHs (sv_2mortal (newSViv ((IV)type)));
1184 else if (PLUGIN_SHUTDOWN == type) {
1185 subname = "Collectd::plugin_call_all";
1186 XPUSHs (sv_2mortal (newSViv ((IV)type)));
1188 else { /* Unknown type. Run 'plugin_call_all' and make compiler happy */
1189 subname = "Collectd::plugin_call_all";
1190 XPUSHs (sv_2mortal (newSViv ((IV)type)));
1195 retvals = call_pv_locked (aTHX_ subname);
1198 if (SvTRUE(ERRSV)) {
1199 if (PLUGIN_LOG != type)
1200 ERROR ("perl: %s error: %s", subname, SvPV_nolen(ERRSV));
1203 else if (0 < retvals) {
1215 } /* static int pplugin_call (int, ...) */
1218 * collectd's Perl interpreter based thread implementation.
1220 * This has been inspired by Perl's ithreads introduced in version 5.6.0.
1223 /* must be called with perl_threads->mutex locked */
1224 static void c_ithread_destroy (c_ithread_t *ithread)
1226 dTHXa (ithread->interp);
1228 assert (NULL != perl_threads);
1230 PERL_SET_CONTEXT (aTHX);
1231 log_debug ("Shutting down Perl interpreter %p...", aTHX);
1236 --perl_threads->number_of_threads;
1237 #endif /* COLLECT_DEBUG */
1239 perl_destruct (aTHX);
1242 if (NULL == ithread->prev)
1243 perl_threads->head = ithread->next;
1245 ithread->prev->next = ithread->next;
1247 if (NULL == ithread->next)
1248 perl_threads->tail = ithread->prev;
1250 ithread->next->prev = ithread->prev;
1254 } /* static void c_ithread_destroy (c_ithread_t *) */
1256 static void c_ithread_destructor (void *arg)
1258 c_ithread_t *ithread = (c_ithread_t *)arg;
1259 c_ithread_t *t = NULL;
1261 if (NULL == perl_threads)
1264 pthread_mutex_lock (&perl_threads->mutex);
1266 for (t = perl_threads->head; NULL != t; t = t->next)
1270 /* the ithread no longer exists */
1273 pthread_mutex_unlock (&perl_threads->mutex);
1277 c_ithread_destroy (ithread);
1279 pthread_mutex_unlock (&perl_threads->mutex);
1281 } /* static void c_ithread_destructor (void *) */
1283 /* must be called with perl_threads->mutex locked */
1284 static c_ithread_t *c_ithread_create (PerlInterpreter *base)
1286 c_ithread_t *t = NULL;
1289 assert (NULL != perl_threads);
1291 t = smalloc (sizeof (*t));
1292 memset (t, 0, sizeof (c_ithread_t));
1294 t->interp = (NULL == base)
1296 : perl_clone (base, CLONEf_KEEP_PTR_TABLE);
1300 if ((NULL != base) && (NULL != PL_endav)) {
1301 av_clear (PL_endav);
1302 av_undef (PL_endav);
1307 ++perl_threads->number_of_threads;
1308 #endif /* COLLECT_DEBUG */
1312 if (NULL == perl_threads->tail) {
1313 perl_threads->head = t;
1317 perl_threads->tail->next = t;
1318 t->prev = perl_threads->tail;
1321 t->pthread = pthread_self();
1324 perl_threads->tail = t;
1326 pthread_setspecific (perl_thr_key, (const void *)t);
1328 } /* static c_ithread_t *c_ithread_create (PerlInterpreter *) */
1331 * Filter chains implementation.
1334 static int fc_call (pTHX_ int type, int cb_type, pfc_user_data_t *data, ...)
1341 notification_meta_t **meta = NULL;
1346 if ((type < 0) || (type >= FC_TYPES))
1349 if ((cb_type < 0) || (cb_type >= FC_CB_TYPES))
1352 va_start (ap, data);
1359 XPUSHs (sv_2mortal (newSViv ((IV)type)));
1360 XPUSHs (sv_2mortal (newSVpv (data->name, 0)));
1361 XPUSHs (sv_2mortal (newSViv ((IV)cb_type)));
1363 if (FC_CB_CREATE == cb_type) {
1366 * $_[1] = $user_data;
1369 HV *config = newHV ();
1371 ci = va_arg (ap, oconfig_item_t *);
1373 if (0 != oconfig_item2hv (aTHX_ ci, config)) {
1376 config = (HV *)&PL_sv_undef;
1380 XPUSHs (sv_2mortal (newRV_noinc ((SV *)config)));
1382 else if (FC_CB_DESTROY == cb_type) {
1384 * $_[1] = $user_data;
1387 /* nothing to be done - the user data pointer
1388 * is pushed onto the stack later */
1390 else if (FC_CB_EXEC == cb_type) {
1395 * $_[3] = $user_data;
1403 ds = va_arg (ap, data_set_t *);
1404 vl = va_arg (ap, value_list_t *);
1405 meta = va_arg (ap, notification_meta_t **);
1407 if (0 != data_set2av (aTHX_ ds, pds)) {
1410 pds = (AV *)&PL_sv_undef;
1414 if (0 != value_list2hv (aTHX_ vl, ds, pvl)) {
1417 pvl = (HV *)&PL_sv_undef;
1424 if (0 != notification_meta2av (aTHX_ *meta, pmeta)) {
1427 pmeta = (AV *)&PL_sv_undef;
1432 pmeta = (AV *)&PL_sv_undef;
1435 XPUSHs (sv_2mortal (newRV_noinc ((SV *)pds)));
1436 XPUSHs (sv_2mortal (newRV_noinc ((SV *)pvl)));
1437 XPUSHs (sv_2mortal (newRV_noinc ((SV *)pmeta)));
1440 XPUSHs (sv_2mortal (newRV_inc (data->user_data)));
1444 retvals = call_pv_locked (aTHX_ "Collectd::fc_call");
1446 if ((FC_CB_EXEC == cb_type) && (meta != NULL)) {
1447 assert (pmeta != NULL);
1449 plugin_notification_meta_free (*meta);
1450 av2notification_meta (aTHX_ pmeta, meta);
1454 if (SvTRUE(ERRSV)) {
1455 ERROR ("perl: Collectd::fc_call error: %s", SvPV_nolen(ERRSV));
1458 else if (0 < retvals) {
1461 /* the exec callbacks return a status, while
1462 * the others return a boolean value */
1463 if (FC_CB_EXEC == cb_type)
1465 else if (! SvTRUE (tmp))
1475 } /* static int fc_call (int, int, pfc_user_data_t *, ...) */
1477 static int fc_create (int type, const oconfig_item_t *ci, void **user_data)
1479 pfc_user_data_t *data;
1485 if (NULL == perl_threads)
1489 c_ithread_t *t = NULL;
1491 pthread_mutex_lock (&perl_threads->mutex);
1492 t = c_ithread_create (perl_threads->head->interp);
1493 pthread_mutex_unlock (&perl_threads->mutex);
1498 log_debug ("fc_create: c_ithread: interp = %p (active threads: %i)",
1499 aTHX, perl_threads->number_of_threads);
1501 if ((1 != ci->values_num)
1502 || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
1503 log_warn ("A \"%s\" block expects a single string argument.",
1504 (FC_MATCH == type) ? "Match" : "Target");
1508 data = smalloc (sizeof (*data));
1509 data->name = sstrdup (ci->values[0].value.string);
1510 data->user_data = newSV (0);
1512 ret = fc_call (aTHX_ type, FC_CB_CREATE, data, ci);
1515 PFC_USER_DATA_FREE (data);
1519 } /* static int fc_create (int, const oconfig_item_t *, void **) */
1521 static int fc_destroy (int type, void **user_data)
1523 pfc_user_data_t *data = *(pfc_user_data_t **)user_data;
1529 if ((NULL == perl_threads) || (NULL == data))
1533 c_ithread_t *t = NULL;
1535 pthread_mutex_lock (&perl_threads->mutex);
1536 t = c_ithread_create (perl_threads->head->interp);
1537 pthread_mutex_unlock (&perl_threads->mutex);
1542 log_debug ("fc_destroy: c_ithread: interp = %p (active threads: %i)",
1543 aTHX, perl_threads->number_of_threads);
1545 ret = fc_call (aTHX_ type, FC_CB_DESTROY, data);
1547 PFC_USER_DATA_FREE (data);
1550 } /* static int fc_destroy (int, void **) */
1552 static int fc_exec (int type, const data_set_t *ds, const value_list_t *vl,
1553 notification_meta_t **meta, void **user_data)
1555 pfc_user_data_t *data = *(pfc_user_data_t **)user_data;
1559 if (NULL == perl_threads)
1562 assert (NULL != data);
1565 c_ithread_t *t = NULL;
1567 pthread_mutex_lock (&perl_threads->mutex);
1568 t = c_ithread_create (perl_threads->head->interp);
1569 pthread_mutex_unlock (&perl_threads->mutex);
1574 log_debug ("fc_exec: c_ithread: interp = %p (active threads: %i)",
1575 aTHX, perl_threads->number_of_threads);
1577 return fc_call (aTHX_ type, FC_CB_EXEC, data, ds, vl, meta);
1578 } /* static int fc_exec (int, const data_set_t *, const value_list_t *,
1579 notification_meta_t **, void **) */
1581 static int pmatch_create (const oconfig_item_t *ci, void **user_data)
1583 return fc_create (FC_MATCH, ci, user_data);
1584 } /* static int pmatch_create (const oconfig_item_t *, void **) */
1586 static int pmatch_destroy (void **user_data)
1588 return fc_destroy (FC_MATCH, user_data);
1589 } /* static int pmatch_destroy (void **) */
1591 static int pmatch_match (const data_set_t *ds, const value_list_t *vl,
1592 notification_meta_t **meta, void **user_data)
1594 return fc_exec (FC_MATCH, ds, vl, meta, user_data);
1595 } /* static int pmatch_match (const data_set_t *, const value_list_t *,
1596 notification_meta_t **, void **) */
1598 static match_proc_t pmatch = {
1599 pmatch_create, pmatch_destroy, pmatch_match
1602 static int ptarget_create (const oconfig_item_t *ci, void **user_data)
1604 return fc_create (FC_TARGET, ci, user_data);
1605 } /* static int ptarget_create (const oconfig_item_t *, void **) */
1607 static int ptarget_destroy (void **user_data)
1609 return fc_destroy (FC_TARGET, user_data);
1610 } /* static int ptarget_destroy (void **) */
1612 static int ptarget_invoke (const data_set_t *ds, value_list_t *vl,
1613 notification_meta_t **meta, void **user_data)
1615 return fc_exec (FC_TARGET, ds, vl, meta, user_data);
1616 } /* static int ptarget_invoke (const data_set_t *, value_list_t *,
1617 notification_meta_t **, void **) */
1619 static target_proc_t ptarget = {
1620 ptarget_create, ptarget_destroy, ptarget_invoke
1624 * Exported Perl API.
1627 static void _plugin_register_generic_userdata (pTHX, int type, const char *desc)
1630 user_data_t userdata;
1631 char cb_name[DATA_MAX_NAME_LEN];
1636 log_err ("Usage: Collectd::plugin_register_%s(pluginname, subname)",
1641 if (! SvOK (ST (0))) {
1642 log_err ("Collectd::plugin_register_%s(pluginname, subname): "
1643 "Invalid pluginname", desc);
1646 if (! SvOK (ST (1))) {
1647 log_err ("Collectd::plugin_register_%s(pluginname, subname): "
1648 "Invalid subname", desc);
1652 log_debug ("Collectd::plugin_register_%s: "
1653 "plugin = \"%s\", sub = \"%s\"",
1654 desc, SvPV_nolen (ST (0)), SvPV_nolen (ST (1)));
1656 ssnprintf (cb_name, sizeof (cb_name), "perl/%s", SvPV_nolen (ST (0)));
1657 memset(&userdata, 0, sizeof(userdata));
1658 userdata.data = strdup(SvPV_nolen (ST (1)));
1659 userdata.free_func = free;
1661 if (PLUGIN_READ == type) {
1662 ret = plugin_register_complex_read(
1666 plugin_get_interval(), /* Default interval */
1669 else if (PLUGIN_WRITE == type) {
1670 ret = plugin_register_write(cb_name, perl_write, &userdata);
1672 else if (PLUGIN_LOG == type) {
1673 ret = plugin_register_log(cb_name, perl_log, &userdata);
1675 else if (PLUGIN_NOTIF == type) {
1676 ret = plugin_register_notification(cb_name, perl_notify, &userdata);
1678 else if (PLUGIN_FLUSH == type) {
1679 ret = plugin_register_flush(cb_name, perl_flush, &userdata);
1688 free (userdata.data);
1691 } /* static void _plugin_register_generic_userdata ( ... ) */
1694 * Collectd::plugin_register_TYPE (pluginname, subname).
1697 * name of the perl plugin
1700 * name of the plugin's subroutine that does the work
1703 static XS (Collectd_plugin_register_read) {
1704 return _plugin_register_generic_userdata(aTHX, PLUGIN_READ, "read");
1707 static XS (Collectd_plugin_register_write) {
1708 return _plugin_register_generic_userdata(aTHX, PLUGIN_WRITE, "write");
1711 static XS (Collectd_plugin_register_log) {
1712 return _plugin_register_generic_userdata(aTHX, PLUGIN_LOG, "log");
1715 static XS (Collectd_plugin_register_notification) {
1716 return _plugin_register_generic_userdata(aTHX, PLUGIN_NOTIF, "notification");
1719 static XS (Collectd_plugin_register_flush) {
1720 return _plugin_register_generic_userdata(aTHX, PLUGIN_FLUSH, "flush");
1723 typedef int perl_unregister_function_t(const char *name);
1725 static void _plugin_unregister_generic (pTHX,
1726 perl_unregister_function_t *unreg, const char *desc)
1728 char cb_name[DATA_MAX_NAME_LEN];
1733 log_err ("Usage: Collectd::plugin_unregister_%s(pluginname)", desc);
1737 if (! SvOK (ST (0))) {
1738 log_err ("Collectd::plugin_unregister_%s(pluginname): "
1739 "Invalid pluginname", desc);
1743 log_debug ("Collectd::plugin_unregister_%s: plugin = \"%s\"",
1744 desc, SvPV_nolen (ST (0)));
1746 ssnprintf (cb_name, sizeof (cb_name), "perl/%s", SvPV_nolen (ST (0)));
1753 } /* static void _plugin_unregister_generic ( ... ) */
1756 * Collectd::plugin_unregister_TYPE (pluginname).
1759 * type of callback to be unregistered: read, write, log, notification, flush
1762 * name of the perl plugin
1765 static XS (Collectd_plugin_unregister_read) {
1766 return _plugin_unregister_generic(aTHX,
1767 plugin_unregister_read, "read");
1770 static XS (Collectd_plugin_unregister_write) {
1771 return _plugin_unregister_generic(aTHX,
1772 plugin_unregister_write, "write");
1775 static XS (Collectd_plugin_unregister_log) {
1776 return _plugin_unregister_generic(aTHX,
1777 plugin_unregister_log, "log");
1780 static XS (Collectd_plugin_unregister_notification) {
1781 return _plugin_unregister_generic(aTHX,
1782 plugin_unregister_notification, "notification");
1785 static XS (Collectd_plugin_unregister_flush) {
1786 return _plugin_unregister_generic(aTHX,
1787 plugin_unregister_flush, "flush");
1791 * Collectd::plugin_register_data_set (type, dataset).
1794 * type of the dataset
1797 * dataset to be registered
1799 static XS (Collectd_plugin_register_ds)
1806 log_warn ("Using plugin_register() to register new data-sets is "
1807 "deprecated - add new entries to a custom types.db instead.");
1810 log_err ("Usage: Collectd::plugin_register_data_set(type, dataset)");
1814 log_debug ("Collectd::plugin_register_data_set: "
1815 "type = \"%s\", dataset = \"%s\"",
1816 SvPV_nolen (ST (0)), SvPV_nolen (ST (1)));
1820 if (SvROK (data) && (SVt_PVAV == SvTYPE (SvRV (data)))) {
1821 ret = pplugin_register_data_set (aTHX_ SvPV_nolen (ST (0)),
1825 log_err ("Collectd::plugin_register_data_set: Invalid data.");
1833 } /* static XS (Collectd_plugin_register_ds) */
1836 * Collectd::plugin_unregister_data_set (type).
1839 * type of the dataset
1841 static XS (Collectd_plugin_unregister_ds)
1846 log_err ("Usage: Collectd::plugin_unregister_data_set(type)");
1850 log_debug ("Collectd::plugin_unregister_data_set: type = \"%s\"",
1851 SvPV_nolen (ST (0)));
1853 if (0 == pplugin_unregister_data_set (SvPV_nolen (ST (0))))
1857 } /* static XS (Collectd_plugin_register_ds) */
1860 * Collectd::plugin_dispatch_values (name, values).
1863 * name of the plugin
1866 * value list to submit
1868 static XS (Collectd_plugin_dispatch_values)
1877 log_err ("Usage: Collectd::plugin_dispatch_values(values)");
1881 log_debug ("Collectd::plugin_dispatch_values: values=\"%s\"",
1882 SvPV_nolen (ST (/* stack index = */ 0)));
1884 values = ST (/* stack index = */ 0);
1889 /* Make sure the argument is a hash reference. */
1890 if (! (SvROK (values) && (SVt_PVHV == SvTYPE (SvRV (values))))) {
1891 log_err ("Collectd::plugin_dispatch_values: Invalid values.");
1895 ret = pplugin_dispatch_values (aTHX_ (HV *)SvRV (values));
1901 } /* static XS (Collectd_plugin_dispatch_values) */
1904 * Collectd::plugin_get_interval ().
1906 static XS (Collectd_plugin_get_interval)
1910 /* make sure we don't get any unused variable warnings for 'items';
1911 * don't abort, though */
1913 log_err ("Usage: Collectd::plugin_get_interval()");
1915 XSRETURN_NV ((NV) CDTIME_T_TO_DOUBLE (plugin_get_interval ()));
1916 } /* static XS (Collectd_plugin_get_interval) */
1918 /* Collectd::plugin_write (plugin, ds, vl).
1921 * name of the plugin to call, may be 'undef'
1924 * data-set that describes the submitted values, may be 'undef'
1927 * value-list to be written
1929 static XS (Collectd__plugin_write)
1940 log_err ("Usage: Collectd::plugin_write(plugin, ds, vl)");
1944 log_debug ("Collectd::plugin_write: plugin=\"%s\", ds=\"%s\", vl=\"%s\"",
1945 SvPV_nolen (ST (0)), SvOK (ST (1)) ? SvPV_nolen (ST (1)) : "",
1946 SvPV_nolen (ST (2)));
1948 if (! SvOK (ST (0)))
1951 plugin = SvPV_nolen (ST (0));
1954 if (SvROK (ds) && (SVt_PVAV == SvTYPE (SvRV (ds))))
1955 ds_array = (AV *)SvRV (ds);
1956 else if (! SvOK (ds))
1959 log_err ("Collectd::plugin_write: Invalid data-set.");
1964 if (! (SvROK (vl) && (SVt_PVHV == SvTYPE (SvRV (vl))))) {
1965 log_err ("Collectd::plugin_write: Invalid value-list.");
1969 ret = pplugin_write (aTHX_ plugin, ds_array, (HV *)SvRV (vl));
1975 } /* static XS (Collectd__plugin_write) */
1978 * Collectd::_plugin_flush (plugin, timeout, identifier).
1981 * name of the plugin to flush
1984 * timeout to use when flushing the data
1987 * data-set identifier to flush
1989 static XS (Collectd__plugin_flush)
1991 char *plugin = NULL;
1998 log_err ("Usage: Collectd::_plugin_flush(plugin, timeout, id)");
2003 plugin = SvPV_nolen (ST (0));
2006 timeout = (int)SvIV (ST (1));
2009 id = SvPV_nolen (ST (2));
2011 log_debug ("Collectd::_plugin_flush: plugin = \"%s\", timeout = %i, "
2012 "id = \"%s\"", plugin, timeout, id);
2014 if (0 == plugin_flush (plugin, timeout, id))
2018 } /* static XS (Collectd__plugin_flush) */
2021 * Collectd::plugin_dispatch_notification (notif).
2024 * notification to dispatch
2026 static XS (Collectd_plugin_dispatch_notification)
2035 log_err ("Usage: Collectd::plugin_dispatch_notification(notif)");
2039 log_debug ("Collectd::plugin_dispatch_notification: notif = \"%s\"",
2040 SvPV_nolen (ST (0)));
2044 if (! (SvROK (notif) && (SVt_PVHV == SvTYPE (SvRV (notif))))) {
2045 log_err ("Collectd::plugin_dispatch_notification: Invalid notif.");
2049 ret = pplugin_dispatch_notification (aTHX_ (HV *)SvRV (notif));
2055 } /* static XS (Collectd_plugin_dispatch_notification) */
2058 * Collectd::plugin_log (level, message).
2061 * log level (LOG_DEBUG, ... LOG_ERR)
2066 static XS (Collectd_plugin_log)
2071 log_err ("Usage: Collectd::plugin_log(level, message)");
2075 plugin_log (SvIV (ST (0)), "%s", SvPV_nolen (ST (1)));
2077 } /* static XS (Collectd_plugin_log) */
2080 * Collectd::_fc_register (type, name)
2088 static XS (Collectd__fc_register)
2098 log_err ("Usage: Collectd::_fc_register(type, name)");
2102 type = SvIV (ST (0));
2103 name = SvPV_nolen (ST (1));
2105 if (FC_MATCH == type)
2106 ret = fc_register_match (name, pmatch);
2107 else if (FC_TARGET == type)
2108 ret = fc_register_target (name, ptarget);
2114 } /* static XS (Collectd_fc_register) */
2117 * Collectd::call_by_name (...).
2119 * Call a Perl sub identified by its name passed through $Collectd::cb_name.
2121 static XS (Collectd_call_by_name)
2126 if (NULL == (tmp = get_sv ("Collectd::cb_name", 0))) {
2127 sv_setpv (get_sv ("@", 1), "cb_name has not been set");
2132 name = SvPV_nolen (tmp);
2134 if (NULL == get_cv (name, 0)) {
2135 sv_setpvf (get_sv ("@", 1), "unknown callback \"%s\"", name);
2140 /* simply pass on the subroutine call without touching the stack,
2141 * thus leaving any arguments and return values in place */
2143 } /* static XS (Collectd_call_by_name) */
2146 * Interface to collectd.
2149 static int perl_init (void)
2154 if (NULL == perl_threads)
2158 c_ithread_t *t = NULL;
2160 pthread_mutex_lock (&perl_threads->mutex);
2161 t = c_ithread_create (perl_threads->head->interp);
2162 pthread_mutex_unlock (&perl_threads->mutex);
2167 log_debug ("perl_init: c_ithread: interp = %p (active threads: %i)",
2168 aTHX, perl_threads->number_of_threads);
2170 /* Lock the base thread to avoid race conditions with c_ithread_create().
2171 * See https://github.com/collectd/collectd/issues/9 and
2172 * https://github.com/collectd/collectd/issues/1706 for details.
2174 assert (aTHX == perl_threads->head->interp);
2175 pthread_mutex_lock (&perl_threads->mutex);
2177 status = pplugin_call (aTHX_ PLUGIN_INIT);
2179 pthread_mutex_unlock (&perl_threads->mutex);
2182 } /* static int perl_init (void) */
2184 static int perl_read (user_data_t *user_data)
2188 if (NULL == perl_threads)
2192 c_ithread_t *t = NULL;
2194 pthread_mutex_lock (&perl_threads->mutex);
2195 t = c_ithread_create (perl_threads->head->interp);
2196 pthread_mutex_unlock (&perl_threads->mutex);
2201 /* Assert that we're not running as the base thread. Otherwise, we might
2202 * run into concurrency issues with c_ithread_create(). See
2203 * https://github.com/collectd/collectd/issues/9 for details. */
2204 assert (aTHX != perl_threads->head->interp);
2206 log_debug ("perl_read: c_ithread: interp = %p (active threads: %i)",
2207 aTHX, perl_threads->number_of_threads);
2209 return pplugin_call (aTHX_ PLUGIN_READ, user_data->data);
2210 } /* static int perl_read (user_data_t *user_data) */
2212 static int perl_write (const data_set_t *ds, const value_list_t *vl,
2213 user_data_t *user_data)
2218 if (NULL == perl_threads)
2222 c_ithread_t *t = NULL;
2224 pthread_mutex_lock (&perl_threads->mutex);
2225 t = c_ithread_create (perl_threads->head->interp);
2226 pthread_mutex_unlock (&perl_threads->mutex);
2231 /* Lock the base thread if this is not called from one of the read threads
2232 * to avoid race conditions with c_ithread_create(). See
2233 * https://github.com/collectd/collectd/issues/9 for details. */
2234 if (aTHX == perl_threads->head->interp)
2235 pthread_mutex_lock (&perl_threads->mutex);
2237 log_debug ("perl_write: c_ithread: interp = %p (active threads: %i)",
2238 aTHX, perl_threads->number_of_threads);
2239 status = pplugin_call (aTHX_ PLUGIN_WRITE, user_data->data, ds, vl);
2241 if (aTHX == perl_threads->head->interp)
2242 pthread_mutex_unlock (&perl_threads->mutex);
2245 } /* static int perl_write (const data_set_t *, const value_list_t *) */
2247 static void perl_log (int level, const char *msg,
2248 user_data_t *user_data)
2252 if (NULL == perl_threads)
2256 c_ithread_t *t = NULL;
2258 pthread_mutex_lock (&perl_threads->mutex);
2259 t = c_ithread_create (perl_threads->head->interp);
2260 pthread_mutex_unlock (&perl_threads->mutex);
2265 /* Lock the base thread if this is not called from one of the read threads
2266 * to avoid race conditions with c_ithread_create(). See
2267 * https://github.com/collectd/collectd/issues/9 for details.
2270 if (aTHX == perl_threads->head->interp)
2271 pthread_mutex_lock (&perl_threads->mutex);
2273 pplugin_call (aTHX_ PLUGIN_LOG, user_data->data, level, msg);
2275 if (aTHX == perl_threads->head->interp)
2276 pthread_mutex_unlock (&perl_threads->mutex);
2279 } /* static void perl_log (int, const char *) */
2281 static int perl_notify (const notification_t *notif, user_data_t *user_data)
2285 if (NULL == perl_threads)
2289 c_ithread_t *t = NULL;
2291 pthread_mutex_lock (&perl_threads->mutex);
2292 t = c_ithread_create (perl_threads->head->interp);
2293 pthread_mutex_unlock (&perl_threads->mutex);
2297 return pplugin_call (aTHX_ PLUGIN_NOTIF, user_data->data, notif);
2298 } /* static int perl_notify (const notification_t *) */
2300 static int perl_flush (cdtime_t timeout, const char *identifier,
2301 user_data_t *user_data)
2305 if (NULL == perl_threads)
2309 c_ithread_t *t = NULL;
2311 pthread_mutex_lock (&perl_threads->mutex);
2312 t = c_ithread_create (perl_threads->head->interp);
2313 pthread_mutex_unlock (&perl_threads->mutex);
2317 return pplugin_call (aTHX_ PLUGIN_FLUSH, user_data->data, timeout, identifier);
2318 } /* static int perl_flush (const int) */
2320 static int perl_shutdown (void)
2327 plugin_unregister_complex_config ("perl");
2328 plugin_unregister_read_group ("perl");
2330 if (NULL == perl_threads)
2334 pthread_mutex_lock (&perl_threads->mutex);
2335 t = c_ithread_create (perl_threads->head->interp);
2336 pthread_mutex_unlock (&perl_threads->mutex);
2341 log_debug ("perl_shutdown: c_ithread: interp = %p (active threads: %i)",
2342 aTHX, perl_threads->number_of_threads);
2344 plugin_unregister_init ("perl");
2346 ret = pplugin_call (aTHX_ PLUGIN_SHUTDOWN);
2348 pthread_mutex_lock (&perl_threads->mutex);
2349 t = perl_threads->tail;
2352 struct timespec ts_wait;
2353 c_ithread_t *thr = t;
2355 /* the pointer has to be advanced before destroying
2356 * the thread as this will free the memory */
2361 /* Give some time to thread to exit from Perl interpreter */
2362 WARNING ("perl shutdown: Thread is running inside Perl. Waiting.");
2364 ts_wait.tv_nsec = 500000;
2365 nanosleep (&ts_wait, NULL);
2368 pthread_kill (thr->pthread, SIGTERM);
2369 ERROR ("perl shutdown: Thread hangs inside Perl. Thread killed.");
2371 /* Mark as running to avoid deadlock:
2372 c_ithread_destroy -> log_debug -> perl_log()
2375 c_ithread_destroy (thr);
2378 pthread_mutex_unlock (&perl_threads->mutex);
2379 pthread_mutex_destroy (&perl_threads->mutex);
2380 pthread_mutexattr_destroy (&perl_threads->mutexattr);
2382 sfree (perl_threads);
2384 pthread_key_delete (perl_thr_key);
2388 plugin_unregister_shutdown ("perl");
2390 } /* static void perl_shutdown (void) */
2393 * Access functions for global variables.
2395 * These functions implement the "magic" used to access
2396 * the global variables from Perl.
2399 static int g_pv_get (pTHX_ SV *var, MAGIC *mg)
2401 char *pv = mg->mg_ptr;
2404 } /* static int g_pv_get (pTHX_ SV *, MAGIC *) */
2406 static int g_pv_set (pTHX_ SV *var, MAGIC *mg)
2408 char *pv = mg->mg_ptr;
2409 sstrncpy (pv, SvPV_nolen (var), DATA_MAX_NAME_LEN);
2411 } /* static int g_pv_set (pTHX_ SV *, MAGIC *) */
2413 static int g_interval_get (pTHX_ SV *var, MAGIC *mg)
2415 log_warn ("Accessing $interval_g is deprecated (and might not "
2416 "give the desired results) - plugin_get_interval() should "
2417 "be used instead.");
2418 sv_setnv (var, CDTIME_T_TO_DOUBLE (interval_g));
2420 } /* static int g_interval_get (pTHX_ SV *, MAGIC *) */
2422 static int g_interval_set (pTHX_ SV *var, MAGIC *mg)
2424 double nv = (double)SvNV (var);
2425 log_warn ("Accessing $interval_g is deprecated (and might not "
2426 "give the desired results) - plugin_get_interval() should "
2427 "be used instead.");
2428 interval_g = DOUBLE_TO_CDTIME_T (nv);
2430 } /* static int g_interval_set (pTHX_ SV *, MAGIC *) */
2432 static MGVTBL g_pv_vtbl = {
2433 g_pv_get, g_pv_set, NULL, NULL, NULL, NULL, NULL
2434 #if HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL
2438 static MGVTBL g_interval_vtbl = {
2439 g_interval_get, g_interval_set, NULL, NULL, NULL, NULL, NULL
2440 #if HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL
2445 /* bootstrap the Collectd module */
2446 static void xs_init (pTHX)
2450 char *file = __FILE__;
2454 /* enable usage of Perl modules using shared libraries */
2455 newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
2458 for (int i = 0; NULL != api[i].f; ++i)
2459 newXS (api[i].name, api[i].f, file);
2461 stash = gv_stashpv ("Collectd", 1);
2463 /* export "constants" */
2464 for (int i = 0; '\0' != constants[i].name[0]; ++i)
2465 newCONSTSUB (stash, constants[i].name, newSViv (constants[i].value));
2467 /* export global variables
2468 * by adding "magic" to the SV's representing the globale variables
2469 * perl is able to automagically call the get/set function when
2470 * accessing any such variable (this is basically the same as using
2472 /* global strings */
2473 for (int i = 0; '\0' != g_strings[i].name[0]; ++i) {
2474 tmp = get_sv (g_strings[i].name, 1);
2475 sv_magicext (tmp, NULL, PERL_MAGIC_ext, &g_pv_vtbl,
2476 g_strings[i].var, 0);
2479 tmp = get_sv ("Collectd::interval_g", /* create = */ 1);
2480 sv_magicext (tmp, NULL, /* how = */ PERL_MAGIC_ext,
2481 /* vtbl = */ &g_interval_vtbl,
2482 /* name = */ NULL, /* namelen = */ 0);
2485 } /* static void xs_init (pTHX) */
2487 /* Initialize the global Perl interpreter. */
2488 static int init_pi (int argc, char **argv)
2492 if (NULL != perl_threads)
2495 log_info ("Initializing Perl interpreter...");
2498 for (int i = 0; i < argc; ++i)
2499 log_debug ("argv[%i] = \"%s\"", i, argv[i]);
2501 #endif /* COLLECT_DEBUG */
2503 if (0 != pthread_key_create (&perl_thr_key, c_ithread_destructor)) {
2504 log_err ("init_pi: pthread_key_create failed");
2506 /* this must not happen - cowardly giving up if it does */
2511 /* On FreeBSD, PERL_SYS_INIT3 expands to some expression which
2512 * triggers a "value computed is not used" warning by gcc. */
2515 PERL_SYS_INIT3 (&argc, &argv, &environ);
2517 perl_threads = smalloc (sizeof (*perl_threads));
2518 memset (perl_threads, 0, sizeof (c_ithread_list_t));
2520 pthread_mutexattr_init(&perl_threads->mutexattr);
2521 pthread_mutexattr_settype(&perl_threads->mutexattr, PTHREAD_MUTEX_RECURSIVE);
2522 pthread_mutex_init (&perl_threads->mutex, &perl_threads->mutexattr);
2523 /* locking the mutex should not be necessary at this point
2524 * but let's just do it for the sake of completeness */
2525 pthread_mutex_lock (&perl_threads->mutex);
2527 perl_threads->head = c_ithread_create (NULL);
2528 perl_threads->tail = perl_threads->head;
2530 if (NULL == (perl_threads->head->interp = perl_alloc ())) {
2531 log_err ("init_pi: Not enough memory.");
2535 aTHX = perl_threads->head->interp;
2536 pthread_mutex_unlock (&perl_threads->mutex);
2538 perl_construct (aTHX);
2540 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
2542 if (0 != perl_parse (aTHX_ xs_init, argc, argv, NULL)) {
2543 SV *err = get_sv ("@", 1);
2544 log_err ("init_pi: Unable to bootstrap Collectd: %s",
2547 perl_destruct (perl_threads->head->interp);
2548 perl_free (perl_threads->head->interp);
2549 sfree (perl_threads);
2551 pthread_key_delete (perl_thr_key);
2555 /* Set $0 to "collectd" because perl_parse() has to set it to "-e". */
2556 sv_setpv (get_sv ("0", 0), "collectd");
2560 plugin_register_init ("perl", perl_init);
2561 plugin_register_shutdown ("perl", perl_shutdown);
2563 } /* static int init_pi (const char **, const int) */
2566 * LoadPlugin "<Plugin>"
2568 static int perl_config_loadplugin (pTHX_ oconfig_item_t *ci)
2570 char module_name[DATA_MAX_NAME_LEN];
2574 if ((0 != ci->children_num) || (1 != ci->values_num)
2575 || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2576 log_err ("LoadPlugin expects a single string argument.");
2580 value = ci->values[0].value.string;
2582 if (NULL == get_module_name (module_name, sizeof (module_name), value)) {
2583 log_err ("Invalid module name %s", value);
2587 if (0 != init_pi (perl_argc, perl_argv))
2590 assert (NULL != perl_threads);
2591 assert (NULL != perl_threads->head);
2593 aTHX = perl_threads->head->interp;
2595 log_debug ("perl_config: Loading Perl plugin \"%s\"", value);
2596 load_module (PERL_LOADMOD_NOIMPORT,
2597 newSVpv (module_name, strlen (module_name)), Nullsv);
2599 } /* static int perl_config_loadplugin (oconfig_item_it *) */
2604 static int perl_config_basename (pTHX_ oconfig_item_t *ci)
2608 if ((0 != ci->children_num) || (1 != ci->values_num)
2609 || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2610 log_err ("BaseName expects a single string argument.");
2614 value = ci->values[0].value.string;
2616 log_debug ("perl_config: Setting plugin basename to \"%s\"", value);
2617 sstrncpy (base_name, value, sizeof (base_name));
2619 } /* static int perl_config_basename (oconfig_item_it *) */
2622 * EnableDebugger "<Package>"|""
2624 static int perl_config_enabledebugger (pTHX_ oconfig_item_t *ci)
2628 if ((0 != ci->children_num) || (1 != ci->values_num)
2629 || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2630 log_err ("EnableDebugger expects a single string argument.");
2634 if (NULL != perl_threads) {
2635 log_warn ("EnableDebugger has no effects if used after LoadPlugin.");
2639 value = ci->values[0].value.string;
2641 perl_argv = realloc (perl_argv,
2642 (++perl_argc + 1) * sizeof (char *));
2644 if (NULL == perl_argv) {
2645 log_err ("perl_config: Not enough memory.");
2649 if ('\0' == value[0]) {
2650 perl_argv[perl_argc - 1] = "-d";
2653 perl_argv[perl_argc - 1] = smalloc (strlen (value) + 4);
2654 sstrncpy (perl_argv[perl_argc - 1], "-d:", 4);
2655 sstrncpy (perl_argv[perl_argc - 1] + 3, value, strlen (value) + 1);
2658 perl_argv[perl_argc] = NULL;
2660 } /* static int perl_config_enabledebugger (oconfig_item_it *) */
2663 * IncludeDir "<Dir>"
2665 static int perl_config_includedir (pTHX_ oconfig_item_t *ci)
2669 if ((0 != ci->children_num) || (1 != ci->values_num)
2670 || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2671 log_err ("IncludeDir expects a single string argument.");
2675 value = ci->values[0].value.string;
2678 perl_argv = realloc (perl_argv,
2679 (++perl_argc + 1) * sizeof (char *));
2681 if (NULL == perl_argv) {
2682 log_err ("perl_config: Not enough memory.");
2686 perl_argv[perl_argc - 1] = smalloc (strlen (value) + 3);
2687 sstrncpy(perl_argv[perl_argc - 1], "-I", 3);
2688 sstrncpy(perl_argv[perl_argc - 1] + 2, value, strlen (value) + 1);
2690 perl_argv[perl_argc] = NULL;
2693 /* prepend the directory to @INC */
2694 av_unshift (GvAVn (PL_incgv), 1);
2695 av_store (GvAVn (PL_incgv), 0, newSVpv (value, strlen (value)));
2698 } /* static int perl_config_includedir (oconfig_item_it *) */
2703 static int perl_config_plugin (pTHX_ oconfig_item_t *ci)
2713 if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2714 log_err ("LoadPlugin expects a single string argument.");
2718 plugin = ci->values[0].value.string;
2721 if (0 != oconfig_item2hv (aTHX_ ci, config)) {
2725 log_err ("Unable to convert configuration to a Perl hash value.");
2726 config = (HV *)&PL_sv_undef;
2734 XPUSHs (sv_2mortal (newSVpv (plugin, 0)));
2735 XPUSHs (sv_2mortal (newRV_noinc ((SV *)config)));
2739 retvals = call_pv ("Collectd::_plugin_dispatch_config", G_SCALAR);
2754 } /* static int perl_config_plugin (oconfig_item_it *) */
2756 static int perl_config (oconfig_item_t *ci)
2762 for (int i = 0; i < ci->children_num; ++i) {
2763 oconfig_item_t *c = ci->children + i;
2764 int current_status = 0;
2766 if (NULL != perl_threads)
2768 if ((aTHX = PERL_GET_CONTEXT) == NULL)
2772 if (0 == strcasecmp (c->key, "LoadPlugin"))
2773 current_status = perl_config_loadplugin (aTHX_ c);
2774 else if (0 == strcasecmp (c->key, "BaseName"))
2775 current_status = perl_config_basename (aTHX_ c);
2776 else if (0 == strcasecmp (c->key, "EnableDebugger"))
2777 current_status = perl_config_enabledebugger (aTHX_ c);
2778 else if (0 == strcasecmp (c->key, "IncludeDir"))
2779 current_status = perl_config_includedir (aTHX_ c);
2780 else if (0 == strcasecmp (c->key, "Plugin"))
2781 current_status = perl_config_plugin (aTHX_ c);
2784 log_warn ("Ignoring unknown config key \"%s\".", c->key);
2788 /* fatal error - it's up to perl_config_* to clean up */
2789 if (0 > current_status) {
2790 log_err ("Configuration failed with a fatal error - "
2791 "plugin disabled!");
2792 return current_status;
2795 status += current_status;
2798 } /* static int perl_config (oconfig_item_t *) */
2800 void module_register (void)
2803 perl_argv = smalloc ((perl_argc + 1) * sizeof (*perl_argv));
2805 /* default options for the Perl interpreter */
2807 perl_argv[1] = "-MCollectd";
2808 perl_argv[2] = "-e";
2810 perl_argv[4] = NULL;
2812 plugin_register_complex_config ("perl", perl_config);
2814 } /* void module_register (void) */
2816 /* vim: set sw=4 ts=4 tw=78 noexpandtab : */