]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/manager: pass soft-reboot count to generators
authorMike Yuan <me@yhndnzj.com>
Sat, 28 Sep 2024 13:54:42 +0000 (15:54 +0200)
committerMike Yuan <me@yhndnzj.com>
Mon, 14 Oct 2024 23:18:26 +0000 (01:18 +0200)
soft-reboot allows switching into a different root/installation,
i.e. potentially invalidate settings from kernel cmdline and such.
Let's hence inform generators about soft-reboots.

man/systemd.generator.xml
src/core/manager.c

index ae4c2c5c0b3c0a319b6f44b7c0c9a57158819438..1a9b5d1653037e7a39779c390d581283f6f1aa8b 100644 (file)
         <xi:include href="version-info.xml" xpointer="v251"/></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><varname>$SYSTEMD_SOFT_REBOOTS_COUNT</varname></term>
+
+        <listitem><para>If the system has soft-rebooted, this variable is set to the count of soft-reboots.
+        This environment variable is only set for system generators.</para>
+
+        <xi:include href="version-info.xml" xpointer="v257"/></listitem>
+      </varlistentry>
+
       <varlistentry>
         <term><varname>$SYSTEMD_FIRST_BOOT</varname></term>
 
index 373f4d66e7b8aaea6a15628403981faf7365614c..b9ea79a7adacc214e7410fce23875f126063854f 100644 (file)
@@ -4081,6 +4081,12 @@ static int build_generator_environment(Manager *m, char ***ret) {
                 if (r < 0)
                         return r;
 
+                if (m->soft_reboots_count > 0) {
+                        r = strv_env_assignf(&nl, "SYSTEMD_SOFT_REBOOTS_COUNT", "%u", m->soft_reboots_count);
+                        if (r < 0)
+                                return r;
+                }
+
                 if (m->first_boot >= 0) {
                         r = strv_env_assign(&nl, "SYSTEMD_FIRST_BOOT", one_zero(m->first_boot));
                         if (r < 0)