]> err.no Git - systemd/commitdiff
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 14f18eb921649ab2baed81fc6206fd08032ab10b..b6a1da7fa46a1c0635cc3e22146402bda4bacd13 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 5cf78966a15f9f2fbdd94cf0df5eeadd19ef9f7f..49bdae7258c9819b8d55940d006a36ebd5b629b0 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 fd9bdae1ad66ff6923ee46efd8cf4ab5a954fc2b..1775c1daf2d2c62e6fdf2e5d9cfe947dc1189e9e 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 9a82c71dcb249b1e268f8959385fecbc05782f59..fecdee12e275b89f2b1220f9374142d550f13028 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 3256fbaafc8093e33778c2b518bbb5dd5d083e7f..b469009bf7e151da121beb6e103f90236f1d3b28 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)