]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/transaction: when isolating, keep triggered units only if their triggers are... 40140/head
authorFranck Bui <fbui@suse.com>
Wed, 26 Nov 2025 10:38:34 +0000 (11:38 +0100)
committerMike Yuan <me@yhndnzj.com>
Wed, 31 Dec 2025 18:33:19 +0000 (19:33 +0100)
Follow-up for 32d6707dd1692d41e12f5469dfdcbc10f14d6619.

Co-authored-by: Mike Yuan <me@yhndnzj.com>
src/core/transaction.c

index 59c7f8c97f6a467884579fb425a62d53c67a06b9..90cc8ee41f1bf87188b7fd717e05a900938c8cf4 100644 (file)
@@ -1178,6 +1178,28 @@ static bool shall_stop_on_isolate(Transaction *tr, Unit *u) {
         if (hashmap_contains(tr->jobs, u))
                 return false;
 
+        /* Keep units that are triggered by units we want to keep around. */
+        Unit *other;
+        UNIT_FOREACH_DEPENDENCY(other, u, UNIT_ATOM_TRIGGERED_BY) {
+                if (UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
+                        continue;
+
+                /* Is the trigger about to go down? */
+                Job *other_job = hashmap_get(tr->jobs, other);
+
+                bool has_stop = false;
+                LIST_FOREACH(transaction, j, other_job)
+                        if (j->type == JOB_STOP) {
+                                has_stop = true;
+                                break;
+                        }
+                if (has_stop)
+                        continue;
+
+                if (other->ignore_on_isolate || other_job)
+                        return false;
+        }
+
         return true;
 }
 
@@ -1191,7 +1213,6 @@ int transaction_add_isolate_jobs(Transaction *tr, Manager *m) {
 
         HASHMAP_FOREACH_KEY(u, k, m->units) {
                 _cleanup_(sd_bus_error_free) sd_bus_error e = SD_BUS_ERROR_NULL;
-                Unit *o;
 
                 /* Ignore aliases. */
                 if (u->id != k)
@@ -1204,16 +1225,6 @@ int transaction_add_isolate_jobs(Transaction *tr, Manager *m) {
                 if (!shall_stop_on_isolate(tr, u))
                         continue;
 
-                /* Keep units that are triggered by units we want to keep around. */
-                bool keep = false;
-                UNIT_FOREACH_DEPENDENCY(o, u, UNIT_ATOM_TRIGGERED_BY)
-                        if (!shall_stop_on_isolate(tr, o)) {
-                                keep = true;
-                                break;
-                        }
-                if (keep)
-                        continue;
-
                 r = transaction_add_job_and_dependencies(tr, JOB_STOP, u, tr->anchor_job, TRANSACTION_MATTERS, &e);
                 if (r < 0)
                         log_unit_warning_errno(u, r, "Cannot add isolate job, ignoring: %s", bus_error_message(&e, r));