X Tutup
Skip to content

Commit 48eadb9

Browse files
committed
shared/install: fix handling of a linked unit file
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.
1 parent 48ed75a commit 48eadb9

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/shared/install.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,9 @@ static int install_info_traverse(
16061606
return -ELOOP;
16071607
}
16081608

1609-
r = install_info_follow(ctx, i, lp, flags, false);
1609+
r = install_info_follow(ctx, i, lp, flags,
1610+
/* If linked, don't look at the target name */
1611+
/* ignore_different_name= */ i->type == UNIT_FILE_TYPE_LINKED);
16101612
if (r == -EXDEV) {
16111613
_cleanup_free_ char *buffer = NULL;
16121614
const char *bn;

test/test-systemctl-enable.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,16 @@ cat >"$root/link3.suffix" <<EOF
216216
WantedBy=services.target
217217
EOF
218218

219+
# We wouldn't create such a link ourselves, but it should accept it when present.
219220
ln -s "/link3.suffix" "$root/etc/systemd/system/link3.service"
220221

221-
# SYSTEMD_LOG_LEVEL=debug SYSTEMD_LOG_LOCATION=1 "$systemctl" --root="$root" enable 'link3.service'
222-
# islink "$root/etc/systemd/system/link3.service" "/link3.suffix"
223-
# islink "$root/etc/systemd/system/services.target.wants/link3.service" "../link3.service"
224-
# unit_file_load_or_readlink() needs to be fixed to not follow links
222+
SYSTEMD_LOG_LEVEL=debug SYSTEMD_LOG_LOCATION=1 "$systemctl" --root="$root" enable 'link3.service'
223+
islink "$root/etc/systemd/system/link3.service" "/link3.suffix"
224+
islink "$root/etc/systemd/system/services.target.wants/link3.service" "../link3.service"
225+
226+
SYSTEMD_LOG_LEVEL=debug SYSTEMD_LOG_LOCATION=1 "$systemctl" --root="$root" disable 'link3.service'
227+
test ! -h "$root/etc/systemd/system/link3.service"
228+
test ! -h "$root/etc/systemd/system/services.target.wants/link3.service"
225229

226230
: -------enable on masked-------------------------------------
227231
ln -s "/dev/null" "$root/etc/systemd/system/masked.service"

0 commit comments

Comments
 (0)
X Tutup