chiark / gitweb /
transaction: add starting requirements for JOB_RESTART
[elogind.git] / src / core / transaction.c
index d495cbddc60dff5def0187cd32a6e449f68f9a09..a2efcbcff4a03ea939fa8487f2c3e957ff93dda8 100644 (file)
@@ -11,8 +11,7 @@ static void transaction_delete_job(Transaction *tr, Job *j, bool delete_dependen
 
         transaction_unlink_job(tr, j, delete_dependencies);
 
-        if (!j->installed)
-                job_free(j);
+        job_free(j);
 }
 
 static void transaction_delete_unit(Transaction *tr, Unit *u) {
@@ -243,21 +242,14 @@ static int transaction_merge_jobs(Transaction *tr, DBusError *e) {
                 LIST_FOREACH(transaction, k, j->transaction_next)
                         assert_se(job_type_merge(&t, k->type) == 0);
 
-                /* If an active job is mergeable, merge it too */
-                if (j->unit->job)
-                        job_type_merge(&t, j->unit->job->type); /* Might fail. Which is OK */
-
                 while ((k = j->transaction_next)) {
-                        if (j->installed) {
+                        if (tr->anchor_job == k) {
                                 transaction_merge_and_delete_job(tr, k, j, t);
                                 j = k;
                         } else
                                 transaction_merge_and_delete_job(tr, j, k, t);
                 }
 
-                if (j->unit->job && !j->installed)
-                        transaction_merge_and_delete_job(tr, j, j->unit->job, t);
-
                 assert(!j->transaction_next);
                 assert(!j->transaction_prev);
         }
@@ -286,7 +278,7 @@ static void transaction_drop_redundant(Transaction *tr) {
                         LIST_FOREACH(transaction, k, j) {
 
                                 if (tr->anchor_job != k &&
-                                    (k->installed || job_type_is_redundant(k->type, unit_active_state(k->unit))) &&
+                                    job_type_is_redundant(k->type, unit_active_state(k->unit)) &&
                                     (!k->unit->job || !job_type_is_conflicting(k->type, k->unit->job->type)))
                                         continue;
 
@@ -356,7 +348,6 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi
                         log_info("Walked on cycle path to %s/%s", k->unit->id, job_type_to_string(k->type));
 
                         if (!delete &&
-                            !k->installed &&
                             !unit_matters_to_anchor(k->unit, k)) {
                                 /* Ok, we can drop this one, so let's
                                  * do so. */
@@ -485,7 +476,6 @@ static int transaction_is_destructive(Transaction *tr, DBusError *e) {
                 assert(!j->transaction_next);
 
                 if (j->unit->job &&
-                    j->unit->job != j &&
                     !job_type_is_superset(j->type, j->unit->job->type)) {
 
                         dbus_set_error(e, BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE, "Transaction is destructive.");
@@ -583,24 +573,26 @@ static int transaction_apply(Transaction *tr, Manager *m, JobMode mode) {
                 assert(!j->transaction_prev);
                 assert(!j->transaction_next);
 
-                if (j->installed)
-                        continue;
-
                 r = hashmap_put(m->jobs, UINT32_TO_PTR(j->id), j);
                 if (r < 0)
                         goto rollback;
         }
 
         while ((j = hashmap_steal_first(tr->jobs))) {
-                if (j->installed) {
-                        /* log_debug("Skipping already installed job %s/%s as %u", j->unit->id, job_type_to_string(j->type), (unsigned) j->id); */
-                        continue;
-                }
+                Job *installed_job;
 
                 /* Clean the job dependencies */
                 transaction_unlink_job(tr, j, false);
 
-                job_install(j);
+                installed_job = job_install(j);
+                if (installed_job != j) {
+                        /* j has been merged into a previously installed job */
+                        if (tr->anchor_job == j)
+                                tr->anchor_job = installed_job;
+                        hashmap_remove(m->jobs, UINT32_TO_PTR(j->id));
+                        job_free(j);
+                        j = installed_job;
+                }
 
                 job_add_to_run_queue(j);
                 job_add_to_dbus_queue(j);
@@ -611,12 +603,8 @@ static int transaction_apply(Transaction *tr, Manager *m, JobMode mode) {
 
 rollback:
 
-        HASHMAP_FOREACH(j, tr->jobs, i) {
-                if (j->installed)
-                        continue;
-
+        HASHMAP_FOREACH(j, tr->jobs, i)
                 hashmap_remove(m->jobs, UINT32_TO_PTR(j->id));
-        }
 
         return r;
 }
@@ -878,7 +866,7 @@ int transaction_add_job_and_dependencies(
                 }
 
                 /* Finally, recursively add in all dependencies. */
-                if (type == JOB_START || type == JOB_RELOAD_OR_START) {
+                if (type == JOB_START || type == JOB_RELOAD_OR_START || type == JOB_RESTART) {
                         SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUIRES], i) {
                                 r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, true, override, false, false, ignore_order, e);
                                 if (r < 0) {