chiark / gitweb /
transaction: avoid garbage collecting the anchor job
[elogind.git] / src / core / transaction.c
index 09abe007fb43ea3acda56c1abce9ccb964553fd5..ddb02c068a8b5075158d438ce45f0fbc7673904f 100644 (file)
@@ -38,22 +38,18 @@ void transaction_abort(Transaction *tr) {
         assert(!tr->anchor);
 }
 
-static void transaction_find_jobs_that_matter_to_anchor(Transaction *tr, Job *j, unsigned generation) {
+static void transaction_find_jobs_that_matter_to_anchor(Job *j, unsigned generation) {
         JobDependency *l;
 
-        assert(tr);
-
         /* A recursive sweep through the graph that marks all units
          * that matter to the anchor job, i.e. are directly or
          * indirectly a dependency of the anchor job via paths that
          * are fully marked as mattering. */
 
-        if (j)
-                l = j->subject_list;
-        else
-                l = tr->anchor;
+        j->matters_to_anchor = true;
+        j->generation = generation;
 
-        LIST_FOREACH(subject, l, l) {
+        LIST_FOREACH(subject, l, j->subject_list) {
 
                 /* This link does not matter */
                 if (!l->matters)
@@ -63,10 +59,7 @@ static void transaction_find_jobs_that_matter_to_anchor(Transaction *tr, Job *j,
                 if (l->object->generation == generation)
                         continue;
 
-                l->object->matters_to_anchor = true;
-                l->object->generation = generation;
-
-                transaction_find_jobs_that_matter_to_anchor(tr, l->object, generation);
+                transaction_find_jobs_that_matter_to_anchor(l->object, generation);
         }
 }
 
@@ -461,7 +454,7 @@ static void transaction_collect_garbage(Transaction *tr) {
                 again = false;
 
                 HASHMAP_FOREACH(j, tr->jobs, i) {
-                        if (j->object_list) {
+                        if (tr->anchor_job == j || j->object_list) {
                                 /* log_debug("Keeping job %s/%s because of %s/%s", */
                                 /*           j->unit->id, job_type_to_string(j->type), */
                                 /*           j->object_list->subject ? j->object_list->subject->unit->id : "root", */
@@ -659,7 +652,7 @@ int transaction_activate(Transaction *tr, Manager *m, JobMode mode, DBusError *e
          * the actual list of jobs, if possible. */
 
         /* First step: figure out which jobs matter */
-        transaction_find_jobs_that_matter_to_anchor(tr, NULL, generation++);
+        transaction_find_jobs_that_matter_to_anchor(tr->anchor_job, generation++);
 
         /* Second step: Try not to stop any running services if
          * we don't have to. Don't try to reverse running