5d6eedd
From fba761f0bc86d37119bd18f7bc231e2d9f5d94a7 Mon Sep 17 00:00:00 2001
03e93e2
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
03e93e2
Date: Thu, 12 Jan 2017 04:16:20 -0500
03e93e2
Subject: [PATCH] rpm triggers: do nothing if systemd is not running (#5065)
03e93e2
03e93e2
If we are running in a chroot/container/..., we would print a useless warning about
03e93e2
not being able to communicate with systemd. Trying to do daemon-reload is pointless
03e93e2
in those cases, so let's just skip all actions in that case.
03e93e2
03e93e2
The check uses /run/system/system, as recommended by sd_booted(3).
03e93e2
03e93e2
https://bugzilla.redhat.com/show_bug.cgi?id=1411299
03e93e2
(cherry picked from commit 13749f547357f8e9ec398680548f818dea3aba1c)
03e93e2
---
03e93e2
 src/core/triggers.systemd.in | 22 +++++++++++++---------
03e93e2
 1 file changed, 13 insertions(+), 9 deletions(-)
03e93e2
03e93e2
diff --git a/src/core/triggers.systemd.in b/src/core/triggers.systemd.in
03e93e2
index 0d8c303136..f8c8cbc5f9 100644
03e93e2
--- a/src/core/triggers.systemd.in
03e93e2
+++ b/src/core/triggers.systemd.in
03e93e2
@@ -27,11 +27,13 @@
03e93e2
 -- installed, because other cases are covered by the *un scriptlets,
03e93e2
 -- so sometimes we will reload needlessly.
03e93e2
 
03e93e2
-pid = posix.fork()
03e93e2
-if pid == 0 then
03e93e2
-    assert(posix.exec("%{_bindir}/systemctl", "daemon-reload"))
03e93e2
-elseif pid > 0 then
03e93e2
-    posix.wait(pid)
03e93e2
+if posix.access("/run/systemd/system") then
03e93e2
+    pid = posix.fork()
03e93e2
+    if pid == 0 then
03e93e2
+        assert(posix.exec("%{_bindir}/systemctl", "daemon-reload"))
03e93e2
+    elseif pid > 0 then
03e93e2
+        posix.wait(pid)
03e93e2
+    end
03e93e2
 end
03e93e2
 
03e93e2
 %transfiletriggerun -p <lua> -- @systemunitdir@ /etc/systemd/system
03e93e2
@@ -48,10 +50,12 @@ end
03e93e2
 -- file in %transfiletriggerun and execute the daemon-reload in
03e93e2
 -- the first %filetriggerpostun.
03e93e2
 
03e93e2
-posix.mkdir("%{_localstatedir}/lib")
03e93e2
-posix.mkdir("%{_localstatedir}/lib/rpm-state")
03e93e2
-posix.mkdir("%{_localstatedir}/lib/rpm-state/systemd")
03e93e2
-io.open("%{_localstatedir}/lib/rpm-state/systemd/needs-reload", "w")
03e93e2
+if posix.access("/run/systemd/system") then
03e93e2
+    posix.mkdir("%{_localstatedir}/lib")
03e93e2
+    posix.mkdir("%{_localstatedir}/lib/rpm-state")
03e93e2
+    posix.mkdir("%{_localstatedir}/lib/rpm-state/systemd")
03e93e2
+    io.open("%{_localstatedir}/lib/rpm-state/systemd/needs-reload", "w")
03e93e2
+end
03e93e2
 
03e93e2
 %filetriggerpostun -P 1000100 -p <lua> -- @systemunitdir@ /etc/systemd/system
03e93e2
 if posix.access("%{_localstatedir}/lib/rpm-state/systemd/needs-reload") then