summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-02-25 01:44:30 +0100
committerLennart Poettering <lennart@poettering.net>2016-04-12 13:43:30 +0200
commitcd64fd56134ef00cce0651e741d4ebda3791d97b (patch)
treedb1476a36d5f19cb423c3219e9fb3c26798e8eef
parent39591351391de3ef2fd23cc5aea5bdd6ab712db6 (diff)
path-lookup: split out logic for mkdir/rmdir of generator dirs in their own functions
-rw-r--r--src/core/manager.c15
-rw-r--r--src/shared/path-lookup.c37
-rw-r--r--src/shared/path-lookup.h3
3 files changed, 40 insertions, 15 deletions
diff --git a/src/core/manager.c b/src/core/manager.c
index 1bc7921abe..d48b41d88f 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -2737,15 +2737,7 @@ static int manager_run_generators(Manager *m) {
return 0;
found:
- r = mkdir_p_label(m->lookup_paths.generator, 0755);
- if (r < 0)
- goto finish;
-
- r = mkdir_p_label(m->lookup_paths.generator_early, 0755);
- if (r < 0)
- goto finish;
-
- r = mkdir_p_label(m->lookup_paths.generator_late, 0755);
+ r = lookup_paths_mkdir_generator(&m->lookup_paths);
if (r < 0)
goto finish;
@@ -2759,10 +2751,7 @@ static int manager_run_generators(Manager *m) {
execute_directories((const char* const*) paths, DEFAULT_TIMEOUT_USEC, (char**) argv);
finish:
- /* Trim empty dirs */
- (void) rmdir(m->lookup_paths.generator);
- (void) rmdir(m->lookup_paths.generator_early);
- (void) rmdir(m->lookup_paths.generator_late);
+ lookup_paths_trim_generator(&m->lookup_paths);
return r;
}
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)