Hostinfo day 6: RPM packaging, initscripts, hostinfo-status, hostinfo-test.
[virt-hostinfo.git] / hostinfod / configuration.c
index 86a43dc..7ff3afa 100644 (file)
@@ -122,7 +122,9 @@ struct guests_data {
   const char *cmd;             /* command being tested */
   int in_section;              /* currently processing the right section? */
   double interval;             /* interval for this guest (0 = any) */
+  int interval_set;            /* have we set interval yet? */
   int enabled;                 /* is command enabled? */
+  int enabled_set;             /* have we set enabled flag yet? */
 };
 
 void
@@ -135,7 +137,9 @@ check_guests_file (struct guest_description *hval, const char *cmd,
   data->cmd = cmd;
   data->in_section = 0;
   data->interval = 60.;                /* default */
+  data->interval_set = 0;
   data->enabled = 0;           /* default */
+  data->enabled_set = 0;
 
   process_conf_file (guests_file, 1,
                     guests_process_line, guests_process_section, data);
@@ -156,21 +160,27 @@ guests_process_line (const char *path, int lineno,
     return 0;
 
   if (strcasecmp (key, "interval") == 0) {
-    if (strcasecmp (value, "any") == 0)
-      data->interval = 0;
-    else {
-      if (sscanf (value, "%lg", &data->interval) != 1) {
-       error ("%s:%d: %s: not a valid decimal number", path, lineno, key);
-       return -1;
+    if (!data->interval_set) {
+      if (strcasecmp (value, "any") == 0)
+       data->interval = 0;
+      else {
+       if (sscanf (value, "%lg", &data->interval) != 1) {
+         error ("%s:%d: %s: not a valid decimal number", path, lineno, key);
+         return -1;
+       }
       }
+      data->interval_set = 1;
     }
   } else if (strcasecmp (key, data->cmd) == 0) {
-    bool = get_bool (value);
-    if (bool == -1) {
-      error ("%s:%d: %s: not a valid boolean - use 1 or 0", path, lineno, key);
-      return -1;
+    if (!data->enabled_set) {
+      bool = get_bool (value);
+      if (bool == -1) {
+       error ("%s:%d: %s: not a valid boolean - use 1 or 0", path, lineno, key);
+       return -1;
+      }
+      data->enabled = bool;
+      data->enabled_set = 1;
     }
-    data->enabled = bool;
   }
 
   return 0;