Support comments in the config file
authorChristophe Varoqui <christophe.varoqui@opensvc.com>
Fri, 30 Sep 2016 22:40:21 +0000 (00:40 +0200)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Fri, 30 Sep 2016 22:40:21 +0000 (00:40 +0200)
unmid.c

diff --git a/unmid.c b/unmid.c
index 6c99ace..bae6b6c 100644 (file)
--- a/unmid.c
+++ b/unmid.c
@@ -51,6 +51,8 @@ int conflines;
 int logsink;
 int log_threshold = LOG_DEFAULT_THRESHOLD;
 FILE * kmesg_fp;
+regex_t comment_re;
+static const char * comment_raw = "^\\s*[;#]";
 
 static void *
 signal_set(int signo, void (*func) (int))
@@ -197,6 +199,12 @@ load_config (void)
                        return 1;
                }
 
+               // skip comments
+               regcomp(&comment_re, comment_raw, REG_EXTENDED|REG_NOSUB);
+               if (!regexec(&comment_re, buf, 0, NULL, 0)) {
+                       continue;
+               }
+
                // make room for a new struct
                conf = realloc(conf, (conflines+1)*sizeof(struct config));
                if (!conf) {
@@ -209,7 +217,7 @@ load_config (void)
 
                if (sscanf(buf, "%x %c", &entry->reason, &entry->trigger) != 2) {
                        condlog(LOG_ERR, "syntax error in line: %s", buf);
-                       return 1;
+                       continue;
                }
                snprintf(re, BUFSIZ, "NMI received for unknown reason %x on CPU", entry->reason);
                 condlog(LOG_INFO, " pattern '%s' loaded with trigger '%c'", re, entry->trigger);