summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-06-17 00:11:47 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-06-22 22:45:58 -0400
commitb533ed36a5ca33ba718ad37b18d1aa175f232d03 (patch)
tree6d95c7d8a8efccb40c9935557fad5c665f251d1f
parentf906059875069ef0b72e54581d78fe4e28b375a3 (diff)
install: use symlink_atomic() instead of unlink()+symlink() when force creating a symlink
(cherry picked from commit 1f8c46040e824d7367c2f013de13c87d53f249dc)
-rw-r--r--src/shared/install.c27
1 files changed, 8 insertions, 19 deletions
diff --git a/src/shared/install.c b/src/shared/install.c
index 0f49f2a9b..f0d3d1b7d 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -603,13 +603,9 @@ int unit_file_mask(
continue;
if (force) {
- unlink(path);
-
- if (symlink("/dev/null", path) >= 0) {
-
+ if (symlink_atomic("/dev/null", path) >= 0) {
add_file_change(changes, n_changes, UNIT_FILE_UNLINK, path, NULL);
add_file_change(changes, n_changes, UNIT_FILE_SYMLINK, path, "/dev/null");
-
continue;
}
}
@@ -770,13 +766,9 @@ int unit_file_link(
continue;
if (force) {
- unlink(path);
-
- if (symlink(*i, path) >= 0) {
-
+ if (symlink_atomic(*i, path) >= 0) {
add_file_change(changes, n_changes, UNIT_FILE_UNLINK, path, NULL);
add_file_change(changes, n_changes, UNIT_FILE_SYMLINK, path, *i);
-
continue;
}
}
@@ -1172,17 +1164,14 @@ static int create_symlink(
if (!force)
return -EEXIST;
- r = unlink(new_path);
- if (r < 0 && errno != ENOENT)
- return -errno;
+ r = symlink_atomic(old_path, new_path);
+ if (r < 0)
+ return r;
- if (symlink(old_path, new_path) >= 0) {
- add_file_change(changes, n_changes, UNIT_FILE_UNLINK, new_path, NULL);
- add_file_change(changes, n_changes, UNIT_FILE_SYMLINK, new_path, old_path);
- return 0;
- }
+ add_file_change(changes, n_changes, UNIT_FILE_UNLINK, new_path, NULL);
+ add_file_change(changes, n_changes, UNIT_FILE_SYMLINK, new_path, old_path);
- return -errno;
+ return 0;
}
static int install_info_symlink_alias(