From d21b0c826f6c9ba365f6257becd260aa9d2d82ff Mon Sep 17 00:00:00 2001 From: Boucman Date: Fri, 2 Feb 2018 15:58:40 +0100 Subject: [PATCH] do not report total time when kernel time is not provided (#8063) the whole systemd-analyze time logic is based on the fact that monotonic time 0 is the start of the kernel. If the firmware does not provide a correct time, firmware_time degrades to 0, which is the start of the kernel. The diference between FinishTime and firmware_time is thus correct. That assumption is still true with containers, but the start time of the kernel is not what the user expects : It's the time when the host booted. The total is thus still correct, but highly misleading. Containers can be easily detected (and, in fact, already are) by systemd not reporting any kernel non-monotonic timestamp. This patch simply avoids printing a misleading time when it can detect that case --- src/analyze/analyze.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 834620a4cd7..aab61e4de3b 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -547,7 +547,8 @@ static int pretty_boot_time(sd_bus *bus, char **_buf) { size = strpcpyf(&ptr, size, "%s (initrd) + ", format_timespan(ts, sizeof(ts), t->userspace_time - t->initrd_time, USEC_PER_MSEC)); size = strpcpyf(&ptr, size, "%s (userspace) ", format_timespan(ts, sizeof(ts), t->finish_time - t->userspace_time, USEC_PER_MSEC)); - strpcpyf(&ptr, size, "= %s", format_timespan(ts, sizeof(ts), t->firmware_time + t->finish_time, USEC_PER_MSEC)); + if (t->kernel_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)) size = strpcpyf(&ptr, size, "\n%s reached after %s in userspace", unit_id, format_timespan(ts, sizeof(ts), activated_time - t->userspace_time, USEC_PER_MSEC)); -- 2.47.3