teknoraver / rpms / systemd

Forked from rpms/systemd a month ago
Clone

Blame SOURCES/0198-shared-install-fix-handling-of-a-linked-unit-file.patch

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