]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/core/load-fragment.c
core: simply timer expression parsing by using ".ltype" field of conf-parser logic
[thirdparty/systemd.git] / src / core / load-fragment.c
index 2f62c7acb538081f4d0edfd00bb41cba957a3dac..b9388deac244c9190ed25ac0b10ce2580e3a9b8f 100644 (file)
@@ -312,23 +312,50 @@ int config_parse_unit_path_strv_printf(
                 if (r < 0)
                         return 0;
 
-                r = strv_push(x, k);
+                r = strv_consume(x, TAKE_PTR(k));
                 if (r < 0)
                         return log_oom();
-                k = NULL;
         }
 }
 
-int config_parse_socket_listen(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) {
+static int patch_var_run(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *lvalue,
+                char **path) {
+
+        const char *e;
+        char *z;
+
+        e = path_startswith(*path, "/var/run/");
+        if (!e)
+                return 0;
+
+        z = path_join("/run/", e);
+        if (!z)
+                return log_oom();
+
+        log_syntax(unit, LOG_NOTICE, filename, line, 0,
+                   "%s= references a path below legacy directory /var/run/, updating %s → %s; "
+                   "please update the unit file accordingly.", lvalue, *path, z);
+
+        free_and_replace(*path, z);
+
+        return 1;
+}
+
+int config_parse_socket_listen(
+                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) {
 
         _cleanup_free_ SocketPort *p = NULL;
         SocketPort *tail;
@@ -365,6 +392,12 @@ int config_parse_socket_listen(const char *unit,
                 if (r < 0)
                         return 0;
 
+                if (ltype == SOCKET_FIFO) {
+                        r = patch_var_run(unit, filename, line, lvalue, &k);
+                        if (r < 0)
+                                return r;
+                }
+
                 free_and_replace(p->path, k);
                 p->type = ltype;
 
@@ -394,6 +427,12 @@ int config_parse_socket_listen(const char *unit,
                         return 0;
                 }
 
+                if (k[0] == '/') { /* Only for AF_UNIX file system sockets… */
+                        r = patch_var_run(unit, filename, line, lvalue, &k);
+                        if (r < 0)
+                                return r;
+                }
+
                 r = socket_address_parse_and_warn(&p->address, k);
                 if (r < 0) {
                         if (r != -EAFNOSUPPORT)
@@ -1459,24 +1498,24 @@ int config_parse_exec_smack_process_label(
         return 0;
 }
 
-int config_parse_timer(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_timer(
+                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) {
 
+        _cleanup_(calendar_spec_freep) CalendarSpec *c = NULL;
+        _cleanup_free_ char *k = NULL;
+        Unit *u = userdata;
         Timer *t = data;
         usec_t usec = 0;
         TimerValue *v;
-        TimerBase b;
-        _cleanup_(calendar_spec_freep) CalendarSpec *c = NULL;
-        Unit *u = userdata;
-        _cleanup_free_ char *k = NULL;
         int r;
 
         assert(filename);
@@ -1490,19 +1529,13 @@ int config_parse_timer(const char *unit,
                 return 0;
         }
 
-        b = timer_base_from_string(lvalue);
-        if (b < 0) {
-                log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse timer base, ignoring: %s", lvalue);
-                return 0;
-        }
-
         r = unit_full_printf(u, rvalue, &k);
         if (r < 0) {
                 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue);
                 return 0;
         }
 
-        if (b == TIMER_CALENDAR) {
+        if (ltype == TIMER_CALENDAR) {
                 if (calendar_spec_from_string(k, &c) < 0) {
                         log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse calendar specification, ignoring: %s", k);
                         return 0;
@@ -1513,13 +1546,15 @@ int config_parse_timer(const char *unit,
                         return 0;
                 }
 
-        v = new0(TimerValue, 1);
+        v = new(TimerValue, 1);
         if (!v)
                 return log_oom();
 
-        v->base = b;
-        v->value = usec;
-        v->calendar_spec = TAKE_PTR(c);
+        *v = (TimerValue) {
+                .base = ltype,
+                .value = usec,
+                .calendar_spec = TAKE_PTR(c),
+        };
 
         LIST_PREPEND(value, t->values, v);
 
@@ -2695,7 +2730,9 @@ int config_parse_syscall_filter(
                         c->syscall_whitelist = true;
 
                         /* Accept default syscalls if we are on a whitelist */
-                        r = seccomp_parse_syscall_filter("@default", -1, c->syscall_filter, SECCOMP_PARSE_WHITELIST);
+                        r = seccomp_parse_syscall_filter(
+                                        "@default", -1, c->syscall_filter,
+                                        SECCOMP_PARSE_PERMISSIVE|SECCOMP_PARSE_WHITELIST);
                         if (r < 0)
                                 return r;
                 }
@@ -2722,9 +2759,12 @@ int config_parse_syscall_filter(
                         continue;
                 }
 
-                r = seccomp_parse_syscall_filter_full(name, num, c->syscall_filter,
-                                                      SECCOMP_PARSE_LOG|SECCOMP_PARSE_PERMISSIVE|(invert ? SECCOMP_PARSE_INVERT : 0)|(c->syscall_whitelist ? SECCOMP_PARSE_WHITELIST : 0),
-                                                      unit, filename, line);
+                r = seccomp_parse_syscall_filter_full(
+                                name, num, c->syscall_filter,
+                                SECCOMP_PARSE_LOG|SECCOMP_PARSE_PERMISSIVE|
+                                (invert ? SECCOMP_PARSE_INVERT : 0)|
+                                (c->syscall_whitelist ? SECCOMP_PARSE_WHITELIST : 0),
+                                unit, filename, line);
                 if (r < 0)
                         return r;
         }
@@ -4254,7 +4294,6 @@ int config_parse_pid_file(
         _cleanup_free_ char *k = NULL, *n = NULL;
         Unit *u = userdata;
         char **s = data;
-        const char *e;
         int r;
 
         assert(filename);
@@ -4284,20 +4323,11 @@ int config_parse_pid_file(
         if (r < 0)
                 return r;
 
-        e = path_startswith(n, "/var/run/");
-        if (e) {
-                char *z;
-
-                z = strjoin("/run/", e);
-                if (!z)
-                        return log_oom();
-
-                log_syntax(unit, LOG_NOTICE, filename, line, 0, "PIDFile= references path below legacy directory /var/run/, updating %s → %s; please update the unit file accordingly.", n, z);
-
-                free_and_replace(*s, z);
-        } else
-                free_and_replace(*s, n);
+        r = patch_var_run(unit, filename, line, lvalue, &n);
+        if (r < 0)
+                return r;
 
+        free_and_replace(*s, n);
         return 0;
 }