]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
manager: serialize current objective
authorLuca Boccassi <bluca@debian.org>
Thu, 19 Oct 2023 23:34:29 +0000 (00:34 +0100)
committerLuca Boccassi <bluca@debian.org>
Wed, 17 Apr 2024 17:19:27 +0000 (18:19 +0100)
So that we can tell what happened before the exec. It is overwritten
shortly after deserialization. Use it to bump the soft reboots counter.

src/core/main.c
src/core/manager-serialize.c
src/core/manager.c
src/core/manager.h

index 8c8cf8b4a70e9f286f636f0d9e1494f5c82098a5..7ef66c86732e8845d0ad10d5beb838196f3cb1b5 100644 (file)
@@ -3192,11 +3192,6 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        /* If we got a SoftRebootStart timestamp during deserialization, then we are in a new soft-reboot
-         * iteration, so bump the counter now before starting units, so that they can reliably read it. */
-        if (dual_timestamp_is_set(&m->timestamps[MANAGER_TIMESTAMP_SOFTREBOOT_START]))
-                m->soft_reboots_count++;
-
         /* This will close all file descriptors that were opened, but not claimed by any unit. */
         fds = fdset_free(fds);
         arg_serialization = safe_fclose(arg_serialization);
index 884332b3249e536c7f6fe6db11c4050d11df45f4..6008e5655e800c9cf3cbf1638128ade431af9831 100644 (file)
@@ -158,6 +158,9 @@ int manager_serialize(
         (void) serialize_ratelimit(f, "dump-ratelimit", &m->dump_ratelimit);
         (void) serialize_ratelimit(f, "reload-reexec-ratelimit", &m->reload_reexec_ratelimit);
 
+        if (m->objective >= 0 && m->objective < _MANAGER_OBJECTIVE_MAX)
+                (void) serialize_item_format(f, "previous-objective", "%u", (unsigned) m->objective);
+
         bus_track_serialize(m->subscribed, f, "subscribed");
 
         r = dynamic_user_serialize(m, f, fds);
@@ -529,6 +532,14 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
                                 log_notice("Failed to parse soft reboots counter '%s', ignoring.", val);
                         else
                                 m->soft_reboots_count = n;
+                } else if ((val = startswith(l, "previous-objective="))) {
+                        unsigned n;
+
+                        if (safe_atou(val, &n) < 0 || n >= _MANAGER_OBJECTIVE_MAX)
+                                log_notice("Failed to parse objective '%s', ignoring.", val);
+                        else
+                                m->previous_objective = n;
+
                 } else {
                         ManagerTimestamp q;
 
index 52f5e72e117bd983babd1995a6d15ce83862eaf2..1fb0f7dd21c0b4c850f4d57ac4ccb09b415d777c 100644 (file)
@@ -882,6 +882,7 @@ int manager_new(RuntimeScope runtime_scope, ManagerTestRunFlags test_run_flags,
         *m = (Manager) {
                 .runtime_scope = runtime_scope,
                 .objective = _MANAGER_OBJECTIVE_INVALID,
+                .previous_objective = _MANAGER_OBJECTIVE_INVALID,
 
                 .status_unit_format = STATUS_UNIT_FORMAT_DEFAULT,
 
@@ -1973,6 +1974,11 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds, const char *roo
                                 return log_error_errno(r, "Deserialization failed: %m");
                 }
 
+                /* If we are in a new soft-reboot iteration bump the counter now before starting units, so
+                 * that they can reliably read it. We get the previous objective from serialized state. */
+                if (m->previous_objective == MANAGER_SOFT_REBOOT)
+                        m->soft_reboots_count++;
+
                 /* Any fds left? Find some unit which wants them. This is useful to allow container managers to pass
                  * some file descriptors to us pre-initialized. This enables socket-based activation of entire
                  * containers. */
index 9541a5e0b469dd23bc67d8f689eb8910d5df4e4a..afc49a2f1947f60f04ee16e3818a38a7e5a63f8e 100644 (file)
@@ -379,6 +379,8 @@ struct Manager {
         bool etc_localtime_accessible;
 
         ManagerObjective objective;
+        /* Objective as it was before serialization, mostly to detect soft-reboots */
+        ManagerObjective previous_objective;
 
         /* Flags */
         bool dispatching_load_queue;