From: Zbigniew Jędrzejewski-Szmek Date: Thu, 21 Apr 2016 04:57:50 +0000 (-0400) Subject: shared/install: nicer error message is symlinking chokes on an existing file X-Git-Tag: v230~153^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7d782f265dda805f9e6a533410e17a94b79012e0;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/shared/install.c b/src/shared/install.c index 71012eafb47..7a98c2d298e 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);