chiark / gitweb /
service: introduce Type=idle and use it for gettys
[elogind.git] / src / core / manager.c
index f070295d881274b2ee29aeecf3970148a593d028..a6013668b8a8221997cf92cda3f3430e506f4758 100644 (file)
@@ -259,6 +259,7 @@ int manager_new(ManagerRunningAs running_as, Manager **_m) {
         m->name_data_slot = m->conn_data_slot = m->subscribed_data_slot = -1;
         m->exit_code = _MANAGER_EXIT_CODE_INVALID;
         m->pin_cgroupfs_fd = -1;
+        m->idle_pipe[0] = m->idle_pipe[1] = -1;
 
 #ifdef HAVE_AUDIT
         m->audit_fd = -1;
@@ -518,6 +519,8 @@ void manager_free(Manager *m) {
         hashmap_free(m->cgroup_bondings);
         set_free_free(m->unit_path_cache);
 
+        close_pipe(m->idle_pipe);
+
         free(m);
 }
 
@@ -656,7 +659,6 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
 
 int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool override, DBusError *e, Job **_ret) {
         int r;
-        Job *ret;
         Transaction *tr;
 
         assert(m);
@@ -682,7 +684,7 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove
 
         r = transaction_add_job_and_dependencies(tr, type, unit, NULL, true, override, false,
                                                  mode == JOB_IGNORE_DEPENDENCIES || mode == JOB_IGNORE_REQUIREMENTS,
-                                                 mode == JOB_IGNORE_DEPENDENCIES, e, &ret);
+                                                 mode == JOB_IGNORE_DEPENDENCIES, e);
         if (r < 0)
                 goto tr_abort;
 
@@ -696,10 +698,10 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove
         if (r < 0)
                 goto tr_abort;
 
-        log_debug("Enqueued job %s/%s as %u", unit->id, job_type_to_string(type), (unsigned) ret->id);
+        log_debug("Enqueued job %s/%s as %u", unit->id, job_type_to_string(type), (unsigned) tr->anchor_job->id);
 
         if (_ret)
-                *_ret = ret;
+                *_ret = tr->anchor_job;
 
         transaction_free(tr);
         return 0;
@@ -872,7 +874,8 @@ void manager_clear_jobs(Manager *m) {
         assert(m);
 
         while ((j = hashmap_first(m->jobs)))
-                job_finish_and_invalidate(j, JOB_CANCELED);
+                /* No need to recurse. We're cancelling all jobs. */
+                job_finish_and_invalidate(j, JOB_CANCELED, false);
 }
 
 unsigned manager_dispatch_run_queue(Manager *m) {
@@ -1962,10 +1965,13 @@ void manager_check_finished(Manager *m) {
 
         assert(m);
 
-        if (dual_timestamp_is_set(&m->finish_timestamp))
+        if (hashmap_size(m->jobs) > 0)
                 return;
 
-        if (hashmap_size(m->jobs) > 0)
+        /* Notify Type=idle units that we are done now */
+        close_pipe(m->idle_pipe);
+
+        if (dual_timestamp_is_set(&m->finish_timestamp))
                 return;
 
         dual_timestamp_get(&m->finish_timestamp);