diff --git a/src/core/service.c b/src/core/service.c index 792ec99a00..af5a2decf1 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -668,7 +668,8 @@ static int service_setup_bus_name(Service *s) { assert(s); - if (s->type != SERVICE_DBUS) + /* If s->bus_name is not set, then the unit will be refused by service_verify() later. */ + if (s->type != SERVICE_DBUS || !s->bus_name) return 0; r = unit_add_dependency_by_name(UNIT(s), UNIT_REQUIRES, SPECIAL_DBUS_SOCKET, true, UNIT_DEPENDENCY_FILE); diff --git a/test/units/testsuite-42.sh b/test/units/testsuite-42.sh index e47fab46e6..4e6be7e06e 100755 --- a/test/units/testsuite-42.sh +++ b/test/units/testsuite-42.sh @@ -65,6 +65,10 @@ test -f /run/dbus1 systemd-run --unit=dbus2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=dbus -p BusName=systemd.test.ExecStopPost -p ExecStopPost='/bin/touch /run/dbus2' true test -f /run/dbus2 +# https://github.com/systemd/systemd/issues/19920 +systemd-run --unit=dbus3.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=dbus -p ExecStopPost='/bin/touch /run/dbus3' true \ + && { echo 'unexpected success'; exit 1; } + cat >/tmp/notify1.sh <