diff options
Diffstat (limited to 'src/zabbix_agent/zbxconf.c')
-rw-r--r-- | src/zabbix_agent/zbxconf.c | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/src/zabbix_agent/zbxconf.c b/src/zabbix_agent/zbxconf.c index 54319c4bde5..33375da6a13 100644 --- a/src/zabbix_agent/zbxconf.c +++ b/src/zabbix_agent/zbxconf.c @@ -158,41 +158,69 @@ void load_user_parameters(char **lines) void load_perf_counters(const char **lines) { char name[MAX_STRING_LEN], counterpath[PDH_MAX_COUNTER_PATH], interval[8]; - const char **pline, *msg; + const char **pline; + char *error = NULL; LPTSTR wcounterPath; - -#define ZBX_PC_FAIL(_msg) {msg = _msg; goto pc_fail;} + int period; for (pline = lines; NULL != *pline; pline++) { if (3 < num_param(*pline)) - ZBX_PC_FAIL("required parameter missing"); + { + error = zbx_strdup(error, "Required parameter missing."); + goto pc_fail; + } if (0 != get_param(*pline, 1, name, sizeof(name))) - ZBX_PC_FAIL("cannot parse key"); + { + error = zbx_strdup(error, "Cannot parse key."); + goto pc_fail; + } if (0 != get_param(*pline, 2, counterpath, sizeof(counterpath))) - ZBX_PC_FAIL("cannot parse counter path"); + { + error = zbx_strdup(error, "Cannot parse counter path."); + goto pc_fail; + } if (0 != get_param(*pline, 3, interval, sizeof(interval))) - ZBX_PC_FAIL("cannot parse interval"); + { + error = zbx_strdup(error, "Cannot parse interval."); + goto pc_fail; + } wcounterPath = zbx_acp_to_unicode(counterpath); zbx_unicode_to_utf8_static(wcounterPath, counterpath, PDH_MAX_COUNTER_PATH); zbx_free(wcounterPath); if (FAIL == check_counter_path(counterpath)) - ZBX_PC_FAIL("invalid counter path"); + { + error = zbx_strdup(error, "Invalid counter path."); + goto pc_fail; + } + + period = atoi(interval); - if (NULL == add_perf_counter(name, counterpath, atoi(interval))) - ZBX_PC_FAIL("cannot add counter"); + if (1 > period || MAX_COLLECTOR_PERIOD < period) + { + error = zbx_strdup(NULL, "Interval out of range."); + goto pc_fail; + } + + if (NULL == add_perf_counter(name, counterpath, period, &error)) + { + if (NULL == error) + error = zbx_strdup(error, "Failed to add new performance counter."); + goto pc_fail; + } continue; pc_fail: - zabbix_log(LOG_LEVEL_CRIT, "PerfCounter '%s' FAILED: %s", *pline, msg); - exit(FAIL); + zabbix_log(LOG_LEVEL_CRIT, "cannot add performance counter \"%s\": %s", *pline, error); + zbx_free(error); + + exit(EXIT_FAILURE); } -#undef ZBX_PC_FAIL } #endif /* _WINDOWS */ |