chiark / gitweb /
add functions for dumping server state
[elogind.git] / job.c
diff --git a/job.c b/job.c
index 5cd8f73..87bcd28 100644 (file)
--- a/job.c
+++ b/job.c
@@ -47,13 +47,44 @@ void job_free(Job *j) {
         /* Detach from next 'bigger' objects */
 
         if (j->linked) {
         /* Detach from next 'bigger' objects */
 
         if (j->linked) {
-                if (j->name && j->name->meta.job == j)
-                        j->name->meta.job = NULL;
+                assert(j->name);
+                assert(j->name->meta.job == j);
+                j->name->meta.job = NULL;
 
                 hashmap_remove(j->manager->jobs, UINT32_TO_PTR(j->id));
         }
 
 
                 hashmap_remove(j->manager->jobs, UINT32_TO_PTR(j->id));
         }
 
-        /* Free data and next 'smaller' objects */
+        hashmap_remove(j->manager->jobs_to_add, j->name);
+        set_remove(j->manager->jobs_to_remove, j);
 
 
+        /* Free data and next 'smaller' objects */
         free(j);
 }
         free(j);
 }
+
+void job_dump(Job *j, FILE*f) {
+
+        static const char* const job_type_table[_JOB_TYPE_MAX] = {
+                [JOB_START] = "START",
+                [JOB_STOP] = "STOP",
+                [JOB_VERIFY_STARTED] = "VERIFY_STARTED",
+                [JOB_RELOAD] = "RELOAD",
+                [JOB_RESTART] = "RESTART",
+                [JOB_TRY_RESTART] = "TRY_RESTART",
+                [JOB_RESTART_FINISH] = "RESTART_FINISH"
+        };
+
+        static const char* const job_state_table[_JOB_STATE_MAX] = {
+                [JOB_WAITING] = "WAITING",
+                [JOB_RUNNING] = "RUNNING",
+                [JOB_DONE] = "DONE"
+        };
+
+        assert(j);
+        assert(f);
+
+        fprintf(f, "Job %u: %s → %s in state %s\n",
+                j->id,
+                name_id(j->name),
+                job_type_table[j->type],
+                job_state_table[j->state]);
+}