summaryrefslogtreecommitdiff
path: root/src/portable
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-10-08 17:44:52 +0200
committerLennart Poettering <lennart@poettering.net>2018-10-08 18:49:45 +0200
commitd09d85a2a0899428150eec2ab9083b2e01b0c2d5 (patch)
treebbed23249b7a995a98fa42cc070f38413e4e7d6e /src/portable
parent2ace445da71c30a5f00f379e3915822f7d3dad09 (diff)
downloadsystemd-d09d85a2a0899428150eec2ab9083b2e01b0c2d5.tar.gz
portable: create/remove the 'attached' unit file directory when we can
Let's not litter the system with this unit directory unnecessarily, and let's try to create/remove it when necessary.
Diffstat (limited to 'src/portable')
-rw-r--r--src/portable/portable.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/portable/portable.c b/src/portable/portable.c
index 49eaf84b1a..ca8043b41e 100644
--- a/src/portable/portable.c
+++ b/src/portable/portable.c
@@ -850,14 +850,24 @@ static int attach_unit_file(
assert(PORTABLE_METADATA_IS_UNIT(m));
where = attached_path(paths, flags);
- path = strjoina(where, "/", m->name);
+ (void) mkdir_parents(where, 0755);
+ if (mkdir(where, 0755) < 0) {
+ if (errno != EEXIST)
+ return -errno;
+ } else
+ (void) portable_changes_add(changes, n_changes, PORTABLE_MKDIR, where, NULL);
+
+ path = strjoina(where, "/", m->name);
dropin_dir = strjoin(path, ".d");
if (!dropin_dir)
return -ENOMEM;
- (void) mkdir_p(dropin_dir, 0755);
- (void) portable_changes_add(changes, n_changes, PORTABLE_MKDIR, dropin_dir, NULL);
+ if (mkdir(dropin_dir, 0755) < 0) {
+ if (errno != EEXIST)
+ return -errno;
+ } else
+ (void) portable_changes_add(changes, n_changes, PORTABLE_MKDIR, dropin_dir, NULL);
/* We install the drop-ins first, and the actual unit file last to achieve somewhat atomic behaviour if PID 1
* is reloaded while we are creating things here: as long as only the drop-ins exist the unit doesn't exist at
@@ -1291,6 +1301,10 @@ int portable_detach(
portable_changes_add(changes, n_changes, PORTABLE_UNLINK, sl, NULL);
}
+ /* Try to remove the unit file directory, if we can */
+ if (rmdir(where) >= 0)
+ portable_changes_add(changes, n_changes, PORTABLE_UNLINK, where, NULL);
+
return ret;
not_found: