Skip to content

Commit

Permalink
systemctl: print next timer trigger time with the status verb (system…
Browse files Browse the repository at this point in the history
…d#6242)

It is useful to know when a timer will trigger next when looking at a
timer status message so calculate and print that information.

Closes systemd#5738.

Example output:
$ systemctl status dnf-makecache.timer
● dnf-makecache.timer - dnf makecache timer
   Loaded: loaded (/usr/lib/systemd/system/dnf-makecache.timer; enabled; vendor preset: enabled)
   Active: active (waiting) since Tue 2017-07-04 17:24:02 EDT; 24min ago
  Trigger: Tue 2017-07-04 18:15:56 EDT; 27min left
  • Loading branch information
GiedriusS authored and keszybz committed Jul 4, 2017
1 parent 218f467 commit 601b084
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/systemctl/systemctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3818,6 +3818,8 @@ typedef struct UnitStatusInfo {
bool failed_assert_negate;
const char *failed_assert;
const char *failed_assert_parameter;
usec_t next_elapse_real;
usec_t next_elapse_monotonic;

/* Socket */
unsigned n_accepted;
Expand Down Expand Up @@ -3987,6 +3989,31 @@ static void print_status_info(
else
printf("\n");

if (endswith(i->id, ".timer")) {
char tstamp1[FORMAT_TIMESTAMP_RELATIVE_MAX],
tstamp2[FORMAT_TIMESTAMP_MAX];
char *next_rel_time, *next_time;
dual_timestamp nw, next = {i->next_elapse_real,
i->next_elapse_monotonic};
usec_t next_elapse;

printf(" Trigger: ");

dual_timestamp_get(&nw);
next_elapse = calc_next_elapse(&nw, &next);
next_rel_time = format_timestamp_relative(tstamp1,
sizeof(tstamp1),
next_elapse);
next_time = format_timestamp(tstamp2,
sizeof(tstamp2),
next_elapse);

if (next_time && next_rel_time)
printf("%s; %s\n", next_time, next_rel_time);
else
printf("n/a\n");
}

if (!i->condition_result && i->condition_timestamp > 0) {
UnitCondition *c;
int n = 0;
Expand Down Expand Up @@ -4424,6 +4451,10 @@ static int status_property(const char *name, sd_bus_message *m, UnitStatusInfo *
i->tasks_max = u;
else if (streq(name, "CPUUsageNSec"))
i->cpu_usage_nsec = u;
else if (streq(name, "NextElapseUSecMonotonic"))
i->next_elapse_monotonic = u;
else if (streq(name, "NextElapseUSecRealtime"))
i->next_elapse_real = u;

break;
}
Expand Down

0 comments on commit 601b084

Please sign in to comment.