chiark / gitweb /
conf-parser: when we parse a string list, always fill in something
[elogind.git] / src / shared / conf-parser.c
index c5dd26db5240d1dcf650e46275f29c1485df3f45..c2cf5a6a196d08e4f070770c070ac9a651a418d6 100644 (file)
@@ -467,6 +467,33 @@ int config_parse_unsigned(
         return 0;
 }
 
+int config_parse_double(
+                const char *filename,
+                unsigned line,
+                const char *section,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        double *d = data;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        r = safe_atod(rvalue, d);
+        if (r < 0) {
+                log_error("[%s:%u] Failed to parse numeric value: %s", filename, line, rvalue);
+                return r;
+        }
+
+        return 0;
+}
+
 int config_parse_bytes_size(
                 const char *filename,
                 unsigned line,
@@ -678,9 +705,18 @@ int config_parse_strv(
         assert(data);
 
         if (isempty(rvalue)) {
-                /* Empty assignment resets the list */
+                char **empty;
+
+                /* Empty assignment resets the list. As a special rule
+                 * we actually fill in a real empty array here rather
+                 * than NULL, since some code wants to know if
+                 * something was set at all... */
+                empty = strv_new(NULL, NULL);
+                if (!empty)
+                        return log_oom();
+
                 strv_free(*sv);
-                *sv = NULL;
+                *sv = empty;
                 return 0;
         }