]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
rpm triggers: do nothing if systemd is not running (#5065)
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 12 Jan 2017 09:16:20 +0000 (04:16 -0500)
committerLennart Poettering <lennart@poettering.net>
Thu, 12 Jan 2017 09:16:20 +0000 (10:16 +0100)
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

src/core/triggers.systemd.in

index 0d8c3031360e7dc3f4e3b2528df176cdef866082..f8c8cbc5f991ea9efe667a5e0b0d017cf2980400 100644 (file)
 -- installed, because other cases are covered by the *un scriptlets,
 -- so sometimes we will reload needlessly.
 
-pid = posix.fork()
-if pid == 0 then
-    assert(posix.exec("%{_bindir}/systemctl", "daemon-reload"))
-elseif pid > 0 then
-    posix.wait(pid)
+if posix.access("/run/systemd/system") then
+    pid = posix.fork()
+    if pid == 0 then
+        assert(posix.exec("%{_bindir}/systemctl", "daemon-reload"))
+    elseif pid > 0 then
+        posix.wait(pid)
+    end
 end
 
 %transfiletriggerun -p <lua> -- @systemunitdir@ /etc/systemd/system
@@ -48,10 +50,12 @@ end
 -- file in %transfiletriggerun and execute the daemon-reload in
 -- the first %filetriggerpostun.
 
-posix.mkdir("%{_localstatedir}/lib")
-posix.mkdir("%{_localstatedir}/lib/rpm-state")
-posix.mkdir("%{_localstatedir}/lib/rpm-state/systemd")
-io.open("%{_localstatedir}/lib/rpm-state/systemd/needs-reload", "w")
+if posix.access("/run/systemd/system") then
+    posix.mkdir("%{_localstatedir}/lib")
+    posix.mkdir("%{_localstatedir}/lib/rpm-state")
+    posix.mkdir("%{_localstatedir}/lib/rpm-state/systemd")
+    io.open("%{_localstatedir}/lib/rpm-state/systemd/needs-reload", "w")
+end
 
 %filetriggerpostun -P 1000100 -p <lua> -- @systemunitdir@ /etc/systemd/system
 if posix.access("%{_localstatedir}/lib/rpm-state/systemd/needs-reload") then