1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-13 00:58:27 +03:00

systemctl: move next elapse calculation to its own function

This commit is contained in:
Djalal Harouni 2014-02-24 01:42:24 +01:00 committed by Zbigniew Jędrzejewski-Szmek
parent 454f7158c6
commit f5080e7385

View File

@ -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,