ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
3e5297
From d4bd8777a483ea834e687c1ee35dee32efe6e49f Mon Sep 17 00:00:00 2001
3e5297
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
3e5297
Date: Wed, 7 Jul 2021 14:02:36 +0200
3e5297
Subject: [PATCH 1/5] rpm: don't specify the full path for systemctl and other
3e5297
 commands
3e5297
3e5297
We can make things a bit simpler and more readable by not specifying the path.
3e5297
Since we didn't specify the full path for all commands (including those invoked
3e5297
recursively by anythign we invoke), this didn't really privide any security or
3e5297
robustness benefits. I guess that full paths were used because this style of
3e5297
rpm packagnig was popular in the past, with macros used for everything
3e5297
possible, with special macros for common commands like %{__ln} and %{__mkdir}.
3e5297
3e5297
(cherry picked from commit 7d9ee15d0fc2af87481ee371b278dbe7e68165ef)
3e5297
---
3e5297
 src/rpm/macros.systemd.in      | 24 ++++++++++++------------
3e5297
 src/rpm/triggers.systemd.in    | 18 +++++++++---------
3e5297
 src/rpm/triggers.systemd.sh.in | 18 +++++++++---------
3e5297
 3 files changed, 30 insertions(+), 30 deletions(-)
3e5297
3e5297
diff --git a/src/rpm/macros.systemd.in b/src/rpm/macros.systemd.in
3e5297
index 3a0169a85f..3129ab2d61 100644
3e5297
--- a/src/rpm/macros.systemd.in
3e5297
+++ b/src/rpm/macros.systemd.in
3e5297
@@ -46,9 +46,9 @@ OrderWithRequires(postun): systemd \
3e5297
 
3e5297
 %systemd_post() \
3e5297
 %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_post}} \
3e5297
-if [ $1 -eq 1 ] && [ -x %{_bindir}/systemctl ]; then \
3e5297
+if [ $1 -eq 1 ] && command -v systemctl >/dev/null; then \
3e5297
     # Initial installation \
3e5297
-    %{_bindir}/systemctl --no-reload preset %{?*} || : \
3e5297
+    systemctl --no-reload preset %{?*} || : \
3e5297
 fi \
3e5297
 %{nil}
3e5297
 
3e5297
@@ -56,21 +56,21 @@ fi \
3e5297
 
3e5297
 %systemd_preun() \
3e5297
 %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_preun}} \
3e5297
-if [ $1 -eq 0 ] && [ -x %{_bindir}/systemctl ]; then \
3e5297
+if [ $1 -eq 0 ] && command -v systemctl >/dev/null; then \
3e5297
     # Package removal, not upgrade \
3e5297
     if [ -d /run/systemd/system ]; then \
3e5297
-          %{_bindir}/systemctl --no-reload disable --now %{?*} || : \
3e5297
+          systemctl --no-reload disable --now %{?*} || : \
3e5297
     else \
3e5297
-          %{_bindir}/systemctl --no-reload disable %{?*} || : \
3e5297
+          systemctl --no-reload disable %{?*} || : \
3e5297
     fi \
3e5297
 fi \
3e5297
 %{nil}
3e5297
 
3e5297
 %systemd_user_preun() \
3e5297
 %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_preun}} \
3e5297
-if [ $1 -eq 0 ] && [ -x %{_bindir}/systemctl ]; then \
3e5297
+if [ $1 -eq 0 ] && command -v systemctl >/dev/null; then \
3e5297
     # Package removal, not upgrade \
3e5297
-    %{_bindir}/systemctl --global disable %{?*} || : \
3e5297
+    systemctl --global disable %{?*} || : \
3e5297
 fi \
3e5297
 %{nil}
3e5297
 
3e5297
@@ -84,10 +84,10 @@ fi \
3e5297
 
3e5297
 %systemd_postun_with_restart() \
3e5297
 %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_postun_with_restart}} \
3e5297
-if [ $1 -ge 1 ] && [ -x %{_bindir}/systemctl ]; then \
3e5297
+if [ $1 -ge 1 ] && command -v systemctl >/dev/null; then \
3e5297
     # Package upgrade, not uninstall \
3e5297
     for unit in %{?*}; do \
3e5297
-         %{_bindir}/systemctl set-property $unit Markers=+needs-restart || : \
3e5297
+        systemctl set-property $unit Markers=+needs-restart || : \
3e5297
     done \
3e5297
 fi \
3e5297
 %{nil}
3e5297
@@ -105,17 +105,17 @@ fi \
3e5297
 # Deprecated. Use %tmpfiles_create_package instead
3e5297
 %tmpfiles_create() \
3e5297
 %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# tmpfiles_create}} \
3e5297
-[ -x %{_bindir}/systemd-tmpfiles ] && %{_bindir}/systemd-tmpfiles --create %{?*} || : \
3e5297
+command -v systemd-tmpfiles >/dev/null && systemd-tmpfiles --create %{?*} || : \
3e5297
 %{nil}
3e5297
 
3e5297
 # Deprecated. Use %sysusers_create_package instead
3e5297
 %sysusers_create() \
3e5297
 %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# sysusers_create}} \
3e5297
-[ -x %{_bindir}/systemd-sysusers ] && %{_bindir}/systemd-sysusers %{?*} || : \
3e5297
+command -v systemd-sysusers >/dev/null && systemd-sysusers %{?*} || : \
3e5297
 %{nil}
3e5297
 
3e5297
 %sysusers_create_inline() \
3e5297
-[ -x %{_bindir}/systemd-sysusers ] && %{_bindir}/systemd-sysusers - <
3e5297
+command -v systemd-sysusers >/dev/null && systemd-sysusers - <
3e5297
 %{?*} \
3e5297
 SYSTEMD_INLINE_EOF\
3e5297
 %{nil}
3e5297
diff --git a/src/rpm/triggers.systemd.in b/src/rpm/triggers.systemd.in
3e5297
index b33d2212e8..247358008a 100644
3e5297
--- a/src/rpm/triggers.systemd.in
3e5297
+++ b/src/rpm/triggers.systemd.in
3e5297
@@ -16,14 +16,14 @@
3e5297
 if posix.access("/run/systemd/system") then
3e5297
     pid = posix.fork()
3e5297
     if pid == 0 then
3e5297
-        assert(posix.exec("%{_bindir}/systemctl", "daemon-reload"))
3e5297
+        assert(posix.execp("systemctl", "daemon-reload"))
3e5297
     elseif pid > 0 then
3e5297
         posix.wait(pid)
3e5297
     end
3e5297
 
3e5297
     pid = posix.fork()
3e5297
     if pid == 0 then
3e5297
-        assert(posix.exec("%{_bindir}/systemctl", "reload-or-restart", "--marked"))
3e5297
+        assert(posix.execp("systemctl", "reload-or-restart", "--marked"))
3e5297
     elseif pid > 0 then
3e5297
         posix.wait(pid)
3e5297
     end
3e5297
@@ -38,7 +38,7 @@ end
3e5297
 if posix.access("/run/systemd/system") then
3e5297
     pid = posix.fork()
3e5297
     if pid == 0 then
3e5297
-        assert(posix.exec("%{_bindir}/systemctl", "daemon-reload"))
3e5297
+        assert(posix.execp("systemctl", "daemon-reload"))
3e5297
     elseif pid > 0 then
3e5297
         posix.wait(pid)
3e5297
     end
3e5297
@@ -49,7 +49,7 @@ end
3e5297
 if posix.access("/run/systemd/system") then
3e5297
     pid = posix.fork()
3e5297
     if pid == 0 then
3e5297
-        assert(posix.exec("%{_bindir}/systemctl", "reload-or-restart", "--marked"))
3e5297
+        assert(posix.execp("systemctl", "reload-or-restart", "--marked"))
3e5297
     elseif pid > 0 then
3e5297
         posix.wait(pid)
3e5297
     end
3e5297
@@ -62,7 +62,7 @@ end
3e5297
 if posix.access("/run/systemd/system") then
3e5297
     pid = posix.fork()
3e5297
     if pid == 0 then
3e5297
-        assert(posix.exec("%{_bindir}/systemd-sysusers"))
3e5297
+        assert(posix.execp("systemd-sysusers"))
3e5297
     elseif pid > 0 then
3e5297
         posix.wait(pid)
3e5297
     end
3e5297
@@ -74,7 +74,7 @@ end
3e5297
 if posix.access("/run/systemd/system") then
3e5297
     pid = posix.fork()
3e5297
     if pid == 0 then
3e5297
-        assert(posix.exec("%{_bindir}/systemd-hwdb", "update"))
3e5297
+        assert(posix.execp("systemd-hwdb", "update"))
3e5297
     elseif pid > 0 then
3e5297
         posix.wait(pid)
3e5297
     end
3e5297
@@ -86,7 +86,7 @@ end
3e5297
 if posix.access("/run/systemd/system") then
3e5297
     pid = posix.fork()
3e5297
     if pid == 0 then
3e5297
-        assert(posix.exec("%{_bindir}/journalctl", "--update-catalog"))
3e5297
+        assert(posix.execp("journalctl", "--update-catalog"))
3e5297
     elseif pid > 0 then
3e5297
         posix.wait(pid)
3e5297
     end
3e5297
@@ -111,7 +111,7 @@ end
3e5297
 if posix.access("/run/systemd/system") then
3e5297
     pid = posix.fork()
3e5297
     if pid == 0 then
3e5297
-        assert(posix.exec("%{_bindir}/systemd-tmpfiles", "--create"))
3e5297
+        assert(posix.execp("systemd-tmpfiles", "--create"))
3e5297
     elseif pid > 0 then
3e5297
         posix.wait(pid)
3e5297
     end
3e5297
@@ -123,7 +123,7 @@ end
3e5297
 if posix.access("/run/systemd/system") then
3e5297
     pid = posix.fork()
3e5297
     if pid == 0 then
3e5297
-        assert(posix.exec("%{_bindir}/udevadm", "control", "--reload"))
3e5297
+        assert(posix.execp("udevadm", "control", "--reload"))
3e5297
     elseif pid > 0 then
3e5297
         posix.wait(pid)
3e5297
     end
3e5297
diff --git a/src/rpm/triggers.systemd.sh.in b/src/rpm/triggers.systemd.sh.in
3e5297
index 22abad9812..1631be18c9 100644
3e5297
--- a/src/rpm/triggers.systemd.sh.in
3e5297
+++ b/src/rpm/triggers.systemd.sh.in
3e5297
@@ -15,8 +15,8 @@
3e5297
 # installed, because other cases are covered by the *un scriptlets,
3e5297
 # so sometimes we will reload needlessly.
3e5297
 if test -d "/run/systemd/system"; then
3e5297
-  %{_bindir}/systemctl daemon-reload || :
3e5297
-  %{_bindir}/systemctl reload-or-restart --marked || :
3e5297
+  systemctl daemon-reload || :
3e5297
+  systemctl reload-or-restart --marked || :
3e5297
 fi
3e5297
 
3e5297
 %transfiletriggerpostun -P 1000100 -- {{SYSTEM_DATA_UNIT_DIR}} /etc/systemd/system
3e5297
@@ -26,13 +26,13 @@ fi
3e5297
 # have been installed, but before %postun scripts in packages get
3e5297
 # executed.
3e5297
 if test -d "/run/systemd/system"; then
3e5297
-  %{_bindir}/systemctl daemon-reload || :
3e5297
+  systemctl daemon-reload || :
3e5297
 fi
3e5297
 
3e5297
 %transfiletriggerpostun -P 10000 -- {{SYSTEM_DATA_UNIT_DIR}} /etc/systemd/system
3e5297
 # We restart remaining services that should be restarted here.
3e5297
 if test -d "/run/systemd/system"; then
3e5297
-  %{_bindir}/systemctl reload-or-restart --marked || :
3e5297
+  systemctl reload-or-restart --marked || :
3e5297
 fi
3e5297
 
3e5297
 %transfiletriggerin -P 1000700 -- {{SYSUSERS_DIR}}
3e5297
@@ -40,21 +40,21 @@ fi
3e5297
 # specified users automatically. The priority is set such that it
3e5297
 # will run before the tmpfiles file trigger.
3e5297
 if test -d "/run/systemd/system"; then
3e5297
-  %{_bindir}/systemd-sysusers || :
3e5297
+  systemd-sysusers || :
3e5297
 fi
3e5297
 
3e5297
 %transfiletriggerin -P 1000700 udev -- {{UDEV_HWDB_DIR}}
3e5297
 # This script will automatically invoke hwdb update if files have been
3e5297
 # installed or updated in {{UDEV_HWDB_DIR}}.
3e5297
 if test -d "/run/systemd/system"; then
3e5297
-  %{_bindir}/systemd-hwdb update || :
3e5297
+  systemd-hwdb update || :
3e5297
 fi
3e5297
 
3e5297
 %transfiletriggerin -P 1000700 -- {{SYSTEMD_CATALOG_DIR}}
3e5297
 # This script will automatically invoke journal catalog update if files
3e5297
 # have been installed or updated in {{SYSTEMD_CATALOG_DIR}}.
3e5297
 if test -d "/run/systemd/system"; then
3e5297
-  %{_bindir}/journalctl --update-catalog || :
3e5297
+  journalctl --update-catalog || :
3e5297
 fi
3e5297
 
3e5297
 %transfiletriggerin -P 1000700 -- {{BINFMT_DIR}}
3e5297
@@ -71,14 +71,14 @@ fi
3e5297
 # tmpfiles automatically. The priority is set such that it will run
3e5297
 # after the sysusers file trigger, but before any other triggers.
3e5297
 if test -d "/run/systemd/system"; then
3e5297
-  %{_bindir}/systemd-tmpfiles --create || :
3e5297
+  systemd-tmpfiles --create || :
3e5297
 fi
3e5297
 
3e5297
 %transfiletriggerin -P 1000600 udev -- {{UDEV_RULES_DIR}}
3e5297
 # This script will automatically update udev with new rules if files
3e5297
 # have been installed or updated in {{UDEV_RULES_DIR}}.
3e5297
 if test -e /run/udev/control; then
3e5297
-  %{_bindir}/udevadm control --reload || :
3e5297
+  udevadm control --reload || :
3e5297
 fi
3e5297
 
3e5297
 %transfiletriggerin -P 1000500 -- {{SYSCTL_DIR}}
3e5297
-- 
3e5297
2.31.1
3e5297