From 45639f1be5f5aeea3c468abe69e38f68d52e39ee Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 23 Nov 2017 17:45:58 +0100 Subject: [PATCH] core: never remove "transient" and "control" directories from unit search path 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 | 7 ------- src/core/unit.c | 4 +++- src/shared/path-lookup.c | 8 ++++++++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/core/manager.c b/src/core/manager.c index ccc3e25..be44ab3 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -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); diff --git a/src/core/unit.c b/src/core/unit.c index 4d0cd6e..a12d24b 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -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; diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c index b40887b..57e0757 100644 --- a/src/shared/path-lookup.c +++ b/src/shared/path-lookup.c @@ -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 -- 2.7.4