chiark / gitweb /
service: unify tstamp serialization code
authorLennart Poettering <lennart@poettering.net>
Thu, 28 Oct 2010 01:16:03 +0000 (03:16 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 28 Oct 2010 01:16:03 +0000 (03:16 +0200)
src/manager.c
src/service.c
src/unit.c
src/util.c
src/util.h

index 14f18eb..b6a1da7 100644 (file)
@@ -2545,9 +2545,9 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
                         break;
 
                 if (startswith(l, "startup-timestamp="))
-                        dual_timestamp_deserialize(f, l+18, &m->startup_timestamp);
+                        dual_timestamp_deserialize(l+18, &m->startup_timestamp);
                 else if (startswith(l, "finish-timestamp="))
-                        dual_timestamp_deserialize(f, l+17, &m->finish_timestamp);
+                        dual_timestamp_deserialize(l+17, &m->finish_timestamp);
                 else
                         log_debug("Unknown serialization item '%s'", l);
         }
index 5cf7896..49bdae7 100644 (file)
@@ -2299,21 +2299,10 @@ static int service_serialize(Unit *u, FILE *f, FDSet *fds) {
 
         if (s->main_exec_status.pid > 0) {
                 unit_serialize_item_format(u, f, "main-exec-status-pid", "%lu", (unsigned long) s->main_exec_status.pid);
+                dual_timestamp_serialize(f, "main-exec-status-start", &s->main_exec_status.start_timestamp);
+                dual_timestamp_serialize(f, "main-exec-status-exit", &s->main_exec_status.exit_timestamp);
 
-                if (s->main_exec_status.start_timestamp.realtime > 0) {
-                        unit_serialize_item_format(u, f, "main-exec-status-start-realtime",
-                                                   "%llu", (unsigned long long) s->main_exec_status.start_timestamp.realtime);
-
-                        unit_serialize_item_format(u, f, "main-exec-status-start-monotonic",
-                                                   "%llu", (unsigned long long) s->main_exec_status.start_timestamp.monotonic);
-                }
-
-                if (s->main_exec_status.exit_timestamp.realtime > 0) {
-                        unit_serialize_item_format(u, f, "main-exec-status-exit-realtime",
-                                                   "%llu", (unsigned long long) s->main_exec_status.exit_timestamp.realtime);
-                        unit_serialize_item_format(u, f, "main-exec-status-exit-monotonic",
-                                                   "%llu", (unsigned long long) s->main_exec_status.exit_timestamp.monotonic);
-
+                if (dual_timestamp_is_set(&s->main_exec_status.exit_timestamp)) {
                         unit_serialize_item_format(u, f, "main-exec-status-code", "%i", s->main_exec_status.code);
                         unit_serialize_item_format(u, f, "main-exec-status-status", "%i", s->main_exec_status.status);
                 }
@@ -2414,35 +2403,11 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
                         log_debug("Failed to parse main-exec-status-status value %s", value);
                 else
                         s->main_exec_status.status = i;
-        } else if (streq(key, "main-exec-status-start-realtime")) {
-                uint64_t k;
-
-                if (safe_atou64(value, &k) < 0)
-                        log_debug("Failed to parse main-exec-status-start-realtime value %s", value);
-                else
-                        s->main_exec_status.start_timestamp.realtime = (usec_t) k;
-        } else if (streq(key, "main-exec-status-start-monotonic")) {
-                uint64_t k;
-
-                if (safe_atou64(value, &k) < 0)
-                        log_debug("Failed to parse main-exec-status-start-monotonic value %s", value);
-                else
-                        s->main_exec_status.start_timestamp.monotonic = (usec_t) k;
-        } else if (streq(key, "main-exec-status-exit-realtime")) {
-                uint64_t k;
-
-                if (safe_atou64(value, &k) < 0)
-                        log_debug("Failed to parse main-exec-status-exit-realtime value %s", value);
-                else
-                        s->main_exec_status.exit_timestamp.realtime = (usec_t) k;
-        } else if (streq(key, "main-exec-status-exit-monotonic")) {
-                uint64_t k;
-
-                if (safe_atou64(value, &k) < 0)
-                        log_debug("Failed to parse main-exec-status-exit-monotonic value %s", value);
-                else
-                        s->main_exec_status.exit_timestamp.monotonic = (usec_t) k;
-        } else
+        } else if (streq(key, "main-exec-status-start"))
+                dual_timestamp_deserialize(value, &s->main_exec_status.start_timestamp);
+        else if (streq(key, "main-exec-status-exit"))
+                dual_timestamp_deserialize(value, &s->main_exec_status.exit_timestamp);
+        else
                 log_debug("Unknown serialization key '%s'", key);
 
         return 0;
index fd9bdae..1775c1d 100644 (file)
@@ -2088,16 +2088,16 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
 
                         continue;
                 } else if (streq(l, "inactive-exit-timestamp")) {
-                        dual_timestamp_deserialize(f, v, &u->meta.inactive_exit_timestamp);
+                        dual_timestamp_deserialize(v, &u->meta.inactive_exit_timestamp);
                         continue;
                 } else if (streq(l, "active-enter-timestamp")) {
-                        dual_timestamp_deserialize(f, v, &u->meta.active_enter_timestamp);
+                        dual_timestamp_deserialize(v, &u->meta.active_enter_timestamp);
                         continue;
                 } else if (streq(l, "active-exit-timestamp")) {
-                        dual_timestamp_deserialize(f, v, &u->meta.active_exit_timestamp);
+                        dual_timestamp_deserialize(v, &u->meta.active_exit_timestamp);
                         continue;
                 } else if (streq(l, "inactive-enter-timestamp")) {
-                        dual_timestamp_deserialize(f, v, &u->meta.inactive_enter_timestamp);
+                        dual_timestamp_deserialize(v, &u->meta.inactive_enter_timestamp);
                         continue;
                 }
 
index 9a82c71..fecdee1 100644 (file)
@@ -3552,10 +3552,9 @@ void dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t) {
                 (unsigned long long) t->monotonic);
 }
 
-void dual_timestamp_deserialize(FILE *f, const char *value, dual_timestamp *t) {
+void dual_timestamp_deserialize(const char *value, dual_timestamp *t) {
         unsigned long long a, b;
 
-        assert(f);
         assert(value);
         assert(t);
 
index 3256fba..b469009 100644 (file)
@@ -368,7 +368,7 @@ DIR *xopendirat(int dirfd, const char *name);
 int ask_password_tty(const char *message, usec_t until, const char *flag_file, char **_passphrase);
 
 void dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t);
-void dual_timestamp_deserialize(FILE *f, const char *line, dual_timestamp *t);
+void dual_timestamp_deserialize(const char *value, dual_timestamp *t);
 
 #define NULSTR_FOREACH(i, l) \
         for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)