]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/basic/unit-file.c
basic/unit-file: fix detection of instance aliases
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 28 Apr 2021 15:06:19 +0000 (17:06 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 4 May 2021 15:59:34 +0000 (17:59 +0200)
commitfd22838734c000933f7c9ca2617398a19b91a80e
tree77f35595e8791510acb95d09de469aefa3b0b51f
parent32464e18b4014e4d3f4996b73be7a9348df83c5b
basic/unit-file: fix detection of instance aliases

We had the following scenario:
under /etc/systemd/system/
- foo@.service
- bar@tty12.service → foo@tty12.service
- multi-user.target.wants/foo@tty12.service

Existing code did not "know" that foo@tty12.service has alias bar@tty12.service:
$ systemctl show -P Names foo@tty12.service
foo@tty12.service

Since multi-user.target is always loaded, we would load foo@tty12.service.
When trying to load bar@tty12.service, it would (correctly) detect that
bar@tty12.service is an alias for foo@tty12.service, and try to merge the
bar@tty12.service unit into the foo@tty12.service. This would fail, because
foo@tty12.service was already loaded, and only about-to-be-loaded units can
be merged.

With the patch we consider bar@tty12.service an alias of foo@tty12.service
immediately, so the issue does not occur:
$ systemctl show -P Names foo@tty12.service
foo@tty12.service bar@tty12.service

Fixes #19409.

This turned in a bigger rewrite. The logic add "the main name and all aliases"
was implemented twice, slightly different in both cases. I split that part out
to a new function. The result about the same length, but hopefully a bit easier
to read.

Logging output is also improved a bit. Some left-over debug logs have been
removed or cleaned up.

This is a fairly big change, but (with the addition in the following commit),
we have pretty good coverage of this logic.
src/basic/unit-file.c