Skip to content

Commit 13749f5

Browse files
keszybzpoettering
authored andcommitted
rpm triggers: do nothing if systemd is not running (systemd#5065)
If we are running in a chroot/container/..., we would print a useless warning about not being able to communicate with systemd. Trying to do daemon-reload is pointless in those cases, so let's just skip all actions in that case. The check uses /run/system/system, as recommended by sd_booted(3). https://bugzilla.redhat.com/show_bug.cgi?id=1411299
1 parent a69f65d commit 13749f5

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/core/triggers.systemd.in

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
-- installed, because other cases are covered by the *un scriptlets,
2828
-- so sometimes we will reload needlessly.
2929

30-
pid = posix.fork()
31-
if pid == 0 then
32-
assert(posix.exec("%{_bindir}/systemctl", "daemon-reload"))
33-
elseif pid > 0 then
34-
posix.wait(pid)
30+
if posix.access("/run/systemd/system") then
31+
pid = posix.fork()
32+
if pid == 0 then
33+
assert(posix.exec("%{_bindir}/systemctl", "daemon-reload"))
34+
elseif pid > 0 then
35+
posix.wait(pid)
36+
end
3537
end
3638

3739
%transfiletriggerun -p <lua> -- @systemunitdir@ /etc/systemd/system
@@ -48,10 +50,12 @@ end
4850
-- file in %transfiletriggerun and execute the daemon-reload in
4951
-- the first %filetriggerpostun.
5052

51-
posix.mkdir("%{_localstatedir}/lib")
52-
posix.mkdir("%{_localstatedir}/lib/rpm-state")
53-
posix.mkdir("%{_localstatedir}/lib/rpm-state/systemd")
54-
io.open("%{_localstatedir}/lib/rpm-state/systemd/needs-reload", "w")
53+
if posix.access("/run/systemd/system") then
54+
posix.mkdir("%{_localstatedir}/lib")
55+
posix.mkdir("%{_localstatedir}/lib/rpm-state")
56+
posix.mkdir("%{_localstatedir}/lib/rpm-state/systemd")
57+
io.open("%{_localstatedir}/lib/rpm-state/systemd/needs-reload", "w")
58+
end
5559

5660
%filetriggerpostun -P 1000100 -p <lua> -- @systemunitdir@ /etc/systemd/system
5761
if posix.access("%{_localstatedir}/lib/rpm-state/systemd/needs-reload") then

0 commit comments

Comments
 (0)