summaryrefslogtreecommitdiffstats
path: root/src/tmpfiles/tmpfiles.c
diff options
context:
space:
mode:
authorWilliam Douglas <william.r.douglas@gmail.com>2017-08-09 17:53:03 +0200
committerLennart Poettering <lennart@poettering.net>2017-08-09 17:53:03 +0200
commitb3f5897f6e46f6dc54d9f46ea16258f558173500 (patch)
treee8b97db3893aeaa4bd235e4d1364b320ac5a82af /src/tmpfiles/tmpfiles.c
parentMerge pull request #6497 from yuwata/bus-prop (diff)
downloadsystemd-b3f5897f6e46f6dc54d9f46ea16258f558173500.tar.xz
systemd-b3f5897f6e46f6dc54d9f46ea16258f558173500.zip
tmpfiles: Allow create symlink on directories (#6039)
Currently if tmpfiles is run with force on symlink creation but there already exists a directory at that location, the creation will fail. This change updates the behavior to remove the directory with rm_fr and then attempts to create the symlink again.
Diffstat (limited to 'src/tmpfiles/tmpfiles.c')
-rw-r--r--src/tmpfiles/tmpfiles.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 9419c99e28..2ab0cd1270 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -1353,6 +1353,15 @@ static int create_item(Item *i) {
r = symlink_atomic(resolved, i->path);
mac_selinux_create_file_clear();
+ if (IN_SET(r, -EEXIST, -ENOTEMPTY)) {
+ r = rm_rf(i->path, REMOVE_ROOT|REMOVE_PHYSICAL);
+ if (r < 0)
+ return log_error_errno(r, "rm -fr %s failed: %m", i->path);
+
+ mac_selinux_create_file_prepare(i->path, S_IFLNK);
+ r = symlink(resolved, i->path) < 0 ? -errno : 0;
+ mac_selinux_create_file_clear();
+ }
if (r < 0)
return log_error_errno(r, "symlink(%s, %s) failed: %m", resolved, i->path);