summaryrefslogtreecommitdiff
path: root/src/systemctl/systemctl.c
diff options
context:
space:
mode:
authorDjalal Harouni <tixxdz@opendz.org>2014-02-24 01:42:24 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-02-23 23:53:25 -0500
commitf5080e738512f92564e272d5dcbb357a1eceaa18 (patch)
tree3d4547b6bb408a9543dde5776c9c8af0602e949d /src/systemctl/systemctl.c
parent454f7158c6cecd18555c5e7dd556e3d544301b52 (diff)
systemctl: move next elapse calculation to its own function
Diffstat (limited to 'src/systemctl/systemctl.c')
-rw-r--r--src/systemctl/systemctl.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index c5ca8dc11d..34d7079299 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -908,6 +908,31 @@ static int output_timers_list(struct timer_info *timer_infos, unsigned n) {
return 0;
}
+static usec_t calc_next_elapse(dual_timestamp *nw, dual_timestamp *next) {
+ usec_t next_elapse;
+
+ assert(nw);
+ assert(next);
+
+ if (next->monotonic != (usec_t) -1 && next->monotonic > 0) {
+ usec_t converted;
+
+ if (next->monotonic > nw->monotonic)
+ converted = nw->realtime + (next->monotonic - nw->monotonic);
+ else
+ converted = nw->realtime - (nw->monotonic - next->monotonic);
+
+ if (next->realtime != (usec_t) -1 && next->realtime > 0)
+ next_elapse = MIN(converted, next->realtime);
+ else
+ next_elapse = converted;
+
+ } else
+ next_elapse = next->realtime;
+
+ return next_elapse;
+}
+
static int list_timers(sd_bus *bus, char **args) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
@@ -944,26 +969,13 @@ static int list_timers(sd_bus *bus, char **args) {
if (r < 0)
goto cleanup;
- if (next.monotonic != (usec_t) -1 && next.monotonic > 0) {
- usec_t converted;
-
- if (next.monotonic > nw.monotonic)
- converted = nw.realtime + (next.monotonic - nw.monotonic);
- else
- converted = nw.realtime - (nw.monotonic - next.monotonic);
-
- if (next.realtime != (usec_t) -1 && next.realtime > 0)
- m = MIN(converted, next.realtime);
- else
- m = converted;
- } else
- m = next.realtime;
-
if (!GREEDY_REALLOC(timer_infos, size, c+1)) {
r = log_oom();
goto cleanup;
}
+ m = calc_next_elapse(&nw, &next);
+
timer_infos[c++] = (struct timer_info) {
.id = u->id,
.next_elapse = m,