diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-07-05 17:15:00 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-05 17:15:00 +0900 |
commit | 6a54fb8f1e51e5e5116810ff6552dd1af8c6c600 (patch) | |
tree | 3456f3f8f4aea667d2c79464adfc7a0d3c74c867 | |
parent | 7e69d90c8d38d00ab6bc40073957108107ca2100 (diff) | |
parent | 3454129571c65c60a967b3b48069f5292e516904 (diff) | |
download | systemd-6a54fb8f1e51e5e5116810ff6552dd1af8c6c600.tar.gz |
Merge pull request #12963 from keszybz/analyze-timestamp
systemd-analyze dump fixup
-rw-r--r-- | src/analyze/analyze.c | 2 | ||||
-rw-r--r-- | src/basic/time-util.h | 14 | ||||
-rw-r--r-- | src/core/job.c | 2 | ||||
-rw-r--r-- | src/core/main.c | 2 | ||||
-rw-r--r-- | src/core/manager.c | 12 | ||||
-rw-r--r-- | src/run/run.c | 4 | ||||
-rw-r--r-- | src/systemctl/systemctl.c | 4 |
7 files changed, 23 insertions, 17 deletions
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 40f54f9d46..97642660e4 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -544,7 +544,7 @@ static int pretty_boot_time(sd_bus *bus, char **_buf) { if (t->kernel_done_time > 0) strpcpyf(&ptr, size, "= %s ", format_timespan(ts, sizeof(ts), t->firmware_time + t->finish_time, USEC_PER_MSEC)); - if (unit_id && activated_time > 0 && activated_time != USEC_INFINITY) { + if (unit_id && timestamp_is_set(activated_time)) { usec_t base = t->userspace_time > 0 ? t->userspace_time : t->reverse_offset; size = strpcpyf(&ptr, size, "\n%s reached after %s in userspace", unit_id, diff --git a/src/basic/time-util.h b/src/basic/time-util.h index a238f6914d..e3a529d970 100644 --- a/src/basic/time-util.h +++ b/src/basic/time-util.h @@ -81,15 +81,19 @@ triple_timestamp* triple_timestamp_from_realtime(triple_timestamp *ts, usec_t u) #define TRIPLE_TIMESTAMP_HAS_CLOCK(clock) \ IN_SET(clock, CLOCK_REALTIME, CLOCK_REALTIME_ALARM, CLOCK_MONOTONIC, CLOCK_BOOTTIME, CLOCK_BOOTTIME_ALARM) +static inline bool timestamp_is_set(usec_t timestamp) { + return timestamp > 0 && timestamp != USEC_INFINITY; +} + static inline bool dual_timestamp_is_set(const dual_timestamp *ts) { - return ((ts->realtime > 0 && ts->realtime != USEC_INFINITY) || - (ts->monotonic > 0 && ts->monotonic != USEC_INFINITY)); + return timestamp_is_set(ts->realtime) || + timestamp_is_set(ts->monotonic); } static inline bool triple_timestamp_is_set(const triple_timestamp *ts) { - return ((ts->realtime > 0 && ts->realtime != USEC_INFINITY) || - (ts->monotonic > 0 && ts->monotonic != USEC_INFINITY) || - (ts->boottime > 0 && ts->boottime != USEC_INFINITY)); + return timestamp_is_set(ts->realtime) || + timestamp_is_set(ts->monotonic) || + timestamp_is_set(ts->boottime); } usec_t triple_timestamp_by_clock(triple_timestamp *ts, clockid_t clock); diff --git a/src/core/job.c b/src/core/job.c index 81f5f9cb72..df7eacfbc0 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -1347,7 +1347,7 @@ int job_coldplug(Job *j) { if (j->unit->job_timeout != USEC_INFINITY) timeout_time = usec_add(j->begin_usec, j->unit->job_timeout); - if (j->begin_running_usec > 0 && j->unit->job_running_timeout != USEC_INFINITY) + if (timestamp_is_set(j->begin_running_usec)) timeout_time = MIN(timeout_time, usec_add(j->begin_running_usec, j->unit->job_running_timeout)); if (timeout_time == USEC_INFINITY) diff --git a/src/core/main.c b/src/core/main.c index 04a6ff6366..f5dcfa09be 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1952,7 +1952,7 @@ static int initialize_runtime( log_warning_errno(r, "Failed to set watchdog device to %s, ignoring: %m", arg_watchdog_device); } - if (arg_runtime_watchdog > 0 && arg_runtime_watchdog != USEC_INFINITY) + if (timestamp_is_set(arg_runtime_watchdog)) watchdog_set_timeout(&arg_runtime_watchdog); } diff --git a/src/core/manager.c b/src/core/manager.c index 0c1adf2850..4a2f07368a 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -2094,13 +2094,15 @@ void manager_dump(Manager *m, FILE *f, const char *prefix) { assert(f); for (q = 0; q < _MANAGER_TIMESTAMP_MAX; q++) { - char buf[FORMAT_TIMESTAMP_MAX]; + const dual_timestamp *t = m->timestamps + q; + char buf[CONST_MAX(FORMAT_TIMESPAN_MAX, FORMAT_TIMESTAMP_MAX)]; - if (dual_timestamp_is_set(m->timestamps + q)) + if (dual_timestamp_is_set(t)) fprintf(f, "%sTimestamp %s: %s\n", strempty(prefix), manager_timestamp_to_string(q), - format_timestamp(buf, sizeof(buf), m->timestamps[q].realtime)); + timestamp_is_set(t->realtime) ? format_timestamp(buf, sizeof buf, t->realtime) : + format_timespan(buf, sizeof buf, t->monotonic, 1)); } manager_dump_units(m, f, prefix); @@ -2896,7 +2898,7 @@ int manager_loop(Manager *m) { while (m->objective == MANAGER_OK) { usec_t wait_usec; - if (m->runtime_watchdog > 0 && m->runtime_watchdog != USEC_INFINITY && MANAGER_IS_SYSTEM(m)) + if (timestamp_is_set(m->runtime_watchdog) && MANAGER_IS_SYSTEM(m)) watchdog_ping(); if (!ratelimit_below(&rl)) { @@ -2927,7 +2929,7 @@ int manager_loop(Manager *m) { continue; /* Sleep for half the watchdog time */ - if (m->runtime_watchdog > 0 && m->runtime_watchdog != USEC_INFINITY && MANAGER_IS_SYSTEM(m)) { + if (timestamp_is_set(m->runtime_watchdog) && MANAGER_IS_SYSTEM(m)) { wait_usec = m->runtime_watchdog / 2; if (wait_usec <= 0) wait_usec = 1; diff --git a/src/run/run.c b/src/run/run.c index 05c1552a8b..c11b7f57ff 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -1266,8 +1266,8 @@ static int start_transient_service( else if (c.exit_code > 0) log_info("Main processes terminated with: code=%s/status=%s", sigchld_code_to_string(c.exit_code), signal_to_string(c.exit_status)); - if (c.inactive_enter_usec > 0 && c.inactive_enter_usec != USEC_INFINITY && - c.inactive_exit_usec > 0 && c.inactive_exit_usec != USEC_INFINITY && + if (timestamp_is_set(c.inactive_enter_usec) && + timestamp_is_set(c.inactive_exit_usec) && c.inactive_enter_usec > c.inactive_exit_usec) { char ts[FORMAT_TIMESPAN_MAX]; log_info("Service runtime: %s", format_timespan(ts, sizeof(ts), c.inactive_enter_usec - c.inactive_exit_usec, USEC_PER_MSEC)); diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index dbe442d7da..8eb9498c19 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -1228,7 +1228,7 @@ static usec_t calc_next_elapse(dual_timestamp *nw, dual_timestamp *next) { assert(nw); assert(next); - if (next->monotonic != USEC_INFINITY && next->monotonic > 0) { + if (timestamp_is_set(next->monotonic)) { usec_t converted; if (next->monotonic > nw->monotonic) @@ -1236,7 +1236,7 @@ static usec_t calc_next_elapse(dual_timestamp *nw, dual_timestamp *next) { else converted = nw->realtime - (nw->monotonic - next->monotonic); - if (next->realtime != USEC_INFINITY && next->realtime > 0) + if (timestamp_is_set(next->realtime)) next_elapse = MIN(converted, next->realtime); else next_elapse = converted; |