summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/path-lookup.c37
-rw-r--r--src/shared/path-lookup.h3
2 files changed, 38 insertions, 2 deletions
diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c
index f437de370c..083e467475 100644
--- a/src/shared/path-lookup.c
+++ b/src/shared/path-lookup.c
@@ -26,6 +26,7 @@
#include "install.h"
#include "log.h"
#include "macro.h"
+#include "mkdir.h"
#include "path-lookup.h"
#include "path-util.h"
#include "stat-util.h"
@@ -457,8 +458,7 @@ int lookup_paths_init(
if (r < 0 && r != -EOPNOTSUPP && r != -ENXIO)
return r;
- /* First priority is whatever has been passed to us via env
- * vars */
+ /* First priority is whatever has been passed to us via env vars */
e = getenv("SYSTEMD_UNIT_PATH");
if (e) {
const char *k;
@@ -633,3 +633,36 @@ void lookup_paths_free(LookupPaths *p) {
p->root_dir = mfree(p->root_dir);
}
+
+int lookup_paths_mkdir_generator(LookupPaths *p) {
+ int r, q;
+
+ assert(p);
+
+ 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);
+}
diff --git a/src/shared/path-lookup.h b/src/shared/path-lookup.h
index b0603c0c99..27be1d8be8 100644
--- a/src/shared/path-lookup.h
+++ b/src/shared/path-lookup.h
@@ -52,5 +52,8 @@ char **generator_paths(UnitFileScope scope);
int lookup_paths_init(LookupPaths *p, UnitFileScope scope, const char *root_dir);
+int lookup_paths_mkdir_generator(LookupPaths *p);
+void lookup_paths_trim_generator(LookupPaths *p);
+
void lookup_paths_free(LookupPaths *p);
#define _cleanup_lookup_paths_free_ _cleanup_(lookup_paths_free)