chiark / gitweb /
architecture: Add tilegx
[elogind.git] / src / shared / conf-parser.c
index d5a639e874a3138bfe040977f1e7fa46a1da905c..cfa669b1139bd416bbb4d1aec1c5a5da46e8c5cd 100644 (file)
@@ -225,6 +225,15 @@ static int parse_line(const char* unit,
         if (startswith(l, ".include ")) {
                 _cleanup_free_ char *fn = NULL;
 
+                /* .includes are a bad idea, we only support them here
+                 * for historical reasons. They create cyclic include
+                 * problems and make it difficult to detect
+                 * configuration file changes with an easy
+                 * stat(). Better approaches, such as .d/ drop-in
+                 * snippets exist.
+                 *
+                 * Support for them should be eventually removed. */
+
                 if (!allow_include) {
                         log_syntax(unit, LOG_ERR, filename, line, EBADMSG,
                                    ".include not allowed here. Ignoring.");
@@ -438,8 +447,7 @@ DEFINE_PARSER(double, double, safe_atod)
 DEFINE_PARSER(nsec, nsec_t, parse_nsec)
 DEFINE_PARSER(sec, usec_t, parse_sec)
 
-
-int config_parse_bytes_size(const char* unit,
+int config_parse_iec_size(const char* unit,
                             const char *filename,
                             unsigned line,
                             const char *section,
@@ -459,10 +467,9 @@ int config_parse_bytes_size(const char* unit,
         assert(rvalue);
         assert(data);
 
-        r = parse_bytes(rvalue, &o);
+        r = parse_size(rvalue, 1024, &o);
         if (r < 0 || (off_t) (size_t) o != o) {
-                log_syntax(unit, LOG_ERR, filename, line, -r,
-                           "Failed to parse byte value, ignoring: %s", rvalue);
+                log_syntax(unit, LOG_ERR, filename, line, r < 0 ? -r : ERANGE, "Failed to parse size value, ignoring: %s", rvalue);
                 return 0;
         }
 
@@ -470,8 +477,37 @@ int config_parse_bytes_size(const char* unit,
         return 0;
 }
 
+int config_parse_si_size(const char* unit,
+                            const char *filename,
+                            unsigned line,
+                            const char *section,
+                            unsigned section_line,
+                            const char *lvalue,
+                            int ltype,
+                            const char *rvalue,
+                            void *data,
+                            void *userdata) {
+
+        size_t *sz = data;
+        off_t o;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        r = parse_size(rvalue, 1000, &o);
+        if (r < 0 || (off_t) (size_t) o != o) {
+                log_syntax(unit, LOG_ERR, filename, line, r < 0 ? -r : ERANGE, "Failed to parse size value, ignoring: %s", rvalue);
+                return 0;
+        }
+
+        *sz = (size_t) o;
+        return 0;
+}
 
-int config_parse_bytes_off(const char* unit,
+int config_parse_iec_off(const char* unit,
                            const char *filename,
                            unsigned line,
                            const char *section,
@@ -492,10 +528,9 @@ int config_parse_bytes_off(const char* unit,
 
         assert_cc(sizeof(off_t) == sizeof(uint64_t));
 
-        r = parse_bytes(rvalue, bytes);
+        r = parse_size(rvalue, 1024, bytes);
         if (r < 0)
-                log_syntax(unit, LOG_ERR, filename, line, -r,
-                           "Failed to parse bytes value, ignoring: %s", rvalue);
+                log_syntax(unit, LOG_ERR, filename, line, -r, "Failed to parse size value, ignoring: %s", rvalue);
 
         return 0;
 }