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)
This commit is contained in:
parent
45a7b16bae
commit
45639f1be5
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue