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;
}
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;
else
success++;
+ plugin_set_ctx(old_ctx);
le = le->next;
}
} /* int plugin_dispatch_notification */
void plugin_log(int level, const char *format, ...) {
- char msg[1024];
+ char msg[1024] = "";
va_list ap;
llentry_t *le;
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) {