]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/install: nicer error message is symlinking chokes on an existing file
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 21 Apr 2016 04:57:50 +0000 (00:57 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 21 Apr 2016 17:41:59 +0000 (13:41 -0400)
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.

src/shared/install.c

index 71012eafb47204fa68304712ddf55434f160ad91..7a98c2d298e42737088fd7a571d9a58530cd21ca 100644 (file)
@@ -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);