chiark / gitweb /
Do not unescape unit names in [Install] section
[elogind.git] / src / shared / conf-parser.c
index 1ad2b4fcba85ae2f5a2db71346e41baef2eac2bc..158e9efd4cecb260bb15426379fa468e9c8dfe7b 100644 (file)
@@ -204,6 +204,7 @@ static int parse_line(const char* unit,
                       bool allow_include,
                       char **section,
                       unsigned *section_line,
+                      bool *section_ignored,
                       char *l,
                       void *userdata) {
 
@@ -266,7 +267,7 @@ static int parse_line(const char* unit,
 
                 if (sections && !nulstr_contains(sections, n)) {
 
-                        if (!relaxed)
+                        if (!relaxed && !startswith(n, "X-"))
                                 log_syntax(unit, LOG_WARNING, filename, line, EINVAL,
                                            "Unknown section '%s'. Ignoring.", n);
 
@@ -274,10 +275,12 @@ static int parse_line(const char* unit,
                         free(*section);
                         *section = NULL;
                         *section_line = 0;
+                        *section_ignored = true;
                 } else {
                         free(*section);
                         *section = n;
                         *section_line = line;
+                        *section_ignored = false;
                 }
 
                 return 0;
@@ -285,7 +288,7 @@ static int parse_line(const char* unit,
 
         if (sections && !*section) {
 
-                if (!relaxed)
+                if (!relaxed && !*section_ignored)
                         log_syntax(unit, LOG_WARNING, filename, line, EINVAL,
                                    "Assignment outside of section. Ignoring.");
 
@@ -328,6 +331,7 @@ int config_parse(const char *unit,
         _cleanup_free_ char *section = NULL, *continuation = NULL;
         _cleanup_fclose_ FILE *ours = NULL;
         unsigned line = 0, section_line = 0;
+        bool section_ignored = false;
         int r;
 
         assert(filename);
@@ -336,8 +340,8 @@ int config_parse(const char *unit,
         if (!f) {
                 f = ours = fopen(filename, "re");
                 if (!f) {
-                        log_error("Failed to open configuration file '%s': %m", filename);
-                        return -errno;
+                        log_full(errno == ENOENT ? LOG_DEBUG : LOG_ERR, "Failed to open configuration file '%s': %m", filename);
+                        return errno == ENOENT ? 0 : -errno;
                 }
         }
 
@@ -399,6 +403,7 @@ int config_parse(const char *unit,
                                allow_include,
                                &section,
                                &section_line,
+                               &section_ignored,
                                p,
                                userdata);
                 free(c);
@@ -565,57 +570,55 @@ int config_parse_bool(const char* unit,
         return 0;
 }
 
-int config_parse_string(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) {
+int config_parse_string(
+                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) {
 
-        char **s = data;
-        char *n;
+        char **s = data, *n;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        n = strdup(rvalue);
-        if (!n)
-                return log_oom();
-
-        if (!utf8_is_valid(n)) {
-                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
-                           "String is not UTF-8 clean, ignoring assignment: %s", rvalue);
-                free(n);
+        if (!utf8_is_valid(rvalue)) {
+                log_invalid_utf8(unit, LOG_ERR, filename, line, EINVAL, rvalue);
                 return 0;
         }
 
-        free(*s);
-        if (*n)
-                *s = n;
+        if (isempty(rvalue))
+                n = NULL;
         else {
-                free(n);
-                *s = NULL;
+                n = strdup(rvalue);
+                if (!n)
+                        return log_oom();
         }
 
+        free(*s);
+        *s = n;
+
         return 0;
 }
 
-int config_parse_path(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) {
+int config_parse_path(
+                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) {
 
         char **s = data, *n;
 
@@ -625,7 +628,7 @@ int config_parse_path(const char *unit,
         assert(data);
 
         if (!utf8_is_valid(rvalue)) {
-                log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Path is not UTF-8 clean, ignoring assignment: %s", rvalue);
+                log_invalid_utf8(unit, LOG_ERR, filename, line, EINVAL, rvalue);
                 return 0;
         }
 
@@ -683,19 +686,18 @@ int config_parse_strv(const char *unit,
         }
 
         FOREACH_WORD_QUOTED(w, l, rvalue, state) {
-                _cleanup_free_ char *n;
+                char *n;
 
-                n = cunescape_length(w, l);
+                n = strndup(w, l);
                 if (!n)
                         return log_oom();
 
                 if (!utf8_is_valid(n)) {
-                        log_syntax(unit, LOG_ERR, filename, line, EINVAL,
-                                   "String is not UTF-8 clean, ignoring: %s", rvalue);
+                        log_invalid_utf8(unit, LOG_ERR, filename, line, EINVAL, rvalue);
                         continue;
                 }
 
-                r = strv_extend(sv, n);
+                r = strv_consume(sv, n);
                 if (r < 0)
                         return log_oom();
         }