run: fix generated unit name clash after soft-reboot
When sd-run connects to D-Bus rather than the private socket, it will generate the transient unit name using the bus ID assigned by the D-Bus broker/daemon. The issue is that this ID is only unique per D-Bus run, if the broker/daemon restarts it starts again from 1, and it's a simple incremental counter for each client. So if a transient unit run-u6.service starts and fails, and it is not collected (default on failure), and the system soft-reboots, any new transient unit might conflict as the counter will restart: Failed to start transient service unit: Unit run-u6.service was already loaded or has a fragment file. Get the soft-reboot counter, and if it's greater than zero, append it to the autogenerated unit name to avoid clashes.
This commit is contained in:
committed by
Yu Watanabe
parent
2a4fb037cb
commit
ed35851693
@@ -146,6 +146,11 @@ elif [ -f /run/testsuite82.touch ]; then
|
||||
# Restart the unit that is not supposed to survive
|
||||
systemd-run --collect --service-type=exec --unit=testsuite-82-nosurvive.service sleep infinity
|
||||
|
||||
# Now ensure there are no naming clashes and a bunch of transient units all succeed
|
||||
for _ in $(seq 1 25); do
|
||||
systemd-run --wait true
|
||||
done
|
||||
|
||||
# Now issue the soft reboot. We should be right back soon. Given /run/nextroot exists, we should
|
||||
# automatically do a softreboot instead of normal reboot.
|
||||
touch /run/testsuite82.touch2
|
||||
@@ -227,6 +232,14 @@ EOF
|
||||
systemd-inhibit --what=shutdown --who=test --why=test --mode=delay \
|
||||
sleep infinity
|
||||
|
||||
# Enqueue a bunch of failing units to try and trigger the transient name clash that happens due to D-Bus
|
||||
# being restarted and the "unique" bus IDs not being unique across restarts
|
||||
for _ in $(seq 1 25); do
|
||||
# Use --wait to ensure we connect to the system bus instead of the private bus (otherwise a UUID is
|
||||
# used instead of the bus ID)
|
||||
systemd-run --wait false || true
|
||||
done
|
||||
|
||||
# Now issue the soft reboot. We should be right back soon.
|
||||
touch /run/testsuite82.touch
|
||||
systemctl --no-block --check-inhibitors=yes soft-reboot
|
||||
|
||||
Reference in New Issue
Block a user