1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-12 13:18:14 +03:00

rpm: check argument counts for systemd macros

Invoking %systemd_tmpfiles (in %post) without any arguments, while
possible, will cause systemd-tmpfiles to process the entire system
configuration, rather than just the newly installed configuration
files. In https://github.com/systemd/systemd/pull/12048, it was
established that processing everything constitutes unusual practice,
and should be flagged as a mistake at build time.

Furthermore, invoking %systemd_post without any arguments will cause
the underlying `systemctl preset` to outright return an error ("Too
few arguments") when run. This can be flagged during build time in
the same manner.

As I have found no ways to successfully nest %if clauses inside a
macro[1], I am helping myself by reusing the recursive variable
expansion technique pioneered in [2].

Now, when %systemd_post or %systemd_tmpfiles is incorrectly used,
rpm gives accurate line number reporting, too:

	error: This macro requires some arguments
	error: line 11: %{systemd_post}

	error: This macro requires two arguments
	error: line 13: %{tmpfiles_create_package meh more more}

[1] what has been tried: %{expand:%%if "%#" == 0 \\\
    %%{error:you have given me %# args} \\\
    %%endif}

[2] http://git.savannah.gnu.org/cgit/automake.git/commit/?id=e0bd4af16da88e4c2c61bde42675660eff7dff51
This commit is contained in:
Jan Engelhardt 2019-03-20 14:48:47 +01:00
parent a49945e663
commit 085f826676

View File

@ -40,7 +40,11 @@ OrderWithRequires(preun): systemd \
OrderWithRequires(postun): systemd \
%{nil}
%__systemd_someargs_0() %{error:This macro requires some arguments}
%__systemd_twoargs_2() %{nil}
%systemd_post() \
%{expand:%%{?__systemd_someargs_%#}} \
if [ $1 -eq 1 ] ; then \
# Initial installation \
systemctl --no-reload preset %{?*} >/dev/null 2>&1 || : \
@ -50,6 +54,7 @@ fi \
%systemd_user_post() %{expand:%systemd_post \\--global %%{?*}}
%systemd_preun() \
%{expand:%%{?__systemd_someargs_%#}} \
if [ $1 -eq 0 ] ; then \
# Package removal, not upgrade \
systemctl --no-reload disable --now %{?*} >/dev/null 2>&1 || : \
@ -57,24 +62,26 @@ fi \
%{nil}
%systemd_user_preun() \
%{expand:%%{?__systemd_someargs_%#}} \
if [ $1 -eq 0 ] ; then \
# Package removal, not upgrade \
systemctl --global disable %{?*} >/dev/null 2>&1 || : \
fi \
%{nil}
%systemd_postun() %{nil}
%systemd_postun() %{expand:%%{?__systemd_someargs_%#}}%{nil}
%systemd_user_postun() %{nil}
%systemd_user_postun() %{expand:%%{?__systemd_someargs_%#}}%{nil}
%systemd_postun_with_restart() \
%{expand:%%{?__systemd_someargs_%#}} \
if [ $1 -ge 1 ] ; then \
# Package upgrade, not uninstall \
systemctl try-restart %{?*} >/dev/null 2>&1 || : \
fi \
%{nil}
%systemd_user_postun_with_restart() %{nil}
%systemd_user_postun_with_restart() %{expand:%%{?__systemd_someargs_%#}}%{nil}
%udev_hwdb_update() %{nil}
@ -84,11 +91,13 @@ fi \
# Deprecated. Use %tmpfiles_create_package instead
%tmpfiles_create() \
%{expand:%%{?__systemd_someargs_%#}} \
systemd-tmpfiles --create %{?*} >/dev/null 2>&1 || : \
%{nil}
# Deprecated. Use %sysusers_create_package instead
%sysusers_create() \
%{expand:%%{?__systemd_someargs_%#}} \
systemd-sysusers %{?*} >/dev/null 2>&1 || : \
%{nil}
@ -112,6 +121,7 @@ SYSTEMD_INLINE_EOF \
# %files
# %{_sysusersdir}/%{name}.conf
%sysusers_create_package() \
%{expand:%%{?!__systemd_twoargs_%#:%%{error:This macro requires two arguments}}} \
systemd-sysusers --replace=%_sysusersdir/%1.conf - <<SYSTEMD_INLINE_EOF >/dev/null 2>&1 || : \
%(cat %2) \
SYSTEMD_INLINE_EOF \
@ -131,15 +141,18 @@ SYSTEMD_INLINE_EOF \
# %files
# %{_tmpfilesdir}/%{name}.conf
%tmpfiles_create_package() \
%{expand:%%{?!__systemd_twoargs_%#:%%{error:This macro requires two arguments}}} \
systemd-tmpfiles --replace=%_tmpfilesdir/%1.conf --create - <<SYSTEMD_INLINE_EOF >/dev/null 2>&1 || : \
%(cat %2) \
SYSTEMD_INLINE_EOF \
%{nil}
%sysctl_apply() \
%{expand:%%{?__systemd_someargs_%#}} \
@rootlibexecdir@/systemd-sysctl %{?*} >/dev/null 2>&1 || : \
%{nil}
%binfmt_apply() \
%{expand:%%{?__systemd_someargs_%#}} \
@rootlibexecdir@/systemd-binfmt %{?*} >/dev/null 2>&1 || : \
%{nil}