]> err.no Git - systemd/commitdiff
add functions for dumping server state
authorLennart Poettering <lennart@poettering.net>
Mon, 18 Jan 2010 23:22:34 +0000 (00:22 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 18 Jan 2010 23:22:34 +0000 (00:22 +0100)
job.c
job.h
main.c
manager.c
manager.h
name.c
name.h

diff --git a/job.c b/job.c
index 689908aeb4c6c4c03778a598d153d3d52ae05339..87bcd289d98eafc8185fcbc2f194172eb431acf2 100644 (file)
--- a/job.c
+++ b/job.c
@@ -60,3 +60,31 @@ void job_free(Job *j) {
         /* Free data and next 'smaller' objects */
         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]);
+}
diff --git a/job.h b/job.h
index d19f747dbdfc3c3c0313553b27b64007b515820b..0fc6fec4625316865faf1d43fd71359563b8a9e7 100644 (file)
--- a/job.h
+++ b/job.h
@@ -53,5 +53,6 @@ struct Job {
 Job* job_new(Manager *m, JobType type, Name *name);
 int job_link(Job *job);
 void job_free(Job *job);
+void job_dump(Job *j, FILE*f);
 
 #endif
diff --git a/main.c b/main.c
index 08ccd4f8dc87139f10635bc44a3b95bf2ac93aa0..f19fb6b5cdfc400923034d2ff69820f8172e514c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -23,10 +23,12 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        if ((r = manager_add_job(m, JOB_START, milestone, JOB_REPLACE, &job)) < 0) {
-                fprintf(stderr, "Failed to start default milestone: %s\n", strerror(-r));
-                goto finish;
-        }
+        manager_dump_names(m, stdout);
+
+        /* if ((r = manager_add_job(m, JOB_START, milestone, JOB_REPLACE, &job)) < 0) { */
+        /*         fprintf(stderr, "Failed to start default milestone: %s\n", strerror(-r)); */
+        /*         goto finish; */
+        /* } */
 
         retval = 0;
 
index 0ad60b2b0bd85dea191782aaf718ff73f21c3304..86ed086eb31c3f48f586a9b38831f2dbcc7d5d2d 100644 (file)
--- a/manager.c
+++ b/manager.c
@@ -333,3 +333,25 @@ finish:
         *_ret = ret;
         return 0;
 }
+
+void manager_dump_jobs(Manager *s, FILE *f) {
+        void *state;
+        Job *j;
+
+        assert(s);
+        assert(f);
+
+        HASHMAP_FOREACH(j, s->jobs, state)
+                job_dump(j, f);
+}
+
+void manager_dump_names(Manager *s, FILE *f) {
+        void *state;
+        Name *n;
+
+        assert(s);
+        assert(f);
+
+        HASHMAP_FOREACH(n, s->names, state)
+                name_dump(n, f);
+}
index 64c4c9d14cf3b2731ae64dc9ff41467834ed45d3..c08f3ccde5a9f1e149024f4dd3a71c1e19a101aa 100644 (file)
--- a/manager.h
+++ b/manager.h
@@ -5,6 +5,7 @@
 
 #include <stdbool.h>
 #include <inttypes.h>
+#include <stdio.h>
 
 typedef struct Manager Manager;
 
@@ -44,4 +45,7 @@ Name *manager_get_name(Manager *m, const char *name);
 int manager_load_name(Manager *m, const char *name, Name **_ret);
 int manager_add_job(Manager *m, JobType job, Name *name, JobMode mode, Job **_ret);
 
+void manager_dump_names(Manager *s, FILE *f);
+void manager_dump_jobs(Manager *s, FILE *f);
+
 #endif
diff --git a/name.c b/name.c
index f29ce2298bbf3f73d2f203deb4b3f22cd71b5c06..80ce5d5b36a6a2bff20d35b3e9d124506f95ea02 100644 (file)
--- a/name.c
+++ b/name.c
@@ -112,7 +112,6 @@ static void bidi_set_free(Name *name, Set *s) {
         Name *other;
 
         assert(name);
-        assert(s);
 
         /* Frees the set and makes sure we are dropped from the
          * inverse pointers */
@@ -360,3 +359,31 @@ int name_merge(Name *name, Name *other) {
 
         return 0;
 }
+
+const char* name_id(Name *n) {
+        assert(n);
+
+        return set_first(n->meta.names);
+}
+
+void name_dump(Name *n, FILE *f) {
+
+        static const char* const state_table[_NAME_STATE_MAX] = {
+                [NAME_STUB] = "STUB",
+                [NAME_LOADED] = "LOADED",
+                [NAME_FAILED] = "FAILED"
+        };
+
+        assert(n);
+
+        fprintf(stderr,
+                "Name %s (%s), state %s\n",
+                name_id(n),
+                n->meta.description ? n->meta.description : name_id(n),
+                state_table[n->meta.state]);
+
+        if (n->meta.job) {
+                fprintf(f, "\t▶ ");
+                job_dump(n->meta.job, f);
+        }
+}
diff --git a/name.h b/name.h
index 696953108d33d5c62d6a007c9daa51dbb742fbe0..116523453763e2a5bdf1c7aa35fc176851c598a5 100644 (file)
--- a/name.h
+++ b/name.h
@@ -39,7 +39,8 @@ typedef enum NameType {
 typedef enum NameState {
         NAME_STUB,
         NAME_LOADED,
-        NAME_FAILED
+        NAME_FAILED,
+        _NAME_STATE_MAX
 } NameState;
 
 typedef enum NameDependency {
@@ -276,5 +277,8 @@ void name_free(Name *name);
 int name_link(Name *name);
 int name_merge(Name *name, Name *other);
 int name_augment(Name *n);
+const char* name_id(Name *n);
+
+void name_dump(Name *n, FILE *f);
 
 #endif