richardphibel / rpms / systemd

Forked from rpms/systemd a year ago
Clone
ac3a84
From 9be28013e62ae471151fdc1f181e21cbd1e72dbd Mon Sep 17 00:00:00 2001
ac3a84
From: Lennart Poettering <lennart@poettering.net>
ac3a84
Date: Fri, 10 Feb 2023 13:38:08 +0100
ac3a84
Subject: [PATCH] core: when isolating to a unit, also keep units running that
ac3a84
 are triggered by units we keep running
ac3a84
ac3a84
Inspired by: #26364
ac3a84
ac3a84
(this might even "fix" #26364, but without debug logs it's hard to make
ac3a84
such claims)
ac3a84
ac3a84
Fixes: #23055
ac3a84
(cherry picked from commit 32d6707dd1692d41e12f5469dfdcbc10f14d6619)
ac3a84
ac3a84
Resolves: #1952378
ac3a84
---
ac3a84
 src/core/transaction.c | 33 +++++++++++++++++++++++++++------
ac3a84
 1 file changed, 27 insertions(+), 6 deletions(-)
ac3a84
ac3a84
diff --git a/src/core/transaction.c b/src/core/transaction.c
ac3a84
index bafbb80b47..8ec853d58d 100644
ac3a84
--- a/src/core/transaction.c
ac3a84
+++ b/src/core/transaction.c
ac3a84
@@ -1092,6 +1092,20 @@ fail:
ac3a84
         return r;
ac3a84
 }
ac3a84
 
ac3a84
+static bool shall_stop_on_isolate(Transaction *tr, Unit *u) {
ac3a84
+        assert(tr);
ac3a84
+        assert(u);
ac3a84
+
ac3a84
+        if (u->ignore_on_isolate)
ac3a84
+                return false;
ac3a84
+
ac3a84
+        /* Is there already something listed for this? */
ac3a84
+        if (hashmap_get(tr->jobs, u))
ac3a84
+                return false;
ac3a84
+
ac3a84
+        return true;
ac3a84
+}
ac3a84
+
ac3a84
 int transaction_add_isolate_jobs(Transaction *tr, Manager *m) {
ac3a84
         Unit *u;
ac3a84
         char *k;
ac3a84
@@ -1101,20 +1115,27 @@ int transaction_add_isolate_jobs(Transaction *tr, Manager *m) {
ac3a84
         assert(m);
ac3a84
 
ac3a84
         HASHMAP_FOREACH_KEY(u, k, m->units) {
ac3a84
+                Unit *o;
ac3a84
 
ac3a84
-                /* ignore aliases */
ac3a84
+                /* Ignore aliases */
ac3a84
                 if (u->id != k)
ac3a84
                         continue;
ac3a84
 
ac3a84
-                if (u->ignore_on_isolate)
ac3a84
+                /* No need to stop inactive units */
ac3a84
+                if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(u)) && !u->job)
ac3a84
                         continue;
ac3a84
 
ac3a84
-                /* No need to stop inactive jobs */
ac3a84
-                if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(u)) && !u->job)
ac3a84
+                if (!shall_stop_on_isolate(tr, u))
ac3a84
                         continue;
ac3a84
 
ac3a84
-                /* Is there already something listed for this? */
ac3a84
-                if (hashmap_get(tr->jobs, u))
ac3a84
+                /* Keep units that are triggered by units we want to keep around. */
ac3a84
+                bool keep = false;
ac3a84
+                UNIT_FOREACH_DEPENDENCY(o, u, UNIT_ATOM_TRIGGERED_BY)
ac3a84
+                        if (!shall_stop_on_isolate(tr, o)) {
ac3a84
+                                keep = true;
ac3a84
+                                break;
ac3a84
+                        }
ac3a84
+                if (keep)
ac3a84
                         continue;
ac3a84
 
ac3a84
                 r = transaction_add_job_and_dependencies(tr, JOB_STOP, u, tr->anchor_job, true, false, false, false, NULL);