chiark / gitweb /
job: job_uninstall()
[elogind.git] / src / core / manager.c
index 44690525ea556422b0e4abaa2e23e7f54528d19b..445931cb83c9b9a0884d2f80df9f2a7a5e7eb64d 100644 (file)
@@ -63,6 +63,7 @@
 #include "exit-status.h"
 #include "virt.h"
 #include "watchdog.h"
+#include "cgroup-util.h"
 
 /* As soon as 16 units are in our GC queue, make sure to run a gc sweep */
 #define GC_QUEUE_ENTRIES_MAX 16
@@ -661,13 +662,15 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
         return r;
 }
 
+static void transaction_unlink_job(Manager *m, Job *j, bool delete_dependencies);
+
 static void transaction_delete_job(Manager *m, Job *j, bool delete_dependencies) {
         assert(m);
         assert(j);
 
         /* Deletes one job from the transaction */
 
-        manager_transaction_unlink_job(m, j, delete_dependencies);
+        transaction_unlink_job(m, j, delete_dependencies);
 
         if (!j->installed)
                 job_free(j);
@@ -707,10 +710,7 @@ static void transaction_abort(Manager *m) {
         assert(m);
 
         while ((j = hashmap_first(m->transaction_jobs)))
-                if (j->installed)
-                        transaction_delete_job(m, j, true);
-                else
-                        job_free(j);
+                transaction_delete_job(m, j, true);
 
         assert(hashmap_isempty(m->transaction_jobs));
 
@@ -757,7 +757,7 @@ static void transaction_merge_and_delete_job(Manager *m, Job *j, Job *other, Job
         assert(j->unit == other->unit);
         assert(!j->installed);
 
-        /* Merges 'other' into 'j' and then deletes j. */
+        /* Merges 'other' into 'j' and then deletes 'other'. */
 
         j->type = t;
         j->state = JOB_WAITING;
@@ -802,6 +802,7 @@ static void transaction_merge_and_delete_job(Manager *m, Job *j, Job *other, Job
         other->object_list = NULL;
         transaction_delete_job(m, other, true);
 }
+
 static bool job_is_conflicted_by(Job *j) {
         JobDependency *l;
 
@@ -1274,13 +1275,17 @@ static int transaction_apply(Manager *m, JobMode mode) {
         }
 
         while ((j = hashmap_steal_first(m->transaction_jobs))) {
+                Job *uj;
                 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;
                 }
 
-                if (j->unit->job)
-                        job_free(j->unit->job);
+                uj = j->unit->job;
+                if (uj) {
+                        job_uninstall(uj);
+                        job_free(uj);
+                }
 
                 j->unit->job = j;
                 j->installed = true;
@@ -1439,6 +1444,7 @@ static Job* transaction_add_one_job(Manager *m, JobType type, Unit *unit, bool o
         LIST_PREPEND(Job, transaction, f, j);
 
         if (hashmap_replace(m->transaction_jobs, unit, f) < 0) {
+                LIST_REMOVE(Job, transaction, f, j);
                 job_free(j);
                 return NULL;
         }
@@ -1451,7 +1457,7 @@ static Job* transaction_add_one_job(Manager *m, JobType type, Unit *unit, bool o
         return j;
 }
 
-void manager_transaction_unlink_job(Manager *m, Job *j, bool delete_dependencies) {
+static void transaction_unlink_job(Manager *m, Job *j, bool delete_dependencies) {
         assert(m);
         assert(j);
 
@@ -3172,7 +3178,7 @@ int manager_set_default_controllers(Manager *m, char **controllers) {
         strv_free(m->default_controllers);
         m->default_controllers = l;
 
-        manager_shorten_default_controllers(m);
+        cg_shorten_controllers(m->default_controllers);
 
         return 0;
 }