From: Bert Vermeulen Date: Mon, 29 Jul 2013 21:47:25 +0000 (+0200) Subject: Config errors should not be fatal X-Git-Tag: collectd-5.4.0~14^2~10 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f295a5c9440195885c76e9904ac8b1dd6a3c2b0d;p=collectd.git Config errors should not be fatal --- diff --git a/src/sigrok.c b/src/sigrok.c index 75badcae..d6900436 100644 --- a/src/sigrok.c +++ b/src/sigrok.c @@ -69,39 +69,35 @@ static int sigrok_config_device(oconfig_item_t *ci) { oconfig_item_t *item; struct config_device *cfdev; - int ret, i; - - if (ci->values_num != 1 || ci->values[0].type != OCONFIG_TYPE_STRING) { - ERROR("Invalid device name."); - return 1; - } + int i; if (!(cfdev = malloc(sizeof(struct config_device)))) { ERROR("malloc() failed."); return 1; } memset(cfdev, 0, sizeof(struct config_device)); - cf_util_get_string(ci, &cfdev->name); + if (cf_util_get_string(ci, &cfdev->name)) { + WARNING("Invalid device name."); + return 1; + } cfdev->min_dispatch_interval = DEFAULT_MIN_DISPATCH_INTERVAL; for (i = 0; i < ci->children_num; i++) { item = ci->children + i; if (item->values_num != 1) { - ERROR("Missing value for '%s'.", item->key); + WARNING("Missing value for '%s'.", item->key); return 1; } if (!strcasecmp(item->key, "driver")) - ret = cf_util_get_string(item, &cfdev->driver); + cf_util_get_string(item, &cfdev->driver); else if (!strcasecmp(item->key, "conn")) - ret = cf_util_get_string(item, &cfdev->conn); + cf_util_get_string(item, &cfdev->conn); else if (!strcasecmp(item->key, "serialcomm")) - ret = cf_util_get_string(item, &cfdev->serialcomm); + cf_util_get_string(item, &cfdev->serialcomm); else if (!strcasecmp(item->key, "interval")) - ret = cf_util_get_cdtime(item, &cfdev->min_dispatch_interval); - if (ret) { - ERROR("Invalid keyword '%s'.", item->key); - return 1; - } + cf_util_get_cdtime(item, &cfdev->min_dispatch_interval); + else + WARNING("Invalid keyword '%s'.", item->key); } config_devices = g_slist_append(config_devices, cfdev); @@ -119,16 +115,13 @@ static int sigrok_config(oconfig_item_t *ci) if (!strcasecmp(item->key, "loglevel")) { if (cf_util_get_int(item, &tmp) || tmp < 0 || tmp > 5) { ERROR("Invalid loglevel"); - return 1; + continue; } loglevel = tmp; - } else if (!strcasecmp(item->key, "Device")) { - if (sigrok_config_device(item) != 0) - return 1; - } else { - ERROR("Invalid keyword '%s'.", item->key); - return 1; - } + } else if (!strcasecmp(item->key, "Device")) + sigrok_config_device(item); + else + WARNING("Invalid keyword '%s'.", item->key); } return 0;