8d419f
From 13c099caa9ae0389423c403152952c3c548fd146 Mon Sep 17 00:00:00 2001
8d419f
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
8d419f
Date: Thu, 17 Mar 2022 16:02:10 +0100
8d419f
Subject: [PATCH] shared/install: fix handling of a linked unit file
8d419f
8d419f
When we have a symlink that goes outside of our search path, we should just
8d419f
ignore the target file name. But we were verifying it, and rejecting in
8d419f
the case where a symlink was created manually.
8d419f
8d419f
(cherry picked from commit 48eadb9d9b66f302cda09cdf6d35fead31aaa968)
8d419f
8d419f
Related: #2082131
8d419f
---
8d419f
 src/shared/install.c          |  4 +++-
8d419f
 test/test-systemctl-enable.sh | 12 ++++++++----
8d419f
 2 files changed, 11 insertions(+), 5 deletions(-)
8d419f
8d419f
diff --git a/src/shared/install.c b/src/shared/install.c
8d419f
index b33f7d4bc1..d6951b805d 100644
8d419f
--- a/src/shared/install.c
8d419f
+++ b/src/shared/install.c
8d419f
@@ -1609,7 +1609,9 @@ static int install_info_traverse(
8d419f
                                 return -ELOOP;
8d419f
                 }
8d419f
 
8d419f
-                r = install_info_follow(ctx, i, lp, flags, false);
8d419f
+                r = install_info_follow(ctx, i, lp, flags,
8d419f
+                                        /* If linked, don't look at the target name */
8d419f
+                                        /* ignore_different_name= */ i->type == UNIT_FILE_TYPE_LINKED);
8d419f
                 if (r == -EXDEV) {
8d419f
                         _cleanup_free_ char *buffer = NULL;
8d419f
                         const char *bn;
8d419f
diff --git a/test/test-systemctl-enable.sh b/test/test-systemctl-enable.sh
8d419f
index 9463433c5b..45f3513de3 100644
8d419f
--- a/test/test-systemctl-enable.sh
8d419f
+++ b/test/test-systemctl-enable.sh
8d419f
@@ -216,12 +216,16 @@ cat >"$root/link3.suffix" <
8d419f
 WantedBy=services.target
8d419f
 EOF
8d419f
 
8d419f
+# We wouldn't create such a link ourselves, but it should accept it when present.
8d419f
 ln -s "/link3.suffix" "$root/etc/systemd/system/link3.service"
8d419f
 
8d419f
-# SYSTEMD_LOG_LEVEL=debug SYSTEMD_LOG_LOCATION=1 "$systemctl" --root="$root" enable 'link3.service'
8d419f
-# islink "$root/etc/systemd/system/link3.service" "/link3.suffix"
8d419f
-# islink "$root/etc/systemd/system/services.target.wants/link3.service" "../link3.service"
8d419f
-# unit_file_load_or_readlink() needs to be fixed to not follow links
8d419f
+SYSTEMD_LOG_LEVEL=debug SYSTEMD_LOG_LOCATION=1 "$systemctl" --root="$root" enable 'link3.service'
8d419f
+islink "$root/etc/systemd/system/link3.service" "/link3.suffix"
8d419f
+islink "$root/etc/systemd/system/services.target.wants/link3.service" "../link3.service"
8d419f
+
8d419f
+SYSTEMD_LOG_LEVEL=debug SYSTEMD_LOG_LOCATION=1 "$systemctl" --root="$root" disable 'link3.service'
8d419f
+test ! -h "$root/etc/systemd/system/link3.service"
8d419f
+test ! -h "$root/etc/systemd/system/services.target.wants/link3.service"
8d419f
 
8d419f
 : -------enable on masked-------------------------------------
8d419f
 ln -s "/dev/null" "$root/etc/systemd/system/masked.service"