]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/install: fix handling of a linked unit file
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 17 Mar 2022 15:02:10 +0000 (16:02 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 29 Mar 2022 14:17:57 +0000 (16:17 +0200)
When we have a symlink that goes outside of our search path, we should just
ignore the target file name. But we were verifying it, and rejecting in
the case where a symlink was created manually.

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

index 6aacdcf967c58cdf964ac1dc6633f59da2e41a45..20707edf58b0c841092677fedc3b816a22bc98ee 100644 (file)
@@ -1606,7 +1606,9 @@ static int install_info_traverse(
                                 return -ELOOP;
                 }
 
-                r = install_info_follow(ctx, i, lp, flags, false);
+                r = install_info_follow(ctx, i, lp, flags,
+                                        /* If linked, don't look at the target name */
+                                        /* ignore_different_name= */ i->type == UNIT_FILE_TYPE_LINKED);
                 if (r == -EXDEV) {
                         _cleanup_free_ char *buffer = NULL;
                         const char *bn;
index 9463433c5ba4b1af6b0ce33b0fe308dbbe80c820..45f3513de3ac42c1fe61c9b72c0152065c88b2f6 100644 (file)
@@ -216,12 +216,16 @@ cat >"$root/link3.suffix" <<EOF
 WantedBy=services.target
 EOF
 
+# We wouldn't create such a link ourselves, but it should accept it when present.
 ln -s "/link3.suffix" "$root/etc/systemd/system/link3.service"
 
-# SYSTEMD_LOG_LEVEL=debug SYSTEMD_LOG_LOCATION=1 "$systemctl" --root="$root" enable 'link3.service'
-# islink "$root/etc/systemd/system/link3.service" "/link3.suffix"
-# islink "$root/etc/systemd/system/services.target.wants/link3.service" "../link3.service"
-# unit_file_load_or_readlink() needs to be fixed to not follow links
+SYSTEMD_LOG_LEVEL=debug SYSTEMD_LOG_LOCATION=1 "$systemctl" --root="$root" enable 'link3.service'
+islink "$root/etc/systemd/system/link3.service" "/link3.suffix"
+islink "$root/etc/systemd/system/services.target.wants/link3.service" "../link3.service"
+
+SYSTEMD_LOG_LEVEL=debug SYSTEMD_LOG_LOCATION=1 "$systemctl" --root="$root" disable 'link3.service'
+test ! -h "$root/etc/systemd/system/link3.service"
+test ! -h "$root/etc/systemd/system/services.target.wants/link3.service"
 
 : -------enable on masked-------------------------------------
 ln -s "/dev/null" "$root/etc/systemd/system/masked.service"