X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fdaemon%2Fplugin.c;h=72e3591cbae51859db8c4cde71132fa90512fae5;hp=427a813485adeeefb325c298d3b641fd62e41fa4;hb=ce79ade493b71b2c6a3dbc18b07d791739ad0cc2;hpb=9ea20c99eadea54a7cb4efb51e2f6e06e4187915 diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index 427a8134..72e3591c 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -346,19 +346,22 @@ static void log_list_callbacks(llist_t **list, /* {{{ */ static int create_register_callback(llist_t **list, /* {{{ */ const char *name, void *callback, user_data_t const *ud) { - callback_func_t *cf; - cf = calloc(1, sizeof(*cf)); + if ((name == NULL) || (callback == NULL)) + return EINVAL; + + callback_func_t *cf = calloc(1, sizeof(*cf)); if (cf == NULL) { free_userdata(ud); ERROR("plugin: create_register_callback: calloc failed."); - return -1; + return ENOMEM; } cf->cf_callback = callback; if (ud == NULL) { - cf->cf_udata.data = NULL; - cf->cf_udata.free_func = NULL; + cf->cf_udata = (user_data_t){ + .data = NULL, .free_func = NULL, + }; } else { cf->cf_udata = *ud; } @@ -1714,8 +1717,12 @@ int plugin_write(const char *plugin, /* {{{ */ callback_func_t *cf = le->value; plugin_write_cb callback; - /* do not switch plugin context; rather keep the context (interval) - * information of the calling read plugin */ + /* Keep the read plugin's interval and flush information but update the + * plugin name. */ + plugin_ctx_t old_ctx = plugin_get_ctx(); + plugin_ctx_t ctx = old_ctx; + ctx.name = cf->cf_ctx.name; + plugin_set_ctx(ctx); DEBUG("plugin: plugin_write: Writing values via %s.", le->key); callback = cf->cf_callback; @@ -1725,6 +1732,7 @@ int plugin_write(const char *plugin, /* {{{ */ else success++; + plugin_set_ctx(old_ctx); le = le->next; } @@ -2200,7 +2208,7 @@ int plugin_dispatch_notification(const notification_t *notif) { } /* int plugin_dispatch_notification */ void plugin_log(int level, const char *format, ...) { - char msg[1024]; + char msg[1024] = ""; va_list ap; llentry_t *le; @@ -2209,9 +2217,13 @@ void plugin_log(int level, const char *format, ...) { return; #endif + char const *name = plugin_get_ctx().name; + if (name != NULL) + snprintf(msg, sizeof(msg), "%s plugin: ", name); + va_start(ap, format); - vsnprintf(msg, sizeof(msg), format, ap); - msg[sizeof(msg) - 1] = '\0'; + vsnprintf(msg + strlen(msg), sizeof(msg) - strlen(msg), format, ap); + msg[sizeof(msg) - 1] = 0; va_end(ap); if (list_log == NULL) {