X Tutup
Skip to content

Commit 7d9ee15

Browse files
committed
rpm: don't specify the full path for systemctl and other commands
We can make things a bit simpler and more readable by not specifying the path. Since we didn't specify the full path for all commands (including those invoked recursively by anythign we invoke), this didn't really privide any security or robustness benefits. I guess that full paths were used because this style of rpm packagnig was popular in the past, with macros used for everything possible, with special macros for common commands like %{__ln} and %{__mkdir}.
1 parent 3cfd5dd commit 7d9ee15

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

src/rpm/macros.systemd.in

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,31 @@ OrderWithRequires(postun): systemd \
4646

4747
%systemd_post() \
4848
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_post}} \
49-
if [ $1 -eq 1 ] && [ -x %{_bindir}/systemctl ]; then \
49+
if [ $1 -eq 1 ] && command -v systemctl >/dev/null; then \
5050
# Initial installation \
51-
%{_bindir}/systemctl --no-reload preset %{?*} || : \
51+
systemctl --no-reload preset %{?*} || : \
5252
fi \
5353
%{nil}
5454

5555
%systemd_user_post() %{expand:%systemd_post \\--global %%{?*}}
5656

5757
%systemd_preun() \
5858
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_preun}} \
59-
if [ $1 -eq 0 ] && [ -x %{_bindir}/systemctl ]; then \
59+
if [ $1 -eq 0 ] && command -v systemctl >/dev/null; then \
6060
# Package removal, not upgrade \
6161
if [ -d /run/systemd/system ]; then \
62-
%{_bindir}/systemctl --no-reload disable --now %{?*} || : \
62+
systemctl --no-reload disable --now %{?*} || : \
6363
else \
64-
%{_bindir}/systemctl --no-reload disable %{?*} || : \
64+
systemctl --no-reload disable %{?*} || : \
6565
fi \
6666
fi \
6767
%{nil}
6868

6969
%systemd_user_preun() \
7070
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_preun}} \
71-
if [ $1 -eq 0 ] && [ -x %{_bindir}/systemctl ]; then \
71+
if [ $1 -eq 0 ] && command -v systemctl >/dev/null; then \
7272
# Package removal, not upgrade \
73-
%{_bindir}/systemctl --global disable %{?*} || : \
73+
systemctl --global disable %{?*} || : \
7474
fi \
7575
%{nil}
7676

@@ -84,10 +84,10 @@ fi \
8484

8585
%systemd_postun_with_restart() \
8686
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_postun_with_restart}} \
87-
if [ $1 -ge 1 ] && [ -x %{_bindir}/systemctl ]; then \
87+
if [ $1 -ge 1 ] && command -v systemctl >/dev/null; then \
8888
# Package upgrade, not uninstall \
8989
for unit in %{?*}; do \
90-
%{_bindir}/systemctl set-property $unit Markers=+needs-restart || : \
90+
systemctl set-property $unit Markers=+needs-restart || : \
9191
done \
9292
fi \
9393
%{nil}
@@ -105,17 +105,17 @@ fi \
105105
# Deprecated. Use %tmpfiles_create_package instead
106106
%tmpfiles_create() \
107107
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# tmpfiles_create}} \
108-
[ -x %{_bindir}/systemd-tmpfiles ] && %{_bindir}/systemd-tmpfiles --create %{?*} || : \
108+
command -v systemd-tmpfiles >/dev/null && systemd-tmpfiles --create %{?*} || : \
109109
%{nil}
110110

111111
# Deprecated. Use %sysusers_create_package instead
112112
%sysusers_create() \
113113
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# sysusers_create}} \
114-
[ -x %{_bindir}/systemd-sysusers ] && %{_bindir}/systemd-sysusers %{?*} || : \
114+
command -v systemd-sysusers >/dev/null && systemd-sysusers %{?*} || : \
115115
%{nil}
116116

117117
%sysusers_create_inline() \
118-
[ -x %{_bindir}/systemd-sysusers ] && %{_bindir}/systemd-sysusers - <<SYSTEMD_INLINE_EOF || : \
118+
command -v systemd-sysusers >/dev/null && systemd-sysusers - <<SYSTEMD_INLINE_EOF || : \
119119
%{?*} \
120120
SYSTEMD_INLINE_EOF\
121121
%{nil}

src/rpm/triggers.systemd.in

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
if posix.access("/run/systemd/system") then
1717
pid = posix.fork()
1818
if pid == 0 then
19-
assert(posix.exec("%{_bindir}/systemctl", "daemon-reload"))
19+
assert(posix.execp("systemctl", "daemon-reload"))
2020
elseif pid > 0 then
2121
posix.wait(pid)
2222
end
2323

