From: J. Javier Maestro Date: Sun, 16 Jun 2013 16:05:53 +0000 (+0200) Subject: write_graphite plugin: config should fail on error X-Git-Tag: collectd-5.4.0~27^2~1 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=dbf45dbf4eab1d058c49fc3bfb8be3e2cba98234;p=collectd.git write_graphite plugin: config should fail on error This is the preferred way of handling config, as it can be seen in snmp.c. It's important to fail on a config error to simplify code in other callbacks. --- diff --git a/src/write_graphite.c b/src/write_graphite.c index 546111bb..c264932f 100644 --- a/src/write_graphite.c +++ b/src/write_graphite.c @@ -456,6 +456,7 @@ static int wg_config_node (oconfig_item_t *ci) user_data_t user_data; char callback_name[DATA_MAX_NAME_LEN]; int i; + int status = 0; cb = malloc (sizeof (*cb)); if (cb == NULL) @@ -478,7 +479,7 @@ static int wg_config_node (oconfig_item_t *ci) /* FIXME: Legacy configuration syntax. */ if (strcasecmp ("Carbon", ci->key) != 0) { - int status = cf_util_get_string (ci, &cb->name); + status = cf_util_get_string (ci, &cb->name); if (status != 0) { wg_callback_free (cb); @@ -520,7 +521,17 @@ static int wg_config_node (oconfig_item_t *ci) { ERROR ("write_graphite plugin: Invalid configuration " "option: %s.", child->key); + status = -1; } + + if (status != 0) + break; + } + + if (status != 0) + { + wg_callback_free (cb); + return (status); } /* FIXME: Legacy configuration syntax. */