typedef struct c_ithread_s {
/* the thread's Perl interpreter */
PerlInterpreter *interp;
- _Bool running; /* thread is inside Perl interpreter */
- _Bool shutdown;
+ bool running; /* thread is inside Perl interpreter */
+ bool shutdown;
pthread_t pthread;
/* double linked list of threads */
* private variables
*/
-static _Bool register_legacy_flush = 1;
+static bool register_legacy_flush = true;
/* if perl_threads != NULL perl_threads->head must
* point to the "base" thread */
-static c_ithread_list_t *perl_threads = NULL;
+static c_ithread_list_t *perl_threads;
/* the key used to store each pthread's ithread */
static pthread_key_t perl_thr_key;
-static int perl_argc = 0;
-static char **perl_argv = NULL;
+static int perl_argc;
+static char **perl_argv;
static char base_name[DATA_MAX_NAME_LEN] = "";
{"Collectd::NOTIF_WARNING", NOTIF_WARNING},
{"Collectd::NOTIF_OKAY", NOTIF_OKAY},
{"", 0}};
-
-struct {
- char name[64];
- char *var;
-} g_strings[] = {{"Collectd::hostname_g", hostname_g}, {"", NULL}};
-
/*
* Helper functions for data type conversion.
*/
if (array_len < ds->ds_num) {
log_warn("av2value: array does not contain enough elements for type "
- "\"%s\": got %zu, want %zu",
+ "\"%s\": got %" PRIsz ", want %" PRIsz,
name, array_len, ds->ds_num);
return 0;
} else if (array_len > ds->ds_num) {
log_warn("av2value: array contains excess elements for type \"%s\": got "
- "%zu, want %zu",
+ "%" PRIsz ", want %" PRIsz,
name, array_len, ds->ds_num);
}
static int notification_meta2av(pTHX_ notification_meta_t *meta, AV *array) {
int meta_num = 0;
-
- while (meta) {
+ for (notification_meta_t *m = meta; m != NULL; m = m->next) {
++meta_num;
- meta = meta->next;
}
av_extend(array, meta_num);
* Call perl sub with thread locking flags handled.
*/
static int call_pv_locked(pTHX_ const char *sub_name) {
- _Bool old_running;
+ bool old_running;
int ret;
c_ithread_t *t = (c_ithread_t *)pthread_getspecific(perl_thr_key);
return 0;
old_running = t->running;
- t->running = 1;
+ t->running = true;
if (t->shutdown) {
t->running = old_running;
/* Mark as running to avoid deadlock:
c_ithread_destroy -> log_debug -> perl_log()
*/
- ithread->running = 1;
+ ithread->running = true;
log_debug("Shutting down Perl interpreter %p...", aTHX);
#if COLLECT_DEBUG
}
t->pthread = pthread_self();
- t->running = 0;
- t->shutdown = 0;
+ t->running = false;
+ t->shutdown = false;
perl_threads->tail = t;
pthread_setspecific(perl_thr_key, (const void *)t);
*/
static XS(Collectd_plugin_register_read) {
- return _plugin_register_generic_userdata(aTHX, PLUGIN_READ, "read");
+ _plugin_register_generic_userdata(aTHX, PLUGIN_READ, "read");
}
static XS(Collectd_plugin_register_write) {
- return _plugin_register_generic_userdata(aTHX, PLUGIN_WRITE, "write");
+ _plugin_register_generic_userdata(aTHX, PLUGIN_WRITE, "write");
}
static XS(Collectd_plugin_register_log) {
- return _plugin_register_generic_userdata(aTHX, PLUGIN_LOG, "log");
+ _plugin_register_generic_userdata(aTHX, PLUGIN_LOG, "log");
}
static XS(Collectd_plugin_register_notification) {
- return _plugin_register_generic_userdata(aTHX, PLUGIN_NOTIF, "notification");
+ _plugin_register_generic_userdata(aTHX, PLUGIN_NOTIF, "notification");
}
static XS(Collectd_plugin_register_flush) {
- return _plugin_register_generic_userdata(aTHX, PLUGIN_FLUSH, "flush");
+ _plugin_register_generic_userdata(aTHX, PLUGIN_FLUSH, "flush");
}
typedef int perl_unregister_function_t(const char *name);
unreg(SvPV_nolen(ST(0)));
XSRETURN_EMPTY;
-
- return;
} /* static void _plugin_unregister_generic ( ... ) */
/*
*/
static XS(Collectd_plugin_unregister_read) {
- return _plugin_unregister_generic(aTHX, plugin_unregister_read, "read");
+ _plugin_unregister_generic(aTHX, plugin_unregister_read, "read");
}
static XS(Collectd_plugin_unregister_write) {
- return _plugin_unregister_generic(aTHX, plugin_unregister_write, "write");
+ _plugin_unregister_generic(aTHX, plugin_unregister_write, "write");
}
static XS(Collectd_plugin_unregister_log) {
- return _plugin_unregister_generic(aTHX, plugin_unregister_log, "log");
+ _plugin_unregister_generic(aTHX, plugin_unregister_log, "log");
}
static XS(Collectd_plugin_unregister_notification) {
- return _plugin_unregister_generic(aTHX, plugin_unregister_notification,
- "notification");
+ _plugin_unregister_generic(aTHX, plugin_unregister_notification,
+ "notification");
}
static XS(Collectd_plugin_unregister_flush) {
- return _plugin_unregister_generic(aTHX, plugin_unregister_flush, "flush");
+ _plugin_unregister_generic(aTHX, plugin_unregister_flush, "flush");
}
/*
/* Lock the base thread to avoid race conditions with c_ithread_create().
* See https://github.com/collectd/collectd/issues/9 and
* https://github.com/collectd/collectd/issues/1706 for details.
- */
+ */
assert(aTHX == perl_threads->head->interp);
pthread_mutex_lock(&perl_threads->mutex);
/* Lock the base thread if this is not called from one of the read threads
* to avoid race conditions with c_ithread_create(). See
* https://github.com/collectd/collectd/issues/9 for details.
- */
+ */
if (aTHX == perl_threads->head->interp)
pthread_mutex_lock(&perl_threads->mutex);
* the thread as this will free the memory */
t = t->prev;
- thr->shutdown = 1;
+ thr->shutdown = true;
if (thr->running) {
/* Give some time to thread to exit from Perl interpreter */
WARNING("perl shutdown: Thread is running inside Perl. Waiting.");
return 0;
} /* static int g_interval_set (pTHX_ SV *, MAGIC *) */
-static MGVTBL g_pv_vtbl = {g_pv_get, g_pv_set, NULL, NULL, NULL, NULL, NULL
+static MGVTBL g_pv_vtbl = {g_pv_get,
+ g_pv_set,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
#if HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL
,
NULL
#endif
};
-static MGVTBL g_interval_vtbl = {g_interval_get, g_interval_set, NULL, NULL,
- NULL, NULL, NULL
+static MGVTBL g_interval_vtbl = {g_interval_get,
+ g_interval_set,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
#if HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL
,
NULL
* accessing any such variable (this is basically the same as using
* tie() in Perl) */
/* global strings */
+ struct {
+ char name[64];
+ char *var;
+ } g_strings[] = {{"Collectd::hostname_g", hostname_g}, {"", NULL}};
+
for (int i = 0; '\0' != g_strings[i].name[0]; ++i) {
tmp = get_sv(g_strings[i].name, 1);
sv_magicext(tmp, NULL, PERL_MAGIC_ext, &g_pv_vtbl, g_strings[i].var, 0);
char *plugin;
HV *config;
+ if (NULL == perl_threads) {
+ log_err("A `Plugin' block was encountered but no plugin was loaded yet. "
+ "Put the appropriate `LoadPlugin' option in front of it.");
+ return -1;
+ }
+
dSP;
if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) {