2 * collectd - src/perl.c
3 * Copyright (C) 2007-2009 Sebastian Harl
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Sebastian Harl <sh at tokkee.org>
25 * Pavel Rochnyak <pavel2000 ngs.ru>
29 * This plugin embeds a Perl interpreter into collectd and provides an
30 * interface for collectd plugins written in perl.
33 /* do not automatically get the thread specific Perl interpreter */
34 #define PERL_NO_GET_CONTEXT
36 #define DONT_POISON_SPRINTF_YET 1
39 #undef DONT_POISON_SPRINTF_YET
48 #if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
50 # pragma GCC poison sprintf
55 /* Some versions of Perl define their own version of DEBUG... :-/ */
60 /* ... while we want the definition found in plugin.h. */
64 #include "filter_chain.h"
66 #if !defined(USE_ITHREADS)
67 # error "Perl does not support ithreads!"
68 #endif /* !defined(USE_ITHREADS) */
70 /* clear the Perl sub's stack frame
71 * (this should only be used inside an XSUB) */
72 #define CLEAR_STACK_FRAME PL_stack_sp = PL_stack_base + *PL_markstack_ptr
76 #define PLUGIN_WRITE 2
77 #define PLUGIN_SHUTDOWN 3
79 #define PLUGIN_NOTIF 5
80 #define PLUGIN_FLUSH 6
82 #define PLUGIN_TYPES 7
84 #define PLUGIN_CONFIG 254
85 #define PLUGIN_DATASET 255
92 #define FC_CB_CREATE 0
93 #define FC_CB_DESTROY 1
98 #define log_debug(...) DEBUG ("perl: " __VA_ARGS__)
99 #define log_info(...) INFO ("perl: " __VA_ARGS__)
100 #define log_warn(...) WARNING ("perl: " __VA_ARGS__)
101 #define log_err(...) ERROR ("perl: " __VA_ARGS__)
103 /* this is defined in DynaLoader.a */
104 void boot_DynaLoader (PerlInterpreter *, CV *);
106 static XS (Collectd_plugin_register_read);
107 static XS (Collectd_plugin_register_write);
108 static XS (Collectd_plugin_register_log);
109 static XS (Collectd_plugin_register_notification);
110 static XS (Collectd_plugin_register_flush);
111 static XS (Collectd_plugin_unregister_read);
112 static XS (Collectd_plugin_unregister_write);
113 static XS (Collectd_plugin_unregister_log);
114 static XS (Collectd_plugin_unregister_notification);
115 static XS (Collectd_plugin_unregister_flush);
116 static XS (Collectd_plugin_register_ds);
117 static XS (Collectd_plugin_unregister_ds);
118 static XS (Collectd_plugin_dispatch_values);
119 static XS (Collectd_plugin_get_interval);
120 static XS (Collectd__plugin_write);
121 static XS (Collectd__plugin_flush);
122 static XS (Collectd_plugin_dispatch_notification);
123 static XS (Collectd_plugin_log);
124 static XS (Collectd__fc_register);
125 static XS (Collectd_call_by_name);
127 static int perl_read (user_data_t *ud);
128 static int perl_write (const data_set_t *ds, const value_list_t *vl,
129 user_data_t *user_data);
130 static void perl_log (int level, const char *msg, user_data_t *user_data);
131 static int perl_notify (const notification_t *notif, user_data_t *user_data);
132 static int perl_flush (cdtime_t timeout, const char *identifier,
133 user_data_t *user_data);
139 typedef struct c_ithread_s {
140 /* the thread's Perl interpreter */
141 PerlInterpreter *interp;
142 _Bool running; /* thread is inside Perl interpreter */
146 /* double linked list of threads */
147 struct c_ithread_s *prev;
148 struct c_ithread_s *next;
156 /* some usage stats */
157 int number_of_threads;
158 #endif /* COLLECT_DEBUG */
160 pthread_mutex_t mutex;
161 pthread_mutexattr_t mutexattr;
164 /* name / user_data for Perl matches / targets */
170 #define PFC_USER_DATA_FREE(data) \
172 sfree ((data)->name); \
173 if (NULL != (data)->user_data) \
174 sv_free ((data)->user_data); \
181 extern char **environ;
187 /* if perl_threads != NULL perl_threads->head must
188 * point to the "base" thread */
189 static c_ithread_list_t *perl_threads = NULL;
191 /* the key used to store each pthread's ithread */
192 static pthread_key_t perl_thr_key;
194 static int perl_argc = 0;
195 static char **perl_argv = NULL;
197 static char base_name[DATA_MAX_NAME_LEN] = "";
204 { "Collectd::plugin_register_read", Collectd_plugin_register_read },
205 { "Collectd::plugin_register_write", Collectd_plugin_register_write },
206 { "Collectd::plugin_register_log", Collectd_plugin_register_log },
207 { "Collectd::plugin_register_notification",
208 Collectd_plugin_register_notification },
209 { "Collectd::plugin_register_flush", Collectd_plugin_register_flush },
210 { "Collectd::plugin_unregister_read", Collectd_plugin_unregister_read },
211 { "Collectd::plugin_unregister_write", Collectd_plugin_unregister_write },
212 { "Collectd::plugin_unregister_log", Collectd_plugin_unregister_log },
213 { "Collectd::plugin_unregister_notification",
214 Collectd_plugin_unregister_notification },
215 { "Collectd::plugin_unregister_flush", Collectd_plugin_unregister_flush },
216 { "Collectd::plugin_register_data_set", Collectd_plugin_register_ds },
217 { "Collectd::plugin_unregister_data_set", Collectd_plugin_unregister_ds },
218 { "Collectd::plugin_dispatch_values", Collectd_plugin_dispatch_values },
219 { "Collectd::plugin_get_interval", Collectd_plugin_get_interval },
220 { "Collectd::_plugin_write", Collectd__plugin_write },
221 { "Collectd::_plugin_flush", Collectd__plugin_flush },
222 { "Collectd::plugin_dispatch_notification",
223 Collectd_plugin_dispatch_notification },
224 { "Collectd::plugin_log", Collectd_plugin_log },
225 { "Collectd::_fc_register", Collectd__fc_register },
226 { "Collectd::call_by_name", Collectd_call_by_name },
235 { "Collectd::TYPE_INIT", PLUGIN_INIT },
236 { "Collectd::TYPE_READ", PLUGIN_READ },
237 { "Collectd::TYPE_WRITE", PLUGIN_WRITE },
238 { "Collectd::TYPE_SHUTDOWN", PLUGIN_SHUTDOWN },
239 { "Collectd::TYPE_LOG", PLUGIN_LOG },
240 { "Collectd::TYPE_NOTIF", PLUGIN_NOTIF },
241 { "Collectd::TYPE_FLUSH", PLUGIN_FLUSH },
242 { "Collectd::TYPE_CONFIG", PLUGIN_CONFIG },
243 { "Collectd::TYPE_DATASET", PLUGIN_DATASET },
244 { "Collectd::DS_TYPE_COUNTER", DS_TYPE_COUNTER },
245 { "Collectd::DS_TYPE_GAUGE", DS_TYPE_GAUGE },
246 { "Collectd::DS_TYPE_DERIVE", DS_TYPE_DERIVE },
247 { "Collectd::DS_TYPE_ABSOLUTE", DS_TYPE_ABSOLUTE },
248 { "Collectd::LOG_ERR", LOG_ERR },
249 { "Collectd::LOG_WARNING", LOG_WARNING },
250 { "Collectd::LOG_NOTICE", LOG_NOTICE },
251 { "Collectd::LOG_INFO", LOG_INFO },
252 { "Collectd::LOG_DEBUG", LOG_DEBUG },
253 { "Collectd::FC_MATCH", FC_MATCH },
254 { "Collectd::FC_TARGET", FC_TARGET },
255 { "Collectd::FC_CB_CREATE", FC_CB_CREATE },
256 { "Collectd::FC_CB_DESTROY", FC_CB_DESTROY },
257 { "Collectd::FC_CB_EXEC", FC_CB_EXEC },
258 { "Collectd::FC_MATCH_NO_MATCH", FC_MATCH_NO_MATCH },
259 { "Collectd::FC_MATCH_MATCHES", FC_MATCH_MATCHES },
260 { "Collectd::FC_TARGET_CONTINUE", FC_TARGET_CONTINUE },
261 { "Collectd::FC_TARGET_STOP", FC_TARGET_STOP },
262 { "Collectd::FC_TARGET_RETURN", FC_TARGET_RETURN },
263 { "Collectd::NOTIF_FAILURE", NOTIF_FAILURE },
264 { "Collectd::NOTIF_WARNING", NOTIF_WARNING },
265 { "Collectd::NOTIF_OKAY", NOTIF_OKAY },
274 { "Collectd::hostname_g", hostname_g },
279 * Helper functions for data type conversion.
294 static int hv2data_source (pTHX_ HV *hash, data_source_t *ds)
298 if ((NULL == hash) || (NULL == ds))
301 if (NULL != (tmp = hv_fetch (hash, "name", 4, 0))) {
302 sstrncpy (ds->name, SvPV_nolen (*tmp), sizeof (ds->name));
305 log_err ("hv2data_source: No DS name given.");
309 if (NULL != (tmp = hv_fetch (hash, "type", 4, 0))) {
310 ds->type = SvIV (*tmp);
312 if ((DS_TYPE_COUNTER != ds->type)
313 && (DS_TYPE_GAUGE != ds->type)
314 && (DS_TYPE_DERIVE != ds->type)
315 && (DS_TYPE_ABSOLUTE != ds->type)) {
316 log_err ("hv2data_source: Invalid DS type.");
321 ds->type = DS_TYPE_COUNTER;
324 if (NULL != (tmp = hv_fetch (hash, "min", 3, 0)))
325 ds->min = SvNV (*tmp);
329 if (NULL != (tmp = hv_fetch (hash, "max", 3, 0)))
330 ds->max = SvNV (*tmp);
334 } /* static int hv2data_source (HV *, data_source_t *) */
336 /* av2value converts at most "len" elements from "array" to "value". Returns the
337 * number of elements converted or zero on error. */
338 static size_t av2value (pTHX_ char *name, AV *array, value_t *value, size_t array_len)
340 const data_set_t *ds;
342 if ((NULL == name) || (NULL == array) || (NULL == value) || (array_len == 0))
345 ds = plugin_get_ds (name);
347 log_err ("av2value: Unknown dataset \"%s\"", name);
351 if (array_len < ds->ds_num) {
352 log_warn ("av2value: array does not contain enough elements for type \"%s\": got %zu, want %zu",
353 name, array_len, ds->ds_num);
355 } else if (array_len > ds->ds_num) {
356 log_warn ("av2value: array contains excess elements for type \"%s\": got %zu, want %zu",
357 name, array_len, ds->ds_num);
360 for (size_t i = 0; i < ds->ds_num; ++i) {
361 SV **tmp = av_fetch (array, i, 0);
364 if (DS_TYPE_COUNTER == ds->ds[i].type)
365 value[i].counter = SvIV (*tmp);
366 else if (DS_TYPE_GAUGE == ds->ds[i].type)
367 value[i].gauge = SvNV (*tmp);
368 else if (DS_TYPE_DERIVE == ds->ds[i].type)
369 value[i].derive = SvIV (*tmp);
370 else if (DS_TYPE_ABSOLUTE == ds->ds[i].type)
371 value[i].absolute = SvIV (*tmp);
379 } /* static size_t av2value (char *, AV *, value_t *, size_t) */
384 * values => [ @values ],
388 * plugin_instance => $pinstance,
389 * type_instance => $tinstance,
392 static int hv2value_list (pTHX_ HV *hash, value_list_t *vl)
396 if ((NULL == hash) || (NULL == vl))
399 if (NULL == (tmp = hv_fetch (hash, "type", 4, 0))) {
400 log_err ("hv2value_list: No type given.");
404 sstrncpy (vl->type, SvPV_nolen (*tmp), sizeof (vl->type));
406 if ((NULL == (tmp = hv_fetch (hash, "values", 6, 0)))
407 || (! (SvROK (*tmp) && (SVt_PVAV == SvTYPE (SvRV (*tmp)))))) {
408 log_err ("hv2value_list: No valid values given.");
413 AV *array = (AV *)SvRV (*tmp);
414 /* av_len returns the highest index, not the actual length. */
415 size_t array_len = (size_t) (av_len (array) + 1);
419 vl->values = calloc (array_len, sizeof (*vl->values));
420 vl->values_len = av2value (aTHX_ vl->type, (AV *)SvRV (*tmp), vl->values, array_len);
421 if (vl->values_len == 0) {
427 if (NULL != (tmp = hv_fetch (hash, "time", 4, 0)))
429 double t = SvNV (*tmp);
430 vl->time = DOUBLE_TO_CDTIME_T (t);
433 if (NULL != (tmp = hv_fetch (hash, "interval", 8, 0)))
435 double t = SvNV (*tmp);
436 vl->interval = DOUBLE_TO_CDTIME_T (t);
439 if (NULL != (tmp = hv_fetch (hash, "host", 4, 0)))
440 sstrncpy (vl->host, SvPV_nolen (*tmp), sizeof (vl->host));
442 sstrncpy (vl->host, hostname_g, sizeof (vl->host));
444 if (NULL != (tmp = hv_fetch (hash, "plugin", 6, 0)))
445 sstrncpy (vl->plugin, SvPV_nolen (*tmp), sizeof (vl->plugin));
447 if (NULL != (tmp = hv_fetch (hash, "plugin_instance", 15, 0)))
448 sstrncpy (vl->plugin_instance, SvPV_nolen (*tmp),
449 sizeof (vl->plugin_instance));
451 if (NULL != (tmp = hv_fetch (hash, "type_instance", 13, 0)))
452 sstrncpy (vl->type_instance, SvPV_nolen (*tmp),
453 sizeof (vl->type_instance));
455 } /* static int hv2value_list (pTHX_ HV *, value_list_t *) */
457 static int av2data_set (pTHX_ AV *array, char *name, data_set_t *ds)
461 if ((NULL == array) || (NULL == name) || (NULL == ds))
464 len = av_len (array);
467 log_err ("av2data_set: Invalid data set.");
471 ds->ds = smalloc ((len + 1) * sizeof (*ds->ds));
472 ds->ds_num = len + 1;
474 for (int i = 0; i <= len; ++i) {
475 SV **elem = av_fetch (array, i, 0);
478 log_err ("av2data_set: Failed to fetch data source %i.", i);
482 if (! (SvROK (*elem) && (SVt_PVHV == SvTYPE (SvRV (*elem))))) {
483 log_err ("av2data_set: Invalid data source.");
487 if (-1 == hv2data_source (aTHX_ (HV *)SvRV (*elem), &ds->ds[i]))
490 log_debug ("av2data_set: "
491 "DS.name = \"%s\", DS.type = %i, DS.min = %f, DS.max = %f",
492 ds->ds[i].name, ds->ds[i].type, ds->ds[i].min, ds->ds[i].max);
495 sstrncpy (ds->type, name, sizeof (ds->type));
497 } /* static int av2data_set (pTHX_ AV *, data_set_t *) */
502 * severity => $severity,
508 * plugin_instance => $instance,
509 * type_instance => $type_instance,
510 * meta => [ { name => <name>, value => <value> }, ... ]
513 static int av2notification_meta (pTHX_ AV *array, notification_meta_t **meta)
515 notification_meta_t **m = meta;
517 int len = av_len (array);
519 for (int i = 0; i <= len; ++i) {
520 SV **tmp = av_fetch (array, i, 0);
526 if (! (SvROK (*tmp) && (SVt_PVHV == SvTYPE (SvRV (*tmp))))) {
527 log_warn ("av2notification_meta: Skipping invalid "
528 "meta information.");
532 hash = (HV *)SvRV (*tmp);
534 *m = smalloc (sizeof (**m));
536 if (NULL == (tmp = hv_fetch (hash, "name", 4, 0))) {
537 log_warn ("av2notification_meta: Skipping invalid "
538 "meta information.");
542 sstrncpy ((*m)->name, SvPV_nolen (*tmp), sizeof ((*m)->name));
544 if (NULL == (tmp = hv_fetch (hash, "value", 5, 0))) {
545 log_warn ("av2notification_meta: Skipping invalid "
546 "meta information.");
552 (*m)->nm_value.nm_double = SvNVX (*tmp);
553 (*m)->type = NM_TYPE_DOUBLE;
555 else if (SvUOK (*tmp)) {
556 (*m)->nm_value.nm_unsigned_int = SvUVX (*tmp);
557 (*m)->type = NM_TYPE_UNSIGNED_INT;
559 else if (SvIOK (*tmp)) {
560 (*m)->nm_value.nm_signed_int = SvIVX (*tmp);
561 (*m)->type = NM_TYPE_SIGNED_INT;
564 (*m)->nm_value.nm_string = sstrdup (SvPV_nolen (*tmp));
565 (*m)->type = NM_TYPE_STRING;
572 } /* static int av2notification_meta (AV *, notification_meta_t *) */
574 static int hv2notification (pTHX_ HV *hash, notification_t *n)
578 if ((NULL == hash) || (NULL == n))
581 if (NULL != (tmp = hv_fetch (hash, "severity", 8, 0)))
582 n->severity = SvIV (*tmp);
584 n->severity = NOTIF_FAILURE;
586 if (NULL != (tmp = hv_fetch (hash, "time", 4, 0)))
588 double t = SvNV (*tmp);
589 n->time = DOUBLE_TO_CDTIME_T (t);
594 if (NULL != (tmp = hv_fetch (hash, "message", 7, 0)))
595 sstrncpy (n->message, SvPV_nolen (*tmp), sizeof (n->message));
597 if (NULL != (tmp = hv_fetch (hash, "host", 4, 0)))
598 sstrncpy (n->host, SvPV_nolen (*tmp), sizeof (n->host));
600 sstrncpy (n->host, hostname_g, sizeof (n->host));
602 if (NULL != (tmp = hv_fetch (hash, "plugin", 6, 0)))
603 sstrncpy (n->plugin, SvPV_nolen (*tmp), sizeof (n->plugin));
605 if (NULL != (tmp = hv_fetch (hash, "plugin_instance", 15, 0)))
606 sstrncpy (n->plugin_instance, SvPV_nolen (*tmp),
607 sizeof (n->plugin_instance));
609 if (NULL != (tmp = hv_fetch (hash, "type", 4, 0)))
610 sstrncpy (n->type, SvPV_nolen (*tmp), sizeof (n->type));
612 if (NULL != (tmp = hv_fetch (hash, "type_instance", 13, 0)))
613 sstrncpy (n->type_instance, SvPV_nolen (*tmp),
614 sizeof (n->type_instance));
617 while (NULL != (tmp = hv_fetch (hash, "meta", 4, 0))) {
618 if (! (SvROK (*tmp) && (SVt_PVAV == SvTYPE (SvRV (*tmp))))) {
619 log_warn ("hv2notification: Ignoring invalid meta information.");
623 if (0 != av2notification_meta (aTHX_ (AV *)SvRV (*tmp), &n->meta)) {
624 plugin_notification_meta_free (n->meta);
631 } /* static int hv2notification (pTHX_ HV *, notification_t *) */
633 static int data_set2av (pTHX_ data_set_t *ds, AV *array)
635 if ((NULL == ds) || (NULL == array))
638 av_extend (array, ds->ds_num);
640 for (size_t i = 0; i < ds->ds_num; ++i) {
641 HV *source = newHV ();
643 if (NULL == hv_store (source, "name", 4,
644 newSVpv (ds->ds[i].name, 0), 0))
647 if (NULL == hv_store (source, "type", 4, newSViv (ds->ds[i].type), 0))
650 if (! isnan (ds->ds[i].min))
651 if (NULL == hv_store (source, "min", 3,
652 newSVnv (ds->ds[i].min), 0))
655 if (! isnan (ds->ds[i].max))
656 if (NULL == hv_store (source, "max", 3,
657 newSVnv (ds->ds[i].max), 0))
660 if (NULL == av_store (array, i, newRV_noinc ((SV *)source)))
664 } /* static int data_set2av (data_set_t *, AV *) */
666 static int value_list2hv (pTHX_ value_list_t *vl, data_set_t *ds, HV *hash)
671 if ((NULL == vl) || (NULL == ds) || (NULL == hash))
675 /* av_extend takes the last *index* to which the array should be extended. */
676 av_extend (values, vl->values_len - 1);
678 assert (ds->ds_num == vl->values_len);
679 for (i = 0; i < vl->values_len; ++i) {
682 if (DS_TYPE_COUNTER == ds->ds[i].type)
683 val = newSViv (vl->values[i].counter);
684 else if (DS_TYPE_GAUGE == ds->ds[i].type)
685 val = newSVnv (vl->values[i].gauge);
686 else if (DS_TYPE_DERIVE == ds->ds[i].type)
687 val = newSViv (vl->values[i].derive);
688 else if (DS_TYPE_ABSOLUTE == ds->ds[i].type)
689 val = newSViv (vl->values[i].absolute);
691 if (NULL == av_store (values, i, val)) {
697 if (NULL == hv_store (hash, "values", 6, newRV_noinc ((SV *)values), 0))
702 double t = CDTIME_T_TO_DOUBLE (vl->time);
703 if (NULL == hv_store (hash, "time", 4, newSVnv (t), 0))
708 double t = CDTIME_T_TO_DOUBLE (vl->interval);
709 if (NULL == hv_store (hash, "interval", 8, newSVnv (t), 0))
713 if ('\0' != vl->host[0])
714 if (NULL == hv_store (hash, "host", 4, newSVpv (vl->host, 0), 0))
717 if ('\0' != vl->plugin[0])
718 if (NULL == hv_store (hash, "plugin", 6, newSVpv (vl->plugin, 0), 0))
721 if ('\0' != vl->plugin_instance[0])
722 if (NULL == hv_store (hash, "plugin_instance", 15,
723 newSVpv (vl->plugin_instance, 0), 0))
726 if ('\0' != vl->type[0])
727 if (NULL == hv_store (hash, "type", 4, newSVpv (vl->type, 0), 0))
730 if ('\0' != vl->type_instance[0])
731 if (NULL == hv_store (hash, "type_instance", 13,
732 newSVpv (vl->type_instance, 0), 0))
735 } /* static int value2av (value_list_t *, data_set_t *, HV *) */
737 static int notification_meta2av (pTHX_ notification_meta_t *meta, AV *array)
746 av_extend (array, meta_num);
748 for (int i = 0; NULL != meta; meta = meta->next, ++i) {
752 if (NULL == hv_store (m, "name", 4, newSVpv (meta->name, 0), 0))
755 if (NM_TYPE_STRING == meta->type)
756 value = newSVpv (meta->nm_value.nm_string, 0);
757 else if (NM_TYPE_SIGNED_INT == meta->type)
758 value = newSViv (meta->nm_value.nm_signed_int);
759 else if (NM_TYPE_UNSIGNED_INT == meta->type)
760 value = newSVuv (meta->nm_value.nm_unsigned_int);
761 else if (NM_TYPE_DOUBLE == meta->type)
762 value = newSVnv (meta->nm_value.nm_double);
763 else if (NM_TYPE_BOOLEAN == meta->type)
764 value = meta->nm_value.nm_boolean ? &PL_sv_yes : &PL_sv_no;
768 if (NULL == hv_store (m, "value", 5, value, 0)) {
773 if (NULL == av_store (array, i, newRV_noinc ((SV *)m))) {
780 } /* static int notification_meta2av (notification_meta_t *, AV *) */
782 static int notification2hv (pTHX_ notification_t *n, HV *hash)
784 if (NULL == hv_store (hash, "severity", 8, newSViv (n->severity), 0))
789 double t = CDTIME_T_TO_DOUBLE (n->time);
790 if (NULL == hv_store (hash, "time", 4, newSVnv (t), 0))
794 if ('\0' != *n->message)
795 if (NULL == hv_store (hash, "message", 7, newSVpv (n->message, 0), 0))
798 if ('\0' != *n->host)
799 if (NULL == hv_store (hash, "host", 4, newSVpv (n->host, 0), 0))
802 if ('\0' != *n->plugin)
803 if (NULL == hv_store (hash, "plugin", 6, newSVpv (n->plugin, 0), 0))
806 if ('\0' != *n->plugin_instance)
807 if (NULL == hv_store (hash, "plugin_instance", 15,
808 newSVpv (n->plugin_instance, 0), 0))
811 if ('\0' != *n->type)
812 if (NULL == hv_store (hash, "type", 4, newSVpv (n->type, 0), 0))
815 if ('\0' != *n->type_instance)
816 if (NULL == hv_store (hash, "type_instance", 13,
817 newSVpv (n->type_instance, 0), 0))
820 if (NULL != n->meta) {
822 if ((0 != notification_meta2av (aTHX_ n->meta, meta))
823 || (NULL == hv_store (hash, "meta", 4,
824 newRV_noinc ((SV *)meta), 0))) {
831 } /* static int notification2hv (notification_t *, HV *) */
833 static int oconfig_item2hv (pTHX_ oconfig_item_t *ci, HV *hash)
838 if (NULL == hv_store (hash, "key", 3, newSVpv (ci->key, 0), 0))
842 if (0 < ci->values_num)
843 av_extend (values, ci->values_num);
845 if (NULL == hv_store (hash, "values", 6, newRV_noinc ((SV *)values), 0)) {
851 for (int i = 0; i < ci->values_num; ++i) {
854 switch (ci->values[i].type) {
855 case OCONFIG_TYPE_STRING:
856 value = newSVpv (ci->values[i].value.string, 0);
858 case OCONFIG_TYPE_NUMBER:
859 value = newSVnv ((NV)ci->values[i].value.number);
861 case OCONFIG_TYPE_BOOLEAN:
862 value = ci->values[i].value.boolean ? &PL_sv_yes : &PL_sv_no;
865 log_err ("oconfig_item2hv: Invalid value type %i.",
867 value = &PL_sv_undef;
870 if (NULL == av_store (values, i, value)) {
876 /* ignoring 'parent' member which is uninteresting in this case */
879 if (0 < ci->children_num)
880 av_extend (children, ci->children_num);
882 if (NULL == hv_store (hash, "children", 8, newRV_noinc ((SV *)children), 0)) {
888 for (int i = 0; i < ci->children_num; ++i) {
889 HV *child = newHV ();
891 if (0 != oconfig_item2hv (aTHX_ ci->children + i, child)) {
897 if (NULL == av_store (children, i, newRV_noinc ((SV *)child))) {
904 } /* static int oconfig_item2hv (pTHX_ oconfig_item_t *, HV *) */
907 * Internal functions.
910 static char *get_module_name (char *buf, size_t buf_len, const char *module) {
912 if (base_name[0] == '\0')
913 status = ssnprintf (buf, buf_len, "%s", module);
915 status = ssnprintf (buf, buf_len, "%s::%s", base_name, module);
916 if ((status < 0) || ((unsigned int)status >= buf_len))
919 } /* char *get_module_name */
922 * Add a plugin's data set definition.
924 static int pplugin_register_data_set (pTHX_ char *name, AV *dataset)
930 if ((NULL == name) || (NULL == dataset))
933 if (0 != av2data_set (aTHX_ dataset, name, &ds))
936 ret = plugin_register_data_set (&ds);
940 } /* static int pplugin_register_data_set (char *, SV *) */
943 * Remove a plugin's data set definition.
945 static int pplugin_unregister_data_set (char *name)
949 return plugin_unregister_data_set (name);
950 } /* static int pplugin_unregister_data_set (char *) */
953 * Submit the values to the write functions.
955 static int pplugin_dispatch_values (pTHX_ HV *values)
957 value_list_t vl = VALUE_LIST_INIT;
964 if (0 != hv2value_list (aTHX_ values, &vl))
967 ret = plugin_dispatch_values (&vl);
971 } /* static int pplugin_dispatch_values (char *, HV *) */
974 * Submit the values to a single write function.
976 static int pplugin_write (pTHX_ const char *plugin, AV *data_set, HV *values)
979 value_list_t vl = VALUE_LIST_INIT;
986 if (0 != hv2value_list (aTHX_ values, &vl))
989 if ((NULL != data_set)
990 && (0 != av2data_set (aTHX_ data_set, vl.type, &ds)))
993 ret = plugin_write (plugin, NULL == data_set ? NULL : &ds, &vl);
995 log_warn ("Dispatching value to plugin \"%s\" failed with status %i.",
996 NULL == plugin ? "<any>" : plugin, ret);
998 if (NULL != data_set)
1002 } /* static int pplugin_write (const char *plugin, HV *, HV *) */
1005 * Dispatch a notification.
1007 static int pplugin_dispatch_notification (pTHX_ HV *notif)
1009 notification_t n = { 0 };
1016 if (0 != hv2notification (aTHX_ notif, &n))
1019 ret = plugin_dispatch_notification (&n);
1020 plugin_notification_meta_free (n.meta);
1022 } /* static int pplugin_dispatch_notification (HV *) */
1025 * Call perl sub with thread locking flags handled.
1027 static int call_pv_locked (pTHX_ const char* sub_name)
1032 c_ithread_t *t = (c_ithread_t *)pthread_getspecific(perl_thr_key);
1033 if (t == NULL) /* thread destroyed */
1036 old_running = t->running;
1040 t->running = old_running;
1044 ret = call_pv (sub_name, G_SCALAR|G_EVAL);
1046 t->running = old_running;
1048 } /* static int call_pv_locked (pTHX, *sub_name) */
1051 * Call all working functions of the given type.
1053 static int pplugin_call (pTHX_ int type, ...)
1063 if ((type < 0) || (type >= PLUGIN_TYPES))
1066 va_start (ap, type);
1073 if (PLUGIN_READ == type) {
1074 subname = va_arg(ap, char *);
1076 else if (PLUGIN_WRITE == type) {
1083 subname = va_arg(ap, char *);
1085 * $_[0] = $plugin_type;
1100 * values => [ $v1, ... ],
1102 * host => $hostname,
1103 * plugin => $plugin,
1105 * plugin_instance => $instance,
1106 * type_instance => $type_instance
1109 ds = va_arg (ap, data_set_t *);
1110 vl = va_arg (ap, value_list_t *);
1112 if (-1 == data_set2av (aTHX_ ds, pds)) {
1115 pds = (AV *)&PL_sv_undef;
1119 if (-1 == value_list2hv (aTHX_ vl, ds, pvl)) {
1122 pvl = (HV *)&PL_sv_undef;
1126 XPUSHs (sv_2mortal (newSVpv (ds->type, 0)));
1127 XPUSHs (sv_2mortal (newRV_noinc ((SV *)pds)));
1128 XPUSHs (sv_2mortal (newRV_noinc ((SV *)pvl)));
1130 else if (PLUGIN_LOG == type) {
1131 subname = va_arg(ap, char *);
1137 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
1138 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
1140 else if (PLUGIN_NOTIF == type) {
1142 HV *notif = newHV ();
1144 subname = va_arg(ap, char *);
1148 * severity => $severity,
1152 * plugin => $plugin,
1154 * plugin_instance => $instance,
1155 * type_instance => $type_instance
1158 n = va_arg (ap, notification_t *);
1160 if (-1 == notification2hv (aTHX_ n, notif)) {
1163 notif = (HV *)&PL_sv_undef;
1167 XPUSHs (sv_2mortal (newRV_noinc ((SV *)notif)));
1169 else if (PLUGIN_FLUSH == type) {
1171 subname = va_arg(ap, char *);
1174 * $_[1] = $identifier;
1176 timeout = va_arg (ap, cdtime_t);
1178 XPUSHs (sv_2mortal (newSVnv (CDTIME_T_TO_DOUBLE (timeout))));
1179 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
1181 else if (PLUGIN_INIT == type) {
1182 subname = "Collectd::plugin_call_all";
1183 XPUSHs (sv_2mortal (newSViv ((IV)type)));
1185 else if (PLUGIN_SHUTDOWN == type) {
1186 subname = "Collectd::plugin_call_all";
1187 XPUSHs (sv_2mortal (newSViv ((IV)type)));
1189 else { /* Unknown type. Run 'plugin_call_all' and make compiler happy */
1190 subname = "Collectd::plugin_call_all";
1191 XPUSHs (sv_2mortal (newSViv ((IV)type)));
1196 retvals = call_pv_locked (aTHX_ subname);
1199 if (SvTRUE(ERRSV)) {
1200 if (PLUGIN_LOG != type)
1201 ERROR ("perl: %s error: %s", subname, SvPV_nolen(ERRSV));
1204 else if (0 < retvals) {
1216 } /* static int pplugin_call (int, ...) */
1219 * collectd's Perl interpreter based thread implementation.
1221 * This has been inspired by Perl's ithreads introduced in version 5.6.0.
1224 /* must be called with perl_threads->mutex locked */
1225 static void c_ithread_destroy (c_ithread_t *ithread)
1227 dTHXa (ithread->interp);
1229 assert (NULL != perl_threads);
1231 PERL_SET_CONTEXT (aTHX);
1232 log_debug ("Shutting down Perl interpreter %p...", aTHX);
1237 --perl_threads->number_of_threads;
1238 #endif /* COLLECT_DEBUG */
1240 perl_destruct (aTHX);
1243 if (NULL == ithread->prev)
1244 perl_threads->head = ithread->next;
1246 ithread->prev->next = ithread->next;
1248 if (NULL == ithread->next)
1249 perl_threads->tail = ithread->prev;
1251 ithread->next->prev = ithread->prev;
1255 } /* static void c_ithread_destroy (c_ithread_t *) */
1257 static void c_ithread_destructor (void *arg)
1259 c_ithread_t *ithread = (c_ithread_t *)arg;
1260 c_ithread_t *t = NULL;
1262 if (NULL == perl_threads)
1265 pthread_mutex_lock (&perl_threads->mutex);
1267 for (t = perl_threads->head; NULL != t; t = t->next)
1271 /* the ithread no longer exists */
1274 pthread_mutex_unlock (&perl_threads->mutex);
1278 c_ithread_destroy (ithread);
1280 pthread_mutex_unlock (&perl_threads->mutex);
1282 } /* static void c_ithread_destructor (void *) */
1284 /* must be called with perl_threads->mutex locked */
1285 static c_ithread_t *c_ithread_create (PerlInterpreter *base)
1287 c_ithread_t *t = NULL;
1290 assert (NULL != perl_threads);
1292 t = smalloc (sizeof (*t));
1293 memset (t, 0, sizeof (c_ithread_t));
1295 t->interp = (NULL == base)
1297 : perl_clone (base, CLONEf_KEEP_PTR_TABLE);
1301 if ((NULL != base) && (NULL != PL_endav)) {
1302 av_clear (PL_endav);
1303 av_undef (PL_endav);
1308 ++perl_threads->number_of_threads;
1309 #endif /* COLLECT_DEBUG */
1313 if (NULL == perl_threads->tail) {
1314 perl_threads->head = t;
1318 perl_threads->tail->next = t;
1319 t->prev = perl_threads->tail;
1322 t->pthread = pthread_self();
1325 perl_threads->tail = t;
1327 pthread_setspecific (perl_thr_key, (const void *)t);
1329 } /* static c_ithread_t *c_ithread_create (PerlInterpreter *) */
1332 * Filter chains implementation.
1335 static int fc_call (pTHX_ int type, int cb_type, pfc_user_data_t *data, ...)
1342 notification_meta_t **meta = NULL;
1347 if ((type < 0) || (type >= FC_TYPES))
1350 if ((cb_type < 0) || (cb_type >= FC_CB_TYPES))
1353 va_start (ap, data);
1360 XPUSHs (sv_2mortal (newSViv ((IV)type)));
1361 XPUSHs (sv_2mortal (newSVpv (data->name, 0)));
1362 XPUSHs (sv_2mortal (newSViv ((IV)cb_type)));
1364 if (FC_CB_CREATE == cb_type) {
1367 * $_[1] = $user_data;
1370 HV *config = newHV ();
1372 ci = va_arg (ap, oconfig_item_t *);
1374 if (0 != oconfig_item2hv (aTHX_ ci, config)) {
1377 config = (HV *)&PL_sv_undef;
1381 XPUSHs (sv_2mortal (newRV_noinc ((SV *)config)));
1383 else if (FC_CB_DESTROY == cb_type) {
1385 * $_[1] = $user_data;
1388 /* nothing to be done - the user data pointer
1389 * is pushed onto the stack later */
1391 else if (FC_CB_EXEC == cb_type) {
1396 * $_[3] = $user_data;
1404 ds = va_arg (ap, data_set_t *);
1405 vl = va_arg (ap, value_list_t *);
1406 meta = va_arg (ap, notification_meta_t **);
1408 if (0 != data_set2av (aTHX_ ds, pds)) {
1411 pds = (AV *)&PL_sv_undef;
1415 if (0 != value_list2hv (aTHX_ vl, ds, pvl)) {
1418 pvl = (HV *)&PL_sv_undef;
1425 if (0 != notification_meta2av (aTHX_ *meta, pmeta)) {
1428 pmeta = (AV *)&PL_sv_undef;
1433 pmeta = (AV *)&PL_sv_undef;
1436 XPUSHs (sv_2mortal (newRV_noinc ((SV *)pds)));
1437 XPUSHs (sv_2mortal (newRV_noinc ((SV *)pvl)));
1438 XPUSHs (sv_2mortal (newRV_noinc ((SV *)pmeta)));
1441 XPUSHs (sv_2mortal (newRV_inc (data->user_data)));
1445 retvals = call_pv_locked (aTHX_ "Collectd::fc_call");
1447 if ((FC_CB_EXEC == cb_type) && (meta != NULL)) {
1448 assert (pmeta != NULL);
1450 plugin_notification_meta_free (*meta);
1451 av2notification_meta (aTHX_ pmeta, meta);
1455 if (SvTRUE(ERRSV)) {
1456 ERROR ("perl: Collectd::fc_call error: %s", SvPV_nolen(ERRSV));
1459 else if (0 < retvals) {
1462 /* the exec callbacks return a status, while
1463 * the others return a boolean value */
1464 if (FC_CB_EXEC == cb_type)
1466 else if (! SvTRUE (tmp))
1476 } /* static int fc_call (int, int, pfc_user_data_t *, ...) */
1478 static int fc_create (int type, const oconfig_item_t *ci, void **user_data)
1480 pfc_user_data_t *data;
1486 if (NULL == perl_threads)
1490 c_ithread_t *t = NULL;
1492 pthread_mutex_lock (&perl_threads->mutex);
1493 t = c_ithread_create (perl_threads->head->interp);
1494 pthread_mutex_unlock (&perl_threads->mutex);
1499 log_debug ("fc_create: c_ithread: interp = %p (active threads: %i)",
1500 aTHX, perl_threads->number_of_threads);
1502 if ((1 != ci->values_num)
1503 || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
1504 log_warn ("A \"%s\" block expects a single string argument.",
1505 (FC_MATCH == type) ? "Match" : "Target");
1509 data = smalloc (sizeof (*data));
1510 data->name = sstrdup (ci->values[0].value.string);
1511 data->user_data = newSV (0);
1513 ret = fc_call (aTHX_ type, FC_CB_CREATE, data, ci);
1516 PFC_USER_DATA_FREE (data);
1520 } /* static int fc_create (int, const oconfig_item_t *, void **) */
1522 static int fc_destroy (int type, void **user_data)
1524 pfc_user_data_t *data = *(pfc_user_data_t **)user_data;
1530 if ((NULL == perl_threads) || (NULL == data))
1534 c_ithread_t *t = NULL;
1536 pthread_mutex_lock (&perl_threads->mutex);
1537 t = c_ithread_create (perl_threads->head->interp);
1538 pthread_mutex_unlock (&perl_threads->mutex);
1543 log_debug ("fc_destroy: c_ithread: interp = %p (active threads: %i)",
1544 aTHX, perl_threads->number_of_threads);
1546 ret = fc_call (aTHX_ type, FC_CB_DESTROY, data);
1548 PFC_USER_DATA_FREE (data);
1551 } /* static int fc_destroy (int, void **) */
1553 static int fc_exec (int type, const data_set_t *ds, const value_list_t *vl,
1554 notification_meta_t **meta, void **user_data)
1556 pfc_user_data_t *data = *(pfc_user_data_t **)user_data;
1560 if (NULL == perl_threads)
1563 assert (NULL != data);
1566 c_ithread_t *t = NULL;
1568 pthread_mutex_lock (&perl_threads->mutex);
1569 t = c_ithread_create (perl_threads->head->interp);
1570 pthread_mutex_unlock (&perl_threads->mutex);
1575 log_debug ("fc_exec: c_ithread: interp = %p (active threads: %i)",
1576 aTHX, perl_threads->number_of_threads);
1578 return fc_call (aTHX_ type, FC_CB_EXEC, data, ds, vl, meta);
1579 } /* static int fc_exec (int, const data_set_t *, const value_list_t *,
1580 notification_meta_t **, void **) */
1582 static int pmatch_create (const oconfig_item_t *ci, void **user_data)
1584 return fc_create (FC_MATCH, ci, user_data);
1585 } /* static int pmatch_create (const oconfig_item_t *, void **) */
1587 static int pmatch_destroy (void **user_data)
1589 return fc_destroy (FC_MATCH, user_data);
1590 } /* static int pmatch_destroy (void **) */
1592 static int pmatch_match (const data_set_t *ds, const value_list_t *vl,
1593 notification_meta_t **meta, void **user_data)
1595 return fc_exec (FC_MATCH, ds, vl, meta, user_data);
1596 } /* static int pmatch_match (const data_set_t *, const value_list_t *,
1597 notification_meta_t **, void **) */
1599 static match_proc_t pmatch = {
1600 pmatch_create, pmatch_destroy, pmatch_match
1603 static int ptarget_create (const oconfig_item_t *ci, void **user_data)
1605 return fc_create (FC_TARGET, ci, user_data);
1606 } /* static int ptarget_create (const oconfig_item_t *, void **) */
1608 static int ptarget_destroy (void **user_data)
1610 return fc_destroy (FC_TARGET, user_data);
1611 } /* static int ptarget_destroy (void **) */
1613 static int ptarget_invoke (const data_set_t *ds, value_list_t *vl,
1614 notification_meta_t **meta, void **user_data)
1616 return fc_exec (FC_TARGET, ds, vl, meta, user_data);
1617 } /* static int ptarget_invoke (const data_set_t *, value_list_t *,
1618 notification_meta_t **, void **) */
1620 static target_proc_t ptarget = {
1621 ptarget_create, ptarget_destroy, ptarget_invoke
1625 * Exported Perl API.
1628 static void _plugin_register_generic_userdata (pTHX, int type, const char *desc)
1631 user_data_t userdata;
1637 log_err ("Usage: Collectd::plugin_register_%s(pluginname, subname)",
1642 if (! SvOK (ST (0))) {
1643 log_err ("Collectd::plugin_register_%s(pluginname, subname): "
1644 "Invalid pluginname", desc);
1647 if (! SvOK (ST (1))) {
1648 log_err ("Collectd::plugin_register_%s(pluginname, subname): "
1649 "Invalid subname", desc);
1653 /* Use pluginname as-is to allow flush a single perl plugin */
1654 pluginname = SvPV_nolen (ST (0));
1656 log_debug ("Collectd::plugin_register_%s: "
1657 "plugin = \"%s\", sub = \"%s\"",
1658 desc, pluginname, SvPV_nolen (ST (1)));
1660 memset(&userdata, 0, sizeof(userdata));
1661 userdata.data = strdup(SvPV_nolen (ST (1)));
1662 userdata.free_func = free;
1664 if (PLUGIN_READ == type) {
1665 ret = plugin_register_complex_read(
1669 plugin_get_interval(), /* Default interval */
1672 else if (PLUGIN_WRITE == type) {
1673 ret = plugin_register_write(pluginname, perl_write, &userdata);
1675 else if (PLUGIN_LOG == type) {
1676 ret = plugin_register_log(pluginname, perl_log, &userdata);
1678 else if (PLUGIN_NOTIF == type) {
1679 ret = plugin_register_notification(pluginname, perl_notify, &userdata);
1681 else if (PLUGIN_FLUSH == type) {
1682 ret = plugin_register_flush(pluginname, perl_flush, &userdata);
1691 free (userdata.data);
1694 } /* static void _plugin_register_generic_userdata ( ... ) */
1697 * Collectd::plugin_register_TYPE (pluginname, subname).
1700 * name of the perl plugin
1703 * name of the plugin's subroutine that does the work
1706 static XS (Collectd_plugin_register_read) {
1707 return _plugin_register_generic_userdata(aTHX, PLUGIN_READ, "read");
1710 static XS (Collectd_plugin_register_write) {
1711 return _plugin_register_generic_userdata(aTHX, PLUGIN_WRITE, "write");
1714 static XS (Collectd_plugin_register_log) {
1715 return _plugin_register_generic_userdata(aTHX, PLUGIN_LOG, "log");
1718 static XS (Collectd_plugin_register_notification) {
1719 return _plugin_register_generic_userdata(aTHX, PLUGIN_NOTIF, "notification");
1722 static XS (Collectd_plugin_register_flush) {
1723 return _plugin_register_generic_userdata(aTHX, PLUGIN_FLUSH, "flush");
1726 typedef int perl_unregister_function_t(const char *name);
1728 static void _plugin_unregister_generic (pTHX,
1729 perl_unregister_function_t *unreg, const char *desc)
1731 char cb_name[DATA_MAX_NAME_LEN];
1736 log_err ("Usage: Collectd::plugin_unregister_%s(pluginname)", desc);
1740 if (! SvOK (ST (0))) {
1741 log_err ("Collectd::plugin_unregister_%s(pluginname): "
1742 "Invalid pluginname", desc);
1746 log_debug ("Collectd::plugin_unregister_%s: plugin = \"%s\"",
1747 desc, SvPV_nolen (ST (0)));
1749 ssnprintf (cb_name, sizeof (cb_name), "perl/%s", SvPV_nolen (ST (0)));
1756 } /* static void _plugin_unregister_generic ( ... ) */
1759 * Collectd::plugin_unregister_TYPE (pluginname).
1762 * type of callback to be unregistered: read, write, log, notification, flush
1765 * name of the perl plugin
1768 static XS (Collectd_plugin_unregister_read) {
1769 return _plugin_unregister_generic(aTHX,
1770 plugin_unregister_read, "read");
1773 static XS (Collectd_plugin_unregister_write) {
1774 return _plugin_unregister_generic(aTHX,
1775 plugin_unregister_write, "write");
1778 static XS (Collectd_plugin_unregister_log) {
1779 return _plugin_unregister_generic(aTHX,
1780 plugin_unregister_log, "log");
1783 static XS (Collectd_plugin_unregister_notification) {
1784 return _plugin_unregister_generic(aTHX,
1785 plugin_unregister_notification, "notification");
1788 static XS (Collectd_plugin_unregister_flush) {
1789 return _plugin_unregister_generic(aTHX,
1790 plugin_unregister_flush, "flush");
1794 * Collectd::plugin_register_data_set (type, dataset).
1797 * type of the dataset
1800 * dataset to be registered
1802 static XS (Collectd_plugin_register_ds)
1809 log_warn ("Using plugin_register() to register new data-sets is "
1810 "deprecated - add new entries to a custom types.db instead.");
1813 log_err ("Usage: Collectd::plugin_register_data_set(type, dataset)");
1817 log_debug ("Collectd::plugin_register_data_set: "
1818 "type = \"%s\", dataset = \"%s\"",
1819 SvPV_nolen (ST (0)), SvPV_nolen (ST (1)));
1823 if (SvROK (data) && (SVt_PVAV == SvTYPE (SvRV (data)))) {
1824 ret = pplugin_register_data_set (aTHX_ SvPV_nolen (ST (0)),
1828 log_err ("Collectd::plugin_register_data_set: Invalid data.");
1836 } /* static XS (Collectd_plugin_register_ds) */
1839 * Collectd::plugin_unregister_data_set (type).
1842 * type of the dataset
1844 static XS (Collectd_plugin_unregister_ds)
1849 log_err ("Usage: Collectd::plugin_unregister_data_set(type)");
1853 log_debug ("Collectd::plugin_unregister_data_set: type = \"%s\"",
1854 SvPV_nolen (ST (0)));
1856 if (0 == pplugin_unregister_data_set (SvPV_nolen (ST (0))))
1860 } /* static XS (Collectd_plugin_register_ds) */
1863 * Collectd::plugin_dispatch_values (name, values).
1866 * name of the plugin
1869 * value list to submit
1871 static XS (Collectd_plugin_dispatch_values)
1880 log_err ("Usage: Collectd::plugin_dispatch_values(values)");
1884 log_debug ("Collectd::plugin_dispatch_values: values=\"%s\"",
1885 SvPV_nolen (ST (/* stack index = */ 0)));
1887 values = ST (/* stack index = */ 0);
1892 /* Make sure the argument is a hash reference. */
1893 if (! (SvROK (values) && (SVt_PVHV == SvTYPE (SvRV (values))))) {
1894 log_err ("Collectd::plugin_dispatch_values: Invalid values.");
1898 ret = pplugin_dispatch_values (aTHX_ (HV *)SvRV (values));
1904 } /* static XS (Collectd_plugin_dispatch_values) */
1907 * Collectd::plugin_get_interval ().
1909 static XS (Collectd_plugin_get_interval)
1913 /* make sure we don't get any unused variable warnings for 'items';
1914 * don't abort, though */
1916 log_err ("Usage: Collectd::plugin_get_interval()");
1918 XSRETURN_NV ((NV) CDTIME_T_TO_DOUBLE (plugin_get_interval ()));
1919 } /* static XS (Collectd_plugin_get_interval) */
1921 /* Collectd::plugin_write (plugin, ds, vl).
1924 * name of the plugin to call, may be 'undef'
1927 * data-set that describes the submitted values, may be 'undef'
1930 * value-list to be written
1932 static XS (Collectd__plugin_write)
1943 log_err ("Usage: Collectd::plugin_write(plugin, ds, vl)");
1947 log_debug ("Collectd::plugin_write: plugin=\"%s\", ds=\"%s\", vl=\"%s\"",
1948 SvPV_nolen (ST (0)), SvOK (ST (1)) ? SvPV_nolen (ST (1)) : "",
1949 SvPV_nolen (ST (2)));
1951 if (! SvOK (ST (0)))
1954 plugin = SvPV_nolen (ST (0));
1957 if (SvROK (ds) && (SVt_PVAV == SvTYPE (SvRV (ds))))
1958 ds_array = (AV *)SvRV (ds);
1959 else if (! SvOK (ds))
1962 log_err ("Collectd::plugin_write: Invalid data-set.");
1967 if (! (SvROK (vl) && (SVt_PVHV == SvTYPE (SvRV (vl))))) {
1968 log_err ("Collectd::plugin_write: Invalid value-list.");
1972 ret = pplugin_write (aTHX_ plugin, ds_array, (HV *)SvRV (vl));
1978 } /* static XS (Collectd__plugin_write) */
1981 * Collectd::_plugin_flush (plugin, timeout, identifier).
1984 * name of the plugin to flush
1987 * timeout to use when flushing the data
1990 * data-set identifier to flush
1992 static XS (Collectd__plugin_flush)
1994 char *plugin = NULL;
2001 log_err ("Usage: Collectd::_plugin_flush(plugin, timeout, id)");
2006 plugin = SvPV_nolen (ST (0));
2009 timeout = (int)SvIV (ST (1));
2012 id = SvPV_nolen (ST (2));
2014 log_debug ("Collectd::_plugin_flush: plugin = \"%s\", timeout = %i, "
2015 "id = \"%s\"", plugin, timeout, id);
2017 if (0 == plugin_flush (plugin, timeout, id))
2021 } /* static XS (Collectd__plugin_flush) */
2024 * Collectd::plugin_dispatch_notification (notif).
2027 * notification to dispatch
2029 static XS (Collectd_plugin_dispatch_notification)
2038 log_err ("Usage: Collectd::plugin_dispatch_notification(notif)");
2042 log_debug ("Collectd::plugin_dispatch_notification: notif = \"%s\"",
2043 SvPV_nolen (ST (0)));
2047 if (! (SvROK (notif) && (SVt_PVHV == SvTYPE (SvRV (notif))))) {
2048 log_err ("Collectd::plugin_dispatch_notification: Invalid notif.");
2052 ret = pplugin_dispatch_notification (aTHX_ (HV *)SvRV (notif));
2058 } /* static XS (Collectd_plugin_dispatch_notification) */
2061 * Collectd::plugin_log (level, message).
2064 * log level (LOG_DEBUG, ... LOG_ERR)
2069 static XS (Collectd_plugin_log)
2074 log_err ("Usage: Collectd::plugin_log(level, message)");
2078 plugin_log (SvIV (ST (0)), "%s", SvPV_nolen (ST (1)));
2080 } /* static XS (Collectd_plugin_log) */
2083 * Collectd::_fc_register (type, name)
2091 static XS (Collectd__fc_register)
2101 log_err ("Usage: Collectd::_fc_register(type, name)");
2105 type = SvIV (ST (0));
2106 name = SvPV_nolen (ST (1));
2108 if (FC_MATCH == type)
2109 ret = fc_register_match (name, pmatch);
2110 else if (FC_TARGET == type)
2111 ret = fc_register_target (name, ptarget);
2117 } /* static XS (Collectd_fc_register) */
2120 * Collectd::call_by_name (...).
2122 * Call a Perl sub identified by its name passed through $Collectd::cb_name.
2124 static XS (Collectd_call_by_name)
2129 if (NULL == (tmp = get_sv ("Collectd::cb_name", 0))) {
2130 sv_setpv (get_sv ("@", 1), "cb_name has not been set");
2135 name = SvPV_nolen (tmp);
2137 if (NULL == get_cv (name, 0)) {
2138 sv_setpvf (get_sv ("@", 1), "unknown callback \"%s\"", name);
2143 /* simply pass on the subroutine call without touching the stack,
2144 * thus leaving any arguments and return values in place */
2146 } /* static XS (Collectd_call_by_name) */
2149 * Interface to collectd.
2152 static int perl_init (void)
2157 if (NULL == perl_threads)
2161 c_ithread_t *t = NULL;
2163 pthread_mutex_lock (&perl_threads->mutex);
2164 t = c_ithread_create (perl_threads->head->interp);
2165 pthread_mutex_unlock (&perl_threads->mutex);
2170 log_debug ("perl_init: c_ithread: interp = %p (active threads: %i)",
2171 aTHX, perl_threads->number_of_threads);
2173 /* Lock the base thread to avoid race conditions with c_ithread_create().
2174 * See https://github.com/collectd/collectd/issues/9 and
2175 * https://github.com/collectd/collectd/issues/1706 for details.
2177 assert (aTHX == perl_threads->head->interp);
2178 pthread_mutex_lock (&perl_threads->mutex);
2180 status = pplugin_call (aTHX_ PLUGIN_INIT);
2182 pthread_mutex_unlock (&perl_threads->mutex);
2185 } /* static int perl_init (void) */
2187 static int perl_read (user_data_t *user_data)
2191 if (NULL == perl_threads)
2195 c_ithread_t *t = NULL;
2197 pthread_mutex_lock (&perl_threads->mutex);
2198 t = c_ithread_create (perl_threads->head->interp);
2199 pthread_mutex_unlock (&perl_threads->mutex);
2204 /* Assert that we're not running as the base thread. Otherwise, we might
2205 * run into concurrency issues with c_ithread_create(). See
2206 * https://github.com/collectd/collectd/issues/9 for details. */
2207 assert (aTHX != perl_threads->head->interp);
2209 log_debug ("perl_read: c_ithread: interp = %p (active threads: %i)",
2210 aTHX, perl_threads->number_of_threads);
2212 return pplugin_call (aTHX_ PLUGIN_READ, user_data->data);
2213 } /* static int perl_read (user_data_t *user_data) */
2215 static int perl_write (const data_set_t *ds, const value_list_t *vl,
2216 user_data_t *user_data)
2221 if (NULL == perl_threads)
2225 c_ithread_t *t = NULL;
2227 pthread_mutex_lock (&perl_threads->mutex);
2228 t = c_ithread_create (perl_threads->head->interp);
2229 pthread_mutex_unlock (&perl_threads->mutex);
2234 /* Lock the base thread if this is not called from one of the read threads
2235 * to avoid race conditions with c_ithread_create(). See
2236 * https://github.com/collectd/collectd/issues/9 for details. */
2237 if (aTHX == perl_threads->head->interp)
2238 pthread_mutex_lock (&perl_threads->mutex);
2240 log_debug ("perl_write: c_ithread: interp = %p (active threads: %i)",
2241 aTHX, perl_threads->number_of_threads);
2242 status = pplugin_call (aTHX_ PLUGIN_WRITE, user_data->data, ds, vl);
2244 if (aTHX == perl_threads->head->interp)
2245 pthread_mutex_unlock (&perl_threads->mutex);
2248 } /* static int perl_write (const data_set_t *, const value_list_t *) */
2250 static void perl_log (int level, const char *msg,
2251 user_data_t *user_data)
2255 if (NULL == perl_threads)
2259 c_ithread_t *t = NULL;
2261 pthread_mutex_lock (&perl_threads->mutex);
2262 t = c_ithread_create (perl_threads->head->interp);
2263 pthread_mutex_unlock (&perl_threads->mutex);
2268 /* Lock the base thread if this is not called from one of the read threads
2269 * to avoid race conditions with c_ithread_create(). See
2270 * https://github.com/collectd/collectd/issues/9 for details.
2273 if (aTHX == perl_threads->head->interp)
2274 pthread_mutex_lock (&perl_threads->mutex);
2276 pplugin_call (aTHX_ PLUGIN_LOG, user_data->data, level, msg);
2278 if (aTHX == perl_threads->head->interp)
2279 pthread_mutex_unlock (&perl_threads->mutex);
2282 } /* static void perl_log (int, const char *) */
2284 static int perl_notify (const notification_t *notif, user_data_t *user_data)
2288 if (NULL == perl_threads)
2292 c_ithread_t *t = NULL;
2294 pthread_mutex_lock (&perl_threads->mutex);
2295 t = c_ithread_create (perl_threads->head->interp);
2296 pthread_mutex_unlock (&perl_threads->mutex);
2300 return pplugin_call (aTHX_ PLUGIN_NOTIF, user_data->data, notif);
2301 } /* static int perl_notify (const notification_t *) */
2303 static int perl_flush (cdtime_t timeout, const char *identifier,
2304 user_data_t *user_data)
2308 if (NULL == perl_threads)
2312 c_ithread_t *t = NULL;
2314 pthread_mutex_lock (&perl_threads->mutex);
2315 t = c_ithread_create (perl_threads->head->interp);
2316 pthread_mutex_unlock (&perl_threads->mutex);
2320 return pplugin_call (aTHX_ PLUGIN_FLUSH, user_data->data, timeout, identifier);
2321 } /* static int perl_flush (const int) */
2323 static int perl_shutdown (void)
2330 plugin_unregister_complex_config ("perl");
2331 plugin_unregister_read_group ("perl");
2333 if (NULL == perl_threads)
2337 pthread_mutex_lock (&perl_threads->mutex);
2338 t = c_ithread_create (perl_threads->head->interp);
2339 pthread_mutex_unlock (&perl_threads->mutex);
2344 log_debug ("perl_shutdown: c_ithread: interp = %p (active threads: %i)",
2345 aTHX, perl_threads->number_of_threads);
2347 plugin_unregister_init ("perl");
2349 ret = pplugin_call (aTHX_ PLUGIN_SHUTDOWN);
2351 pthread_mutex_lock (&perl_threads->mutex);
2352 t = perl_threads->tail;
2355 struct timespec ts_wait;
2356 c_ithread_t *thr = t;
2358 /* the pointer has to be advanced before destroying
2359 * the thread as this will free the memory */
2364 /* Give some time to thread to exit from Perl interpreter */
2365 WARNING ("perl shutdown: Thread is running inside Perl. Waiting.");
2367 ts_wait.tv_nsec = 500000;
2368 nanosleep (&ts_wait, NULL);
2371 pthread_kill (thr->pthread, SIGTERM);
2372 ERROR ("perl shutdown: Thread hangs inside Perl. Thread killed.");
2374 /* Mark as running to avoid deadlock:
2375 c_ithread_destroy -> log_debug -> perl_log()
2378 c_ithread_destroy (thr);
2381 pthread_mutex_unlock (&perl_threads->mutex);
2382 pthread_mutex_destroy (&perl_threads->mutex);
2383 pthread_mutexattr_destroy (&perl_threads->mutexattr);
2385 sfree (perl_threads);
2387 pthread_key_delete (perl_thr_key);
2391 plugin_unregister_shutdown ("perl");
2393 } /* static void perl_shutdown (void) */
2396 * Access functions for global variables.
2398 * These functions implement the "magic" used to access
2399 * the global variables from Perl.
2402 static int g_pv_get (pTHX_ SV *var, MAGIC *mg)
2404 char *pv = mg->mg_ptr;
2407 } /* static int g_pv_get (pTHX_ SV *, MAGIC *) */
2409 static int g_pv_set (pTHX_ SV *var, MAGIC *mg)
2411 char *pv = mg->mg_ptr;
2412 sstrncpy (pv, SvPV_nolen (var), DATA_MAX_NAME_LEN);
2414 } /* static int g_pv_set (pTHX_ SV *, MAGIC *) */
2416 static int g_interval_get (pTHX_ SV *var, MAGIC *mg)
2418 log_warn ("Accessing $interval_g is deprecated (and might not "
2419 "give the desired results) - plugin_get_interval() should "
2420 "be used instead.");
2421 sv_setnv (var, CDTIME_T_TO_DOUBLE (interval_g));
2423 } /* static int g_interval_get (pTHX_ SV *, MAGIC *) */
2425 static int g_interval_set (pTHX_ SV *var, MAGIC *mg)
2427 double nv = (double)SvNV (var);
2428 log_warn ("Accessing $interval_g is deprecated (and might not "
2429 "give the desired results) - plugin_get_interval() should "
2430 "be used instead.");
2431 interval_g = DOUBLE_TO_CDTIME_T (nv);
2433 } /* static int g_interval_set (pTHX_ SV *, MAGIC *) */
2435 static MGVTBL g_pv_vtbl = {
2436 g_pv_get, g_pv_set, NULL, NULL, NULL, NULL, NULL
2437 #if HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL
2441 static MGVTBL g_interval_vtbl = {
2442 g_interval_get, g_interval_set, NULL, NULL, NULL, NULL, NULL
2443 #if HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL
2448 /* bootstrap the Collectd module */
2449 static void xs_init (pTHX)
2453 char *file = __FILE__;
2457 /* enable usage of Perl modules using shared libraries */
2458 newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
2461 for (int i = 0; NULL != api[i].f; ++i)
2462 newXS (api[i].name, api[i].f, file);
2464 stash = gv_stashpv ("Collectd", 1);
2466 /* export "constants" */
2467 for (int i = 0; '\0' != constants[i].name[0]; ++i)
2468 newCONSTSUB (stash, constants[i].name, newSViv (constants[i].value));
2470 /* export global variables
2471 * by adding "magic" to the SV's representing the globale variables
2472 * perl is able to automagically call the get/set function when
2473 * accessing any such variable (this is basically the same as using
2475 /* global strings */
2476 for (int i = 0; '\0' != g_strings[i].name[0]; ++i) {
2477 tmp = get_sv (g_strings[i].name, 1);
2478 sv_magicext (tmp, NULL, PERL_MAGIC_ext, &g_pv_vtbl,
2479 g_strings[i].var, 0);
2482 tmp = get_sv ("Collectd::interval_g", /* create = */ 1);
2483 sv_magicext (tmp, NULL, /* how = */ PERL_MAGIC_ext,
2484 /* vtbl = */ &g_interval_vtbl,
2485 /* name = */ NULL, /* namelen = */ 0);
2488 } /* static void xs_init (pTHX) */
2490 /* Initialize the global Perl interpreter. */
2491 static int init_pi (int argc, char **argv)
2495 if (NULL != perl_threads)
2498 log_info ("Initializing Perl interpreter...");
2501 for (int i = 0; i < argc; ++i)
2502 log_debug ("argv[%i] = \"%s\"", i, argv[i]);
2504 #endif /* COLLECT_DEBUG */
2506 if (0 != pthread_key_create (&perl_thr_key, c_ithread_destructor)) {
2507 log_err ("init_pi: pthread_key_create failed");
2509 /* this must not happen - cowardly giving up if it does */
2514 /* On FreeBSD, PERL_SYS_INIT3 expands to some expression which
2515 * triggers a "value computed is not used" warning by gcc. */
2518 PERL_SYS_INIT3 (&argc, &argv, &environ);
2520 perl_threads = smalloc (sizeof (*perl_threads));
2521 memset (perl_threads, 0, sizeof (c_ithread_list_t));
2523 pthread_mutexattr_init(&perl_threads->mutexattr);
2524 pthread_mutexattr_settype(&perl_threads->mutexattr, PTHREAD_MUTEX_RECURSIVE);
2525 pthread_mutex_init (&perl_threads->mutex, &perl_threads->mutexattr);
2526 /* locking the mutex should not be necessary at this point
2527 * but let's just do it for the sake of completeness */
2528 pthread_mutex_lock (&perl_threads->mutex);
2530 perl_threads->head = c_ithread_create (NULL);
2531 perl_threads->tail = perl_threads->head;
2533 if (NULL == (perl_threads->head->interp = perl_alloc ())) {
2534 log_err ("init_pi: Not enough memory.");
2538 aTHX = perl_threads->head->interp;
2539 pthread_mutex_unlock (&perl_threads->mutex);
2541 perl_construct (aTHX);
2543 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
2545 if (0 != perl_parse (aTHX_ xs_init, argc, argv, NULL)) {
2546 SV *err = get_sv ("@", 1);
2547 log_err ("init_pi: Unable to bootstrap Collectd: %s",
2550 perl_destruct (perl_threads->head->interp);
2551 perl_free (perl_threads->head->interp);
2552 sfree (perl_threads);
2554 pthread_key_delete (perl_thr_key);
2558 /* Set $0 to "collectd" because perl_parse() has to set it to "-e". */
2559 sv_setpv (get_sv ("0", 0), "collectd");
2563 plugin_register_init ("perl", perl_init);
2564 plugin_register_shutdown ("perl", perl_shutdown);
2566 } /* static int init_pi (const char **, const int) */
2569 * LoadPlugin "<Plugin>"
2571 static int perl_config_loadplugin (pTHX_ oconfig_item_t *ci)
2573 char module_name[DATA_MAX_NAME_LEN];
2577 if ((0 != ci->children_num) || (1 != ci->values_num)
2578 || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2579 log_err ("LoadPlugin expects a single string argument.");
2583 value = ci->values[0].value.string;
2585 if (NULL == get_module_name (module_name, sizeof (module_name), value)) {
2586 log_err ("Invalid module name %s", value);
2590 if (0 != init_pi (perl_argc, perl_argv))
2593 assert (NULL != perl_threads);
2594 assert (NULL != perl_threads->head);
2596 aTHX = perl_threads->head->interp;
2598 log_debug ("perl_config: Loading Perl plugin \"%s\"", value);
2599 load_module (PERL_LOADMOD_NOIMPORT,
2600 newSVpv (module_name, strlen (module_name)), Nullsv);
2602 } /* static int perl_config_loadplugin (oconfig_item_it *) */
2607 static int perl_config_basename (pTHX_ oconfig_item_t *ci)
2611 if ((0 != ci->children_num) || (1 != ci->values_num)
2612 || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2613 log_err ("BaseName expects a single string argument.");
2617 value = ci->values[0].value.string;
2619 log_debug ("perl_config: Setting plugin basename to \"%s\"", value);
2620 sstrncpy (base_name, value, sizeof (base_name));
2622 } /* static int perl_config_basename (oconfig_item_it *) */
2625 * EnableDebugger "<Package>"|""
2627 static int perl_config_enabledebugger (pTHX_ oconfig_item_t *ci)
2631 if ((0 != ci->children_num) || (1 != ci->values_num)
2632 || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2633 log_err ("EnableDebugger expects a single string argument.");
2637 if (NULL != perl_threads) {
2638 log_warn ("EnableDebugger has no effects if used after LoadPlugin.");
2642 value = ci->values[0].value.string;
2644 perl_argv = realloc (perl_argv,
2645 (++perl_argc + 1) * sizeof (char *));
2647 if (NULL == perl_argv) {
2648 log_err ("perl_config: Not enough memory.");
2652 if ('\0' == value[0]) {
2653 perl_argv[perl_argc - 1] = "-d";
2656 perl_argv[perl_argc - 1] = smalloc (strlen (value) + 4);
2657 sstrncpy (perl_argv[perl_argc - 1], "-d:", 4);
2658 sstrncpy (perl_argv[perl_argc - 1] + 3, value, strlen (value) + 1);
2661 perl_argv[perl_argc] = NULL;
2663 } /* static int perl_config_enabledebugger (oconfig_item_it *) */
2666 * IncludeDir "<Dir>"
2668 static int perl_config_includedir (pTHX_ oconfig_item_t *ci)
2672 if ((0 != ci->children_num) || (1 != ci->values_num)
2673 || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2674 log_err ("IncludeDir expects a single string argument.");
2678 value = ci->values[0].value.string;
2681 perl_argv = realloc (perl_argv,
2682 (++perl_argc + 1) * sizeof (char *));
2684 if (NULL == perl_argv) {
2685 log_err ("perl_config: Not enough memory.");
2689 perl_argv[perl_argc - 1] = smalloc (strlen (value) + 3);
2690 sstrncpy(perl_argv[perl_argc - 1], "-I", 3);
2691 sstrncpy(perl_argv[perl_argc - 1] + 2, value, strlen (value) + 1);
2693 perl_argv[perl_argc] = NULL;
2696 /* prepend the directory to @INC */
2697 av_unshift (GvAVn (PL_incgv), 1);
2698 av_store (GvAVn (PL_incgv), 0, newSVpv (value, strlen (value)));
2701 } /* static int perl_config_includedir (oconfig_item_it *) */
2706 static int perl_config_plugin (pTHX_ oconfig_item_t *ci)
2716 if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
2717 log_err ("LoadPlugin expects a single string argument.");
2721 plugin = ci->values[0].value.string;
2724 if (0 != oconfig_item2hv (aTHX_ ci, config)) {
2728 log_err ("Unable to convert configuration to a Perl hash value.");
2729 config = (HV *)&PL_sv_undef;
2737 XPUSHs (sv_2mortal (newSVpv (plugin, 0)));
2738 XPUSHs (sv_2mortal (newRV_noinc ((SV *)config)));
2742 retvals = call_pv ("Collectd::_plugin_dispatch_config", G_SCALAR);
2757 } /* static int perl_config_plugin (oconfig_item_it *) */
2759 static int perl_config (oconfig_item_t *ci)
2765 for (int i = 0; i < ci->children_num; ++i) {
2766 oconfig_item_t *c = ci->children + i;
2767 int current_status = 0;
2769 if (NULL != perl_threads)
2771 if ((aTHX = PERL_GET_CONTEXT) == NULL)
2775 if (0 == strcasecmp (c->key, "LoadPlugin"))
2776 current_status = perl_config_loadplugin (aTHX_ c);
2777 else if (0 == strcasecmp (c->key, "BaseName"))
2778 current_status = perl_config_basename (aTHX_ c);
2779 else if (0 == strcasecmp (c->key, "EnableDebugger"))
2780 current_status = perl_config_enabledebugger (aTHX_ c);
2781 else if (0 == strcasecmp (c->key, "IncludeDir"))
2782 current_status = perl_config_includedir (aTHX_ c);
2783 else if (0 == strcasecmp (c->key, "Plugin"))
2784 current_status = perl_config_plugin (aTHX_ c);
2787 log_warn ("Ignoring unknown config key \"%s\".", c->key);
2791 /* fatal error - it's up to perl_config_* to clean up */
2792 if (0 > current_status) {
2793 log_err ("Configuration failed with a fatal error - "
2794 "plugin disabled!");
2795 return current_status;
2798 status += current_status;
2801 } /* static int perl_config (oconfig_item_t *) */
2803 void module_register (void)
2806 perl_argv = smalloc ((perl_argc + 1) * sizeof (*perl_argv));
2808 /* default options for the Perl interpreter */
2810 perl_argv[1] = "-MCollectd";
2811 perl_argv[2] = "-e";
2813 perl_argv[4] = NULL;
2815 plugin_register_complex_config ("perl", perl_config);
2817 } /* void module_register (void) */
2819 /* vim: set sw=4 ts=4 tw=78 noexpandtab : */