summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-02-15 20:29:59 +0100
committerLennart Poettering <lennart@poettering.net>2016-02-15 20:29:59 +0100
commit11ab173d4067a4ed6fab811ba2159456053fd4c1 (patch)
tree509a4ca821d87238e73de76087473a169eb9f45a
parent251b4cb6a256d5766ff5b47a4be9057934fe528d (diff)
parentd4c6cc937c4943d3195e0d2169bb52c466507b8e (diff)
Merge pull request #2611 from 0xAX/deserialize-clkid
time-util: introduce deserialize_timestamp_value()
-rw-r--r--src/basic/time-util.c13
-rw-r--r--src/basic/time-util.h1
-rw-r--r--src/login/logind-session.c13
-rw-r--r--src/login/logind-user.c13
-rw-r--r--src/machine/machine.c13
5 files changed, 20 insertions, 33 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index 510f018d9b..ac5988fdf9 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -459,6 +459,19 @@ int dual_timestamp_deserialize(const char *value, dual_timestamp *t) {
return 0;
}
+int deserialize_timestamp_value(const char *value, usec_t *timestamp) {
+ int r;
+
+ assert(value);
+
+ r = safe_atou64(value, timestamp);
+
+ if (r < 0)
+ return log_debug_errno(r, "Failed to parse finish timestamp value \"%s\": %m", value);
+
+ return r;
+}
+
int parse_timestamp(const char *t, usec_t *usec) {
static const struct {
const char *name;
diff --git a/src/basic/time-util.h b/src/basic/time-util.h
index 9894e626c5..a826ad75ec 100644
--- a/src/basic/time-util.h
+++ b/src/basic/time-util.h
@@ -99,6 +99,7 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy);
void dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t);
int dual_timestamp_deserialize(const char *value, dual_timestamp *t);
+int deserialize_timestamp_value(const char *value, usec_t *timestamp);
int parse_timestamp(const char *t, usec_t *usec);
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index 417b7f5d98..9874cdae5e 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -446,17 +446,8 @@ int session_load(Session *s) {
safe_close(fd);
}
- if (realtime) {
- unsigned long long l;
- if (sscanf(realtime, "%llu", &l) > 0)
- s->timestamp.realtime = l;
- }
-
- if (monotonic) {
- unsigned long long l;
- if (sscanf(monotonic, "%llu", &l) > 0)
- s->timestamp.monotonic = l;
- }
+ deserialize_timestamp_value(realtime, &s->timestamp.realtime);
+ deserialize_timestamp_value(monotonic, &s->timestamp.monotonic);
if (controller) {
if (bus_name_has_owner(s->manager->bus, controller, NULL) > 0)
diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index 6b9c69cc45..aa27f73a87 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -321,17 +321,8 @@ int user_load(User *u) {
if (s && s->display && display_is_local(s->display))
u->display = s;
- if (realtime) {
- unsigned long long l;
- if (sscanf(realtime, "%llu", &l) > 0)
- u->timestamp.realtime = l;
- }
-
- if (monotonic) {
- unsigned long long l;
- if (sscanf(monotonic, "%llu", &l) > 0)
- u->timestamp.monotonic = l;
- }
+ deserialize_timestamp_value(realtime, &u->timestamp.realtime);
+ deserialize_timestamp_value(monotonic, &u->timestamp.monotonic);
return r;
}
diff --git a/src/machine/machine.c b/src/machine/machine.c
index 406d5a4b85..7e92ffc474 100644
--- a/src/machine/machine.c
+++ b/src/machine/machine.c
@@ -299,17 +299,8 @@ int machine_load(Machine *m) {
m->class = c;
}
- if (realtime) {
- unsigned long long l;
- if (sscanf(realtime, "%llu", &l) > 0)
- m->timestamp.realtime = l;
- }
-
- if (monotonic) {
- unsigned long long l;
- if (sscanf(monotonic, "%llu", &l) > 0)
- m->timestamp.monotonic = l;
- }
+ deserialize_timestamp_value(realtime, &m->timestamp.realtime);
+ deserialize_timestamp_value(monotonic, &m->timestamp.monotonic);
if (netif) {
size_t allocated = 0, nr = 0;