2424
pid = posix.fork()
2525
if pid == 0 then
26-
assert(posix.exec("%{_bindir}/systemctl", "reload-or-restart", "--marked"))
26+
assert(posix.execp("systemctl", "reload-or-restart", "--marked"))
2727
elseif pid > 0 then
2828
posix.wait(pid)
2929
end
@@ -38,7 +38,7 @@ end
3838
if posix.access("/run/systemd/system") then
3939
pid = posix.fork()
4040
if pid == 0 then
41-
assert(posix.exec("%{_bindir}/systemctl", "daemon-reload"))
41+
assert(posix.execp("systemctl", "daemon-reload"))
4242
elseif pid > 0 then
4343
posix.wait(pid)
4444
end
@@ -49,7 +49,7 @@ end
4949
if posix.access("/run/systemd/system") then
5050
pid = posix.fork()
5151
if pid == 0 then
52-
assert(posix.exec("%{_bindir}/systemctl", "reload-or-restart", "--marked"))
52+
assert(posix.execp("systemctl", "reload-or-restart", "--marked"))
5353
elseif pid > 0 then
5454
posix.wait(pid)
5555
end
@@ -62,7 +62,7 @@ end
6262
if posix.access("/run/systemd/system") then
6363
pid = posix.fork()
6464
if pid == 0 then
65-
assert(posix.exec("%{_bindir}/systemd-sysusers"))
65+
assert(posix.execp("systemd-sysusers"))
6666
elseif pid > 0 then
6767
posix.wait(pid)
6868
end
@@ -74,7 +74,7 @@ end
7474
if posix.access("/run/systemd/system") then
7575
pid = posix.fork()
7676
if pid == 0 then
77-
assert(posix.exec("%{_bindir}/systemd-hwdb", "update"))
77+
assert(posix.execp("systemd-hwdb", "update"))
7878
elseif pid > 0 then
7979
posix.wait(pid)
8080
end
@@ -86,7 +86,7 @@ end
8686
if posix.access("/run/systemd/system") then
8787
pid = posix.fork()
8888
if pid == 0 then
89-
assert(posix.exec("%{_bindir}/journalctl", "--update-catalog"))
89+
assert(posix.execp("journalctl", "--update-catalog"))
9090
elseif pid > 0 then
9191
posix.wait(pid)
9292
end
@@ -111,7 +111,7 @@ end
111111
if posix.access("/run/systemd/system") then
112112
pid = posix.fork()
113113
if pid == 0 then
114-
assert(posix.exec("%{_bindir}/systemd-tmpfiles", "--create"))
114+
assert(posix.execp("systemd-tmpfiles", "--create"))
115115
elseif pid > 0 then
116116
posix.wait(pid)
117117
end
@@ -123,7 +123,7 @@ end
123123
if posix.access("/run/systemd/system") then
124124
pid = posix.fork()
125125
if pid == 0 then
126-
assert(posix.exec("%{_bindir}/udevadm", "control", "--reload"))
126+
assert(posix.execp("udevadm", "control", "--reload"))
127127
elseif pid > 0 then
128128
posix.wait(pid)
129129
end

src/rpm/triggers.systemd.sh.in

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# installed, because other cases are covered by the *un scriptlets,
1616
# so sometimes we will reload needlessly.
1717
if test -d "/run/systemd/system"; then
18-
%{_bindir}/systemctl daemon-reload || :
19-
%{_bindir}/systemctl reload-or-restart --marked || :
18+
systemctl daemon-reload || :
19+
systemctl reload-or-restart --marked || :
2020
fi
2121

2222
%transfiletriggerpostun -P 1000100 -- {{SYSTEM_DATA_UNIT_DIR}} /etc/systemd/system
@@ -26,35 +26,35 @@ fi
2626
# have been installed, but before %postun scripts in packages get
2727
# executed.
2828
if test -d "/run/systemd/system"; then
29-
%{_bindir}/systemctl daemon-reload || :
29+
systemctl daemon-reload || :
3030
fi
3131

3232
%transfiletriggerpostun -P 10000 -- {{SYSTEM_DATA_UNIT_DIR}} /etc/systemd/system
3333
# We restart remaining services that should be restarted here.
3434
if test -d "/run/systemd/system"; then
35-
%{_bindir}/systemctl reload-or-restart --marked || :
35+
systemctl reload-or-restart --marked || :
3636
fi
3737

3838
%transfiletriggerin -P 1000700 -- {{SYSUSERS_DIR}}
3939
# This script will process files installed in {{SYSUSERS_DIR}} to create
4040
# specified users automatically. The priority is set such that it
4141
# will run before the tmpfiles file trigger.
4242
if test -d "/run/systemd/system"; then
43-
%{_bindir}/systemd-sysusers || :
43+
systemd-sysusers || :
4444
fi
4545

4646
%transfiletriggerin -P 1000700 udev -- {{UDEV_HWDB_DIR}}
4747
# This script will automatically invoke hwdb update if files have been
4848
# installed or updated in {{UDEV_HWDB_DIR}}.
4949
if test -d "/run/systemd/system"; then
50-
%{_bindir}/systemd-hwdb update || :
50+
systemd-hwdb update || :
5151
fi
5252

5353
%transfiletriggerin -P 1000700 -- {{SYSTEMD_CATALOG_DIR}}
5454
# This script will automatically invoke journal catalog update if files
5555
# have been installed or updated in {{SYSTEMD_CATALOG_DIR}}.
5656
if test -d "/run/systemd/system"; then
57-
%{_bindir}/journalctl --update-catalog || :
57+
journalctl --update-catalog || :
5858
fi
5959

6060
%transfiletriggerin -P 1000700 -- {{BINFMT_DIR}}
@@ -71,14 +71,14 @@ fi
7171
# tmpfiles automatically. The priority is set such that it will run
7272
# after the sysusers file trigger, but before any other triggers.
7373
if test -d "/run/systemd/system"; then
74-
%{_bindir}/systemd-tmpfiles --create || :
74+
systemd-tmpfiles --create || :
7575
fi
7676

7777
%transfiletriggerin -P 1000600 udev -- {{UDEV_RULES_DIR}}
7878
# This script will automatically update udev with new rules if files
7979
# have been installed or updated in {{UDEV_RULES_DIR}}.
8080
if test -e /run/udev/control; then
81-
%{_bindir}/udevadm control --reload || :
81+
udevadm control --reload || :
8282
fi
8383

8484
%transfiletriggerin -P 1000500 -- {{SYSCTL_DIR}}

0 commit comments

Comments
 (0)
X Tutup