]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: never remove "transient" and "control" directories from unit search path
authorLennart Poettering <lennart@poettering.net>
Thu, 23 Nov 2017 16:45:58 +0000 (17:45 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 29 Nov 2017 11:34:12 +0000 (12:34 +0100)
This changes the unit search path logic to never drop the transient and
control directories from the unit search path. This is necessary as we
add new entries to both during runtime, due to the "systemctl
set-property" and transient unit logic.

Previously, the "transient" directory was created during early boot to
deal with this, but the "control" directories were not covered like
that. Creating the control directories early at boot is not possible
however, as /etc might be read-only then, and we do define a persistent
control directory. Hence, let's create these dirs on-demand when we need
them, and make sure the search path clean-up logic never drops them from
the search path even if they are initially missing.

(Also, always create these paths properly labelled)

src/core/manager.c
src/core/unit.c
src/shared/path-lookup.c

index ccc3e254fda54226db431c6daeb9f21002392b6d..be44ab3778daac3c6549c41e4dabfb97c3ed5d8b 100644 (file)
@@ -1336,13 +1336,6 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
         if (r < 0)
                 return r;
 
-        /* Make sure the transient directory always exists, so that it remains
-         * in the search path */
-        r = mkdir_p_label(m->lookup_paths.transient, 0755);
-        if (r < 0)
-                return log_error_errno(r, "Failed to create transient generator directory \"%s\": %m",
-                                       m->lookup_paths.transient);
-
         dual_timestamp_get(m->timestamps + MANAGER_TIMESTAMP_GENERATORS_START);
         r = manager_run_generators(m);
         dual_timestamp_get(m->timestamps + MANAGER_TIMESTAMP_GENERATORS_FINISH);
index 4d0cd6e65db0ef7ae74110deaf81eac4bbf9307d..a12d24b90b853b0b7ad78ee342c40e17857873cf 100644 (file)
@@ -4285,7 +4285,7 @@ int unit_write_setting(Unit *u, UnitWriteFlags flags, const char *name, const ch
         if (r < 0)
                 return r;
 
-        (void) mkdir_p(p, 0755);
+        (void) mkdir_p_label(p, 0755);
         r = write_string_file_atomic_label(q, wrapped);
         if (r < 0)
                 return r;
@@ -4333,6 +4333,8 @@ int unit_make_transient(Unit *u) {
         if (!UNIT_VTABLE(u)->can_transient)
                 return -EOPNOTSUPP;
 
+        (void) mkdir_p_label(u->manager->lookup_paths.transient, 0755);
+
         path = strjoin(u->manager->lookup_paths.transient, "/", u->id);
         if (!path)
                 return -ENOMEM;
index b40887bfbd3a1695541f1d64f4d898576476dc01..57e0757529e86602af157fcdac0488d27e142f3e 100644 (file)
@@ -736,6 +736,14 @@ int lookup_paths_reduce(LookupPaths *p) {
                 struct stat st;
                 unsigned k;
 
+                /* Never strip the transient and control directories from the path */
+                if (path_equal_ptr(p->search_path[c], p->transient) ||
+                    path_equal_ptr(p->search_path[c], p->persistent_control) ||
+                    path_equal_ptr(p->search_path[c], p->runtime_control)) {
+                        c++;
+                        continue;
+                }
+
                 if (p->root_dir)
                         r = lstat(p->search_path[c], &st);
                 else