From dbf45dbf4eab1d058c49fc3bfb8be3e2cba98234 Mon Sep 17 00:00:00 2001 From: "J. Javier Maestro" Date: Sun, 16 Jun 2013 18:05:53 +0200 Subject: [PATCH] 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. --- src/write_graphite.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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. */ -- 2.30.2