Hostinfo day 3: Further work on the daemon.
[virt-hostinfo.git] / hostinfod / configuration.c
index 0d71908..90200f8 100644 (file)
@@ -120,8 +120,10 @@ process_conf_file (const char *path, int exit_if_not_exist,
   while ((r = getline (&line, &len, fp)) != -1) {
     lineno++;
 
+    /*debug ("%s:%d: '%s' (len = %d)", path, lineno, line, len);*/
+
     /* Remove trailing \n */
-    real_len = len;
+    real_len = strlen (line);
     if (real_len > 0 && line[real_len-1] == '\n')
       line[--real_len] = '\0';
 
@@ -142,7 +144,13 @@ process_conf_file (const char *path, int exit_if_not_exist,
 
       debug ("configuration file: section [%s]", line);
 
-      if (process_section && process_section (path, lineno, line) == -1)
+      if (!process_section) {
+       error ("%s:%d: unexpected section header ([%s]) in file",
+              path, lineno, line);
+       exit (1);
+      }
+
+      if (process_section (path, lineno, line) == -1)
        exit (1);
     }
     else {                     /* Key value */