mcelog: make options mutually exclusive
authorTahhan, Maryam <maryam.tahhan@intel.com>
Mon, 29 May 2017 13:04:39 +0000 (14:04 +0100)
committerTahhan, Maryam <maryam.tahhan@intel.com>
Thu, 6 Jul 2017 13:38:17 +0000 (14:38 +0100)
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 <maryam.tahhan@intel.com>
src/collectd.conf.pod
src/mcelog.c

index c1c9461..c19ae73 100644 (file)
@@ -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<McelogClientSocket> I<Path>
@@ -3495,7 +3498,9 @@ not affect the stats being dispatched.
 
 =item B<McelogLogfile> I<Path>
 
-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
 
index 23040c8..865b0d1 100644 (file)
@@ -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);
 }