diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-03-24 12:17:43 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-03-27 20:12:44 +0100 |
commit | 385093b702d5950e7f7203405fc152206b8d77e1 (patch) | |
tree | 229fb3c4e66e3d8e167c6cb336219a40eff25b05 /src/core | |
parent | sd-path,strv: add simple helper to wrap oom handling around strv_split_nulstr() (diff) | |
download | systemd-385093b702d5950e7f7203405fc152206b8d77e1.tar.xz systemd-385093b702d5950e7f7203405fc152206b8d77e1.zip |
Split out generator directory setup to a src/core/generator-setup.c
Those functions have only one non-test user, so we can move them to src/core/.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/generator-setup.c | 58 | ||||
-rw-r--r-- | src/core/generator-setup.h | 8 | ||||
-rw-r--r-- | src/core/manager.c | 1 | ||||
-rw-r--r-- | src/core/meson.build | 2 |
4 files changed, 69 insertions, 0 deletions
diff --git a/src/core/generator-setup.c b/src/core/generator-setup.c new file mode 100644 index 0000000000..78ff590902 --- /dev/null +++ b/src/core/generator-setup.c @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + +#include <unistd.h> + +#include "generator-setup.h" +#include "macro.h" +#include "mkdir.h" +#include "rm-rf.h" + +int lookup_paths_mkdir_generator(LookupPaths *p) { + int r, q; + + assert(p); + + if (!p->generator || !p->generator_early || !p->generator_late) + return -EINVAL; + + r = mkdir_p_label(p->generator, 0755); + + q = mkdir_p_label(p->generator_early, 0755); + if (q < 0 && r >= 0) + r = q; + + q = mkdir_p_label(p->generator_late, 0755); + if (q < 0 && r >= 0) + r = q; + + return r; +} + +void lookup_paths_trim_generator(LookupPaths *p) { + assert(p); + + /* Trim empty dirs */ + + if (p->generator) + (void) rmdir(p->generator); + if (p->generator_early) + (void) rmdir(p->generator_early); + if (p->generator_late) + (void) rmdir(p->generator_late); +} + +void lookup_paths_flush_generator(LookupPaths *p) { + assert(p); + + /* Flush the generated unit files in full */ + + if (p->generator) + (void) rm_rf(p->generator, REMOVE_ROOT|REMOVE_PHYSICAL); + if (p->generator_early) + (void) rm_rf(p->generator_early, REMOVE_ROOT|REMOVE_PHYSICAL); + if (p->generator_late) + (void) rm_rf(p->generator_late, REMOVE_ROOT|REMOVE_PHYSICAL); + + if (p->temporary_dir) + (void) rm_rf(p->temporary_dir, REMOVE_ROOT|REMOVE_PHYSICAL); +} diff --git a/src/core/generator-setup.h b/src/core/generator-setup.h new file mode 100644 index 0000000000..9688601a76 --- /dev/null +++ b/src/core/generator-setup.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +#pragma once + +#include "path-lookup.h" + +int lookup_paths_mkdir_generator(LookupPaths *p); +void lookup_paths_trim_generator(LookupPaths *p); +void lookup_paths_flush_generator(LookupPaths *p); diff --git a/src/core/manager.c b/src/core/manager.c index 4c59addfc8..148df8d523 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -44,6 +44,7 @@ #include "fd-util.h" #include "fileio.h" #include "fs-util.h" +#include "generator-setup.h" #include "hashmap.h" #include "install.h" #include "io-util.h" diff --git a/src/core/meson.build b/src/core/meson.build index 3586838f59..0b31bb79ed 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -72,6 +72,8 @@ libcore_sources = ''' emergency-action.h execute.c execute.h + generator-setup.c + generator-setup.h hostname-setup.c hostname-setup.h ima-setup.c |