From: Tahhan, Maryam Date: Mon, 29 May 2017 13:04:39 +0000 (+0100) Subject: mcelog: make options mutually exclusive X-Git-Tag: collectd-5.8.0~109^2~4 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=13d7a317bc5c677092b9e9ba1109afe47c952512;p=collectd.git mcelog: make options mutually exclusive Make the logfile and socket options mutually exclusive as the collection requirements for the 2 are different and the memory errors from the socket overlap with the logfile. Set the default to memory errors until the logfile changes are merged. Change-Id: If1eef9d37f1ffe404cf679df4dca9ae3c92ab9ea Signed-off-by: Tahhan, Maryam --- diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index c1c94619..c19ae734 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -3477,6 +3477,9 @@ the number of corrected/uncorrected memory errors. =head3 The Memory block +Note: these options cannot be used in conjunction with the logfile options, they are mutually +exclusive. + =over 3 =item B I @@ -3495,7 +3498,9 @@ not affect the stats being dispatched. =item B I -The mcelog file to parse. Defaults to B<"/var/log/mcelog">. +The mcelog file to parse. Defaults to B<"/var/log/mcelog">. Note: this option +cannot be used in conjunction with the memory block options, they are mutually +exclusive. =back diff --git a/src/mcelog.c b/src/mcelog.c index 23040c81..865b0d12 100644 --- a/src/mcelog.c +++ b/src/mcelog.c @@ -164,16 +164,33 @@ static void mcelog_update_dimm_stats(llentry_t *dimm, } static int mcelog_config(oconfig_item_t *ci) { + int use_logfile = 0, use_memory = 0; for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("McelogLogfile", child->key) == 0) { + use_logfile = 1; + if (use_memory) { + ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\", Memory " + "option is already configured.", + child->key); + return (-1); + } if (cf_util_get_string_buffer(child, g_mcelog_config.logfile, sizeof(g_mcelog_config.logfile)) < 0) { ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".", child->key); return (-1); } + memset(socket_adapter.unix_sock.sun_path, 0, + sizeof(socket_adapter.unix_sock.sun_path)); } else if (strcasecmp("Memory", child->key) == 0) { + if (use_logfile) { + ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\", Logfile " + "option is already configured.", + child->key); + return (-1); + } + use_memory = 1; oconfig_item_t *mem_child = child->children; for (int j = 0; j < child->children_num; j++) { mem_child += j; @@ -197,6 +214,7 @@ static int mcelog_config(oconfig_item_t *ci) { return (-1); } } + memset(g_mcelog_config.logfile, 0, sizeof(g_mcelog_config.logfile)); } else { ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".", child->key); @@ -619,6 +637,12 @@ static void *poll_worker(__attribute__((unused)) void *arg) { } static int mcelog_init(void) { + if (g_mcelog_config.logfile != NULL && + socket_adapter.unix_sock.sun_path != NULL) { + INFO(MCELOG_PLUGIN + ": No configuration selected defaulting to memory errors."); + memset(g_mcelog_config.logfile, 0, sizeof(g_mcelog_config.logfile)); + } g_mcelog_config.dimms_list = llist_create(); int err = pthread_mutex_init(&g_mcelog_config.dimms_lock, NULL); if (err < 0) { @@ -631,10 +655,12 @@ static int mcelog_init(void) { return (-1); } - if (plugin_thread_create(&g_mcelog_config.tid, NULL, poll_worker, NULL, - NULL) != 0) { - ERROR(MCELOG_PLUGIN ": Error creating poll thread."); - return (-1); + if (socket_adapter.unix_sock.sun_path != NULL) { + if (plugin_thread_create(&g_mcelog_config.tid, NULL, poll_worker, NULL, + NULL) != 0) { + ERROR(MCELOG_PLUGIN ": Error creating poll thread."); + return (-1); + } } return (0); }