summaryrefslogtreecommitdiff
path: root/src/shared/install.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-04-21 00:57:50 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-04-21 13:41:59 -0400
commit7d782f265dda805f9e6a533410e17a94b79012e0 (patch)
tree630d3bf0cc2f2fb48aceae48012d530c0981dbdc /src/shared/install.c
parent964b26fe2127d28713bccf03603900a7691216ba (diff)
shared/install: nicer error message is symlinking chokes on an existing file
Fixes #1892. Previously: Failed to enable unit: Invalid argument Now: Failed to enable unit, file /etc/systemd/system/ssh.service already exists. It would be nice to include the unit name in the message too. I looked into this, but it would require major surgery on the whole installation logic, because we first create a list of things to change, and then try to apply them in a loop. To transfer the knowledge which unit was the source of each change, the data structures would have to be extended to carry the unit name over into the second loop. So I'm skipping this for now.
Diffstat (limited to 'src/shared/install.c')
-rw-r--r--src/shared/install.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/shared/install.c b/src/shared/install.c
index 71012eafb4..7a98c2d298 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -370,8 +370,14 @@ static int create_symlink(
}
r = readlink_malloc(new_path, &dest);
- if (r < 0)
+ if (r < 0) {
+ /* translate EINVAL (non-symlink exists) to EEXIST */
+ if (r == -EINVAL)
+ r = -EEXIST;
+
+ unit_file_changes_add(changes, n_changes, r, new_path, NULL);
return r;
+ }
if (path_equal(dest, old_path))
return 0;
@@ -382,8 +388,10 @@ static int create_symlink(
}
r = symlink_atomic(old_path, new_path);
- if (r < 0)
+ if (r < 0) {
+ unit_file_changes_add(changes, n_changes, r, new_path, NULL);
return r;
+ }
unit_file_changes_add(changes, n_changes, UNIT_FILE_UNLINK, new_path, NULL);
unit_file_changes_add(changes, n_changes, UNIT_FILE_SYMLINK, new_path, old_path);