condition: allow overriding of ConditionNeedsUpdate= on the kernel command line

This should be useful for addressing #15724.
This commit is contained in:
Lennart Poettering 2020-05-14 09:55:57 +02:00
parent 3931056767
commit f8b4ae29c7
4 changed files with 27 additions and 0 deletions

View file

@ -436,6 +436,15 @@
will not query the user for basic system settings, even if the system boots up for the first time and the will not query the user for basic system settings, even if the system boots up for the first time and the
relevant settings are not initialized yet.</para></listitem> relevant settings are not initialized yet.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><varname>systemd.condition-needs-update=</varname></term>
<listitem><para>Takes a boolean argument. If specified, overrides the result of
<varname>ConditionNeedsUpdate=</varname> unit condition checks. See
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
details.</para></listitem>
</varlistentry>
</variablelist> </variablelist>
</refsect1> </refsect1>

View file

@ -58,6 +58,10 @@
<citerefentry project='man-pages'><refentrytitle>touch</refentrytitle><manvolnum>1</manvolnum></citerefentry> <citerefentry project='man-pages'><refentrytitle>touch</refentrytitle><manvolnum>1</manvolnum></citerefentry>
on it.</para> on it.</para>
<para>Note that if the <varname>systemd.condition-needs-update=</varname> kernel command line option is
used it overrides the <varname>ConditionNeedsUpdate=</varname> unit condition checks. In that case
<filename>systemd-update-done.service</filename> will not reset the condition state until a follow-up
reboot where the kernel switch is not specified anymore.</para>
</refsect1> </refsect1>
<refsect1> <refsect1>

View file

@ -1294,6 +1294,13 @@
<citerefentry><refentrytitle>systemd-update-done.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>, <citerefentry><refentrytitle>systemd-update-done.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
to make sure they run before the stamp file's modification time gets reset indicating a completed to make sure they run before the stamp file's modification time gets reset indicating a completed
update.</para> update.</para>
<para>If the <varname>systemd.condition-needs-update=</varname> option is specified on the kernel
command line (taking a boolean), it will override the result of this condition check, taking
precedence over any file modification time checks. If it is used
<filename>systemd-update-done.service</filename> will not have immediate effect on any following
<varname>ConditionNeedsUpdate=</varname> checks, until the system is rebooted where the kernel
command line option is not specified anymore.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View file

@ -548,12 +548,19 @@ static int condition_test_capability(Condition *c, char **env) {
static int condition_test_needs_update(Condition *c, char **env) { static int condition_test_needs_update(Condition *c, char **env) {
struct stat usr, other; struct stat usr, other;
const char *p; const char *p;
bool b;
int r; int r;
assert(c); assert(c);
assert(c->parameter); assert(c->parameter);
assert(c->type == CONDITION_NEEDS_UPDATE); assert(c->type == CONDITION_NEEDS_UPDATE);
r = proc_cmdline_get_bool("systemd.condition-needs-update", &b);
if (r < 0)
log_debug_errno(r, "Failed to parse systemd.condition-needs-update= kernel command line argument, ignoring: %m");
if (r > 0)
return b;
if (!path_is_absolute(c->parameter)) { if (!path_is_absolute(c->parameter)) {
log_debug("Specified condition parameter '%s' is not absolute, assuming an update is needed.", c->parameter); log_debug("Specified condition parameter '%s' is not absolute, assuming an update is needed.", c->parameter);
return true; return true;