]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
install: when linking a file, create the link first or abort
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 11 Mar 2022 13:27:46 +0000 (14:27 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 29 Mar 2022 14:17:56 +0000 (16:17 +0200)
We'd create aliases and other symlinks first, and only then try to create
the main link. Since that can fail, let's do things in opposite order, and
abort immediately if we can't link the file itself.

src/shared/install.c
test/test-systemctl-enable.sh

index bc15b0e9d203ba305700d13a04b72937aba13b87..5dbc267eb8e2053ba5622feeea0a3fa40e654444 100644 (file)
@@ -1980,6 +1980,13 @@ static int install_info_apply(
 
         bool force = file_flags & UNIT_FILE_FORCE;
 
+        r = install_info_symlink_link(info, lp, config_path, force, changes, n_changes);
+        /* Do not count links to the unit file towards the "carries_install_info" count */
+        if (r < 0)
+                /* If linking of the file failed, do not try to create other symlinks,
+                 * because they might would pointing to a non-existent or wrong unit. */
+                return r;
+
         r = install_info_symlink_alias(scope, info, lp, config_path, force, changes, n_changes);
 
         q = install_info_symlink_wants(scope, file_flags, info, lp, config_path, info->wanted_by, ".wants/", changes, n_changes);
@@ -1990,11 +1997,6 @@ static int install_info_apply(
         if (r == 0)
                 r = q;
 
-        q = install_info_symlink_link(info, lp, config_path, force, changes, n_changes);
-        /* Do not count links to the unit file towards the "carries_install_info" count */
-        if (r == 0 && q < 0)
-                r = q;
-
         return r;
 }
 
index 3aa61222a87474209c79d6aa7d0d3cbc5e304658..c1fb9626ab71bcfa6d250f4de945fe7d8ff76618 100644 (file)
@@ -173,12 +173,9 @@ islink "$root/etc/systemd/system/link1.path" "/link1.path"
 islink "$root/etc/systemd/system/paths.target.wants/link1.path" "/link1.path"
 
 : -------enable already linked different path-----------------
-# FIXME
-# "$systemctl" --root="$root" enable '/subdir/link1.path' && { echo "Expected failure" >&2; exit 1; }
-# test -h "$root/etc/systemd/system/link1.path"
-# readlink "$root/etc/systemd/system/link1.path"
-# test -h "$root/etc/systemd/system/paths.target.wants/link1.path"
-# readlink "$root/etc/systemd/system/paths.target.wants/link1.path"
+"$systemctl" --root="$root" enable '/subdir/link1.path' && { echo "Expected failure" >&2; exit 1; }
+islink "$root/etc/systemd/system/link1.path" "/link1.path"
+islink "$root/etc/systemd/system/paths.target.wants/link1.path" "/link1.path"
 
 : -------enable bad suffix------------------------------------
 cp "$root/link1.path" "$root/subdir/link1.suffix"