Support trailing whitespace in config lines
authorChristophe Varoqui <christophe.varoqui@opensvc.com>
Fri, 30 Sep 2016 23:03:27 +0000 (01:03 +0200)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Fri, 30 Sep 2016 23:03:27 +0000 (01:03 +0200)
And discard empty lines

unmid.c
util.c

diff --git a/unmid.c b/unmid.c
index bae6b6c..635321a 100644 (file)
--- a/unmid.c
+++ b/unmid.c
@@ -180,6 +180,7 @@ load_config (void)
         char re[BUFSIZ];
        struct config *entry;
        conflines = 0;
+       int n;
 
        condlog(LOG_INFO, "read %s", configfile);
        if (!filepresent(configfile)) {
@@ -199,6 +200,10 @@ load_config (void)
                        return 1;
                }
 
+               n = strchop(buf);
+               if (!n)
+                       continue;
+
                // skip comments
                regcomp(&comment_re, comment_raw, REG_EXTENDED|REG_NOSUB);
                if (!regexec(&comment_re, buf, 0, NULL, 0)) {
diff --git a/util.c b/util.c
index 99c8476..07f865c 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1,5 +1,17 @@
+#include <string.h>
+#include <ctype.h>
 #include <sys/stat.h>
 
+size_t
+strchop(char *str)
+{
+       int i;
+
+       for (i=strlen(str)-1; i >=0 && isspace(str[i]); --i) ;
+       str[++i] = '\0';
+       return strlen(str);
+}
+
 int
 filepresent (char * run) {
        struct stat buf;