]> err.no Git - systemd/commitdiff
job: separate job_install()
authorMichal Schmidt <mschmidt@redhat.com>
Fri, 20 Apr 2012 00:04:01 +0000 (02:04 +0200)
committerMichal Schmidt <mschmidt@redhat.com>
Fri, 20 Apr 2012 15:12:28 +0000 (17:12 +0200)
Let the jobs install themselves.

src/core/job.c
src/core/job.h
src/core/transaction.c

index aa7cdbff2add4c3522c38641380d6dc95ea69521..0b5088818408092ce3b9f95dfffb4e132893178e 100644 (file)
@@ -54,21 +54,6 @@ Job* job_new(Unit *unit, JobType type) {
         return j;
 }
 
-void job_uninstall(Job *j) {
-        assert(j->installed);
-        /* Detach from next 'bigger' objects */
-
-        bus_job_send_removed_signal(j);
-
-        if (j->unit->job == j) {
-                j->unit->job = NULL;
-                unit_add_to_gc_queue(j->unit);
-        }
-
-        hashmap_remove(j->manager->jobs, UINT32_TO_PTR(j->id));
-        j->installed = false;
-}
-
 void job_free(Job *j) {
         assert(j);
         assert(!j->installed);
@@ -96,6 +81,35 @@ void job_free(Job *j) {
         free(j);
 }
 
+void job_uninstall(Job *j) {
+        assert(j->installed);
+        /* Detach from next 'bigger' objects */
+
+        bus_job_send_removed_signal(j);
+
+        if (j->unit->job == j) {
+                j->unit->job = NULL;
+                unit_add_to_gc_queue(j->unit);
+        }
+
+        hashmap_remove(j->manager->jobs, UINT32_TO_PTR(j->id));
+        j->installed = false;
+}
+
+void job_install(Job *j) {
+        Job *uj = j->unit->job;
+
+        if (uj) {
+                job_uninstall(uj);
+                job_free(uj);
+        }
+
+        j->unit->job = j;
+        j->installed = true;
+        j->manager->n_installed_jobs ++;
+        log_debug("Installed new job %s/%s as %u", j->unit->id, job_type_to_string(j->type), (unsigned) j->id);
+}
+
 JobDependency* job_dependency_new(Job *subject, Job *object, bool matters, bool conflicts) {
         JobDependency *l;
 
index 4e0c7ca81e7fd48c640a747903f3337614ae800d..0110126ce9f43f872f0d79d9bd71d73e29e82850 100644 (file)
@@ -137,8 +137,9 @@ struct Job {
 };
 
 Job* job_new(Unit *unit, JobType type);
-void job_uninstall(Job *j);
 void job_free(Job *job);
+void job_install(Job *j);
+void job_uninstall(Job *j);
 void job_dump(Job *j, FILE*f, const char *prefix);
 
 JobDependency* job_dependency_new(Job *subject, Job *object, bool matters, bool conflicts);
index 41f7b82fbdf31d29cfdc2086a21daaed24638df4..d495cbddc60dff5def0187cd32a6e449f68f9a09 100644 (file)
@@ -592,33 +592,19 @@ static int transaction_apply(Transaction *tr, Manager *m, JobMode mode) {
         }
 
         while ((j = hashmap_steal_first(tr->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;
                 }
 
-                uj = j->unit->job;
-                if (uj) {
-                        job_uninstall(uj);
-                        job_free(uj);
-                }
-
-                j->unit->job = j;
-                j->installed = true;
-                m->n_installed_jobs ++;
-
-                /* We're fully installed. Now let's free data we don't
-                 * need anymore. */
-
                 /* Clean the job dependencies */
                 transaction_unlink_job(tr, j, false);
 
+                job_install(j);
+
                 job_add_to_run_queue(j);
                 job_add_to_dbus_queue(j);
                 job_start_timer(j);
-
-                log_debug("Installed new job %s/%s as %u", j->unit->id, job_type_to_string(j->type), (unsigned) j->id);
         }
 
         return 0;