diff options
author | William Douglas <william.r.douglas@gmail.com> | 2017-08-09 17:53:03 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-08-09 17:53:03 +0200 |
commit | b3f5897f6e46f6dc54d9f46ea16258f558173500 (patch) | |
tree | e8b97db3893aeaa4bd235e4d1364b320ac5a82af /src/tmpfiles/tmpfiles.c | |
parent | Merge pull request #6497 from yuwata/bus-prop (diff) | |
download | systemd-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.c | 9 |
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); |