From 2fd7ecd2da699d2fece777062e408b62162768f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 16 May 2022 20:06:59 +0200 Subject: [PATCH] rpm: remove check if systemd is running in a few cases rpms can be installed in two different modes: into a chroot, where the system is not running, and onto a live system. In the first mode, where should create all changes that are "permanent", and in the second mode, all changes which are "permanent" but also those which only affect the running system. Thus, changes like new modprobe rules, tmpfiles rules, binfmt rules, udev rules, etc., are guarded by 'test -d "/run/systemd/system"' which is the official way to check if systemd is running, so that they are *not* executed when installed into a chroot. But the same logic does not apply to sysusers, hwdb, and the journal catalog: all those files can and should result in changes being performed immediately to the system. This makes the creation of immutable images possible (because there are no permanent changes to executed after a reboot), and allows other packages to depend on the the effect of those changes. Thus, the guard to check if we're not in a chroot is dropped from triggers for sysusers, hwdb, and the journal catalog. This means that those triggers will execute, and no subsequent work is needed. systemd-sysusers.service, systemd-journal-catalog-update.service, and systemd-hwdb-update.service.in all have ConditionNeedsUpdate= so they they generally won't be invoked after a reboot. (systemd.rpm does not touch /usr to trigger the condition, because the %transfiletriggers make that unnecessary.) https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=2085481 --- src/rpm/triggers.systemd.in | 36 ++++++++++++++-------------------- src/rpm/triggers.systemd.sh.in | 12 +++--------- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/rpm/triggers.systemd.in b/src/rpm/triggers.systemd.in index 8aeb2049c1..4755cdafe8 100644 --- a/src/rpm/triggers.systemd.in +++ b/src/rpm/triggers.systemd.in @@ -72,37 +72,31 @@ end -- This script will process files installed in {{SYSUSERS_DIR}} to create -- specified users automatically. The priority is set such that it -- will run before the tmpfiles file trigger. -if posix.access("/run/systemd/system") then - pid = posix.fork() - if pid == 0 then - assert(posix.execp("systemd-sysusers")) - elseif pid > 0 then - posix.wait(pid) - end +pid = posix.fork() +if pid == 0 then + assert(posix.execp("systemd-sysusers")) +elseif pid > 0 then + posix.wait(pid) end %transfiletriggerin -P 1000700 udev -p -- {{UDEV_HWDB_DIR}} -- This script will automatically invoke hwdb update if files have been -- installed or updated in {{UDEV_HWDB_DIR}}. -if posix.access("/run/systemd/system") then - pid = posix.fork() - if pid == 0 then - assert(posix.execp("systemd-hwdb", "update")) - elseif pid > 0 then - posix.wait(pid) - end +pid = posix.fork() +if pid == 0 then + assert(posix.execp("systemd-hwdb", "update")) +elseif pid > 0 then + posix.wait(pid) end %transfiletriggerin -P 1000700 -p -- {{SYSTEMD_CATALOG_DIR}} -- This script will automatically invoke journal catalog update if files -- have been installed or updated in {{SYSTEMD_CATALOG_DIR}}. -if posix.access("/run/systemd/system") then - pid = posix.fork() - if pid == 0 then - assert(posix.execp("journalctl", "--update-catalog")) - elseif pid > 0 then - posix.wait(pid) - end +pid = posix.fork() +if pid == 0 then + assert(posix.execp("journalctl", "--update-catalog")) +elseif pid > 0 then + posix.wait(pid) end %transfiletriggerin -P 1000700 -p -- {{BINFMT_DIR}} diff --git a/src/rpm/triggers.systemd.sh.in b/src/rpm/triggers.systemd.sh.in index 694cd94e8d..8c301f5ed9 100644 --- a/src/rpm/triggers.systemd.sh.in +++ b/src/rpm/triggers.systemd.sh.in @@ -43,23 +43,17 @@ # This script will process files installed in {{SYSUSERS_DIR}} to create # specified users automatically. The priority is set such that it # will run before the tmpfiles file trigger. -if test -d "/run/systemd/system"; then - systemd-sysusers || : -fi +systemd-sysusers || : %transfiletriggerin -P 1000700 udev -- {{UDEV_HWDB_DIR}} # This script will automatically invoke hwdb update if files have been # installed or updated in {{UDEV_HWDB_DIR}}. -if test -d "/run/systemd/system"; then - systemd-hwdb update || : -fi +systemd-hwdb update || : %transfiletriggerin -P 1000700 -- {{SYSTEMD_CATALOG_DIR}} # This script will automatically invoke journal catalog update if files # have been installed or updated in {{SYSTEMD_CATALOG_DIR}}. -if test -d "/run/systemd/system"; then - journalctl --update-catalog || : -fi +journalctl --update-catalog || : %transfiletriggerin -P 1000700 -- {{BINFMT_DIR}} # This script will automatically apply binfmt rules if files have been