X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Fplugin.c;h=73d7c8414ce65c8ec6c49dfd6e0c897a201f4553;hb=5b979ffa2721f7b8f2a64af2b9b42c9d5f2d690f;hp=72e3591cbae51859db8c4cde71132fa90512fae5;hpb=ce79ade493b71b2c6a3dbc18b07d791739ad0cc2;p=collectd.git diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index 72e3591c..73d7c841 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -292,10 +292,10 @@ static int register_callback(llist_t **list, /* {{{ */ old_cf = le->value; le->value = cf; - WARNING("plugin: register_callback: " - "a callback named `%s' already exists - " - "overwriting the old entry!", - name); + P_WARNING("register_callback: " + "a callback named `%s' already exists - " + "overwriting the old entry!", + name); destroy_callback(old_cf); sfree(key); @@ -315,7 +315,7 @@ static void log_list_callbacks(llist_t **list, /* {{{ */ n = llist_size(*list); if (n == 0) { - INFO("%s [none]", comment); + INFO("%s: [none]", comment); return; } @@ -347,7 +347,7 @@ static int create_register_callback(llist_t **list, /* {{{ */ const char *name, void *callback, user_data_t const *ud) { - if ((name == NULL) || (callback == NULL)) + if (name == NULL || callback == NULL) return EINVAL; callback_func_t *cf = calloc(1, sizeof(*cf)); @@ -713,25 +713,8 @@ plugin_value_list_clone(value_list_t const *vl_orig) /* {{{ */ vl->time = cdtime(); /* Fill in the interval from the thread context, if it is zero. */ - if (vl->interval == 0) { - plugin_ctx_t ctx = plugin_get_ctx(); - - if (ctx.interval != 0) - vl->interval = ctx.interval; - else { - char name[6 * DATA_MAX_NAME_LEN]; - FORMAT_VL(name, sizeof(name), vl); - ERROR("plugin_value_list_clone: Unable to determine " - "interval from context for " - "value list \"%s\". " - "This indicates a broken plugin. " - "Please report this problem to the " - "collectd mailing list or at " - ".", - name); - vl->interval = cf_get_default_interval(); - } - } + if (vl->interval == 0) + vl->interval = plugin_get_interval(); return vl; } /* }}} value_list_t *plugin_value_list_clone */ @@ -1114,9 +1097,9 @@ static int plugin_insert_read(read_func_t *rf) { le = llist_search(read_list, rf->rf_name); if (le != NULL) { pthread_mutex_unlock(&read_lock); - WARNING("The read function \"%s\" is already registered. " - "Check for duplicates in your configuration!", - rf->rf_name); + P_WARNING("The read function \"%s\" is already registered. " + "Check for duplicates in your configuration!", + rf->rf_name); return EINVAL; } @@ -1162,6 +1145,7 @@ int plugin_register_read(const char *name, int (*callback)(void)) { rf->rf_name = strdup(name); rf->rf_type = RF_SIMPLE; rf->rf_interval = plugin_get_interval(); + rf->rf_ctx.interval = rf->rf_interval; status = plugin_insert_read(rf); if (status != 0) { @@ -1203,6 +1187,7 @@ int plugin_register_complex_read(const char *group, const char *name, } rf->rf_ctx = plugin_get_ctx(); + rf->rf_ctx.interval = rf->rf_interval; status = plugin_insert_read(rf); if (status != 0) { @@ -2208,7 +2193,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; @@ -2217,13 +2202,9 @@ 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 + strlen(msg), sizeof(msg) - strlen(msg), format, ap); - msg[sizeof(msg) - 1] = 0; + vsnprintf(msg, sizeof(msg), format, ap); + msg[sizeof(msg) - 1] = '\0'; va_end(ap); if (list_log == NULL) { @@ -2248,6 +2229,21 @@ void plugin_log(int level, const char *format, ...) { } } /* void plugin_log */ +void daemon_log(int level, const char *format, ...) { + char msg[1024] = ""; // Size inherits from plugin_log() + + char const *name = plugin_get_ctx().name; + if (name == NULL) + name = "UNKNOWN"; + + va_list ap; + va_start(ap, format); + vsnprintf(msg, sizeof(msg), format, ap); + va_end(ap); + + plugin_log(level, "%s plugin: %s", name, msg); +} /* void daemon_log */ + int parse_log_severity(const char *severity) { int log_level = -1; @@ -2287,7 +2283,7 @@ const data_set_t *plugin_get_ds(const char *name) { data_set_t *ds; if (data_sets == NULL) { - ERROR("plugin_get_ds: No data sets are defined yet."); + P_ERROR("plugin_get_ds: No data sets are defined yet."); return NULL; } @@ -2518,6 +2514,8 @@ cdtime_t plugin_get_interval(void) { if (interval > 0) return interval; + P_ERROR("plugin_get_interval: Unable to determine Interval from context."); + return cf_get_default_interval(); } /* cdtime_t plugin_get_interval */