From 7bbfcf64b3a1cdd0dea9e647fc557fe73940d811 Mon Sep 17 00:00:00 2001 From: David Tardon Date: Wed, 24 May 2023 15:26:32 +0200 Subject: [PATCH] tree-wide: use timestamp_is_set() at more places --- src/analyze/analyze-critical-chain.c | 2 +- src/analyze/analyze-plot.c | 18 +++++++++--------- src/analyze/analyze-time-data.c | 12 ++++++------ src/core/socket.c | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/analyze/analyze-critical-chain.c b/src/analyze/analyze-critical-chain.c index f80f3ddb63c..4a7f452eaf5 100644 --- a/src/analyze/analyze-critical-chain.c +++ b/src/analyze/analyze-critical-chain.c @@ -29,7 +29,7 @@ static int list_dependencies_print( printf("%s", special_glyph(last ? SPECIAL_GLYPH_TREE_RIGHT : SPECIAL_GLYPH_TREE_BRANCH)); if (times) { - if (times->time > 0) + if (timestamp_is_set(times->time)) printf("%s%s @%s +%s%s", ansi_highlight_red(), name, FORMAT_TIMESPAN(times->activating - boot->userspace_time, USEC_PER_MSEC), FORMAT_TIMESPAN(times->time, USEC_PER_MSEC), ansi_normal()); diff --git a/src/analyze/analyze-plot.c b/src/analyze/analyze-plot.c index ef40e64631d..0fbe17465e0 100644 --- a/src/analyze/analyze-plot.c +++ b/src/analyze/analyze-plot.c @@ -206,14 +206,14 @@ static int produce_plot_as_svg( if (boot->firmware_time > boot->loader_time) m++; - if (boot->loader_time > 0) { + if (timestamp_is_set(boot->loader_time)) { m++; if (width < 1000.0) width = 1000.0; } - if (boot->initrd_time > 0) + if (timestamp_is_set(boot->initrd_time)) m++; - if (boot->kernel_done_time > 0) + if (timestamp_is_set(boot->kernel_done_time)) m++; for (u = times; u->has_data; u++) { @@ -295,22 +295,22 @@ static int produce_plot_as_svg( svg("\n", 20.0 + (SCALE_X * boot->firmware_time)); svg_graph_box(m, -(double) boot->firmware_time, boot->finish_time); - if (boot->firmware_time > 0) { + if (timestamp_is_set(boot->firmware_time)) { svg_bar("firmware", -(double) boot->firmware_time, -(double) boot->loader_time, y); svg_text(true, -(double) boot->firmware_time, y, "firmware"); y++; } - if (boot->loader_time > 0) { + if (timestamp_is_set(boot->loader_time)) { svg_bar("loader", -(double) boot->loader_time, 0, y); svg_text(true, -(double) boot->loader_time, y, "loader"); y++; } - if (boot->kernel_done_time > 0) { + if (timestamp_is_set(boot->kernel_done_time)) { svg_bar("kernel", 0, boot->kernel_done_time, y); svg_text(true, 0, y, "kernel"); y++; } - if (boot->initrd_time > 0) { + if (timestamp_is_set(boot->initrd_time)) { svg_bar("initrd", boot->initrd_time, boot->userspace_time, y); if (boot->initrd_security_start_time < boot->initrd_security_finish_time) svg_bar("security", boot->initrd_security_start_time, boot->initrd_security_finish_time, y); @@ -330,7 +330,7 @@ static int produce_plot_as_svg( } svg_bar("active", boot->userspace_time, boot->finish_time, y); - if (boot->security_start_time > 0) + if (timestamp_is_set(boot->security_start_time)) svg_bar("security", boot->security_start_time, boot->security_finish_time, y); svg_bar("generators", boot->generators_start_time, boot->generators_finish_time, y); svg_bar("unitsload", boot->unitsload_start_time, boot->unitsload_finish_time, y); @@ -354,7 +354,7 @@ static int produce_plot_as_svg( svg_bar("deactivating", 0, 300000, y); svg_text(true, 400000, y, "Deactivating"); y++; - if (boot->security_start_time > 0) { + if (timestamp_is_set(boot->security_start_time)) { svg_bar("security", 0, 300000, y); svg_text(true, 400000, y, "Setting up security module"); y++; diff --git a/src/analyze/analyze-time-data.c b/src/analyze/analyze-time-data.c index baee3cedbb5..70717fc4b27 100644 --- a/src/analyze/analyze-time-data.c +++ b/src/analyze/analyze-time-data.c @@ -173,24 +173,24 @@ int pretty_boot_time(sd_bus *bus, char **ret) { if (!text) return log_oom(); - if (t->firmware_time > 0 && !strextend(&text, FORMAT_TIMESPAN(t->firmware_time - t->loader_time, USEC_PER_MSEC), " (firmware) + ")) + if (timestamp_is_set(t->firmware_time) && !strextend(&text, FORMAT_TIMESPAN(t->firmware_time - t->loader_time, USEC_PER_MSEC), " (firmware) + ")) return log_oom(); - if (t->loader_time > 0 && !strextend(&text, FORMAT_TIMESPAN(t->loader_time, USEC_PER_MSEC), " (loader) + ")) + if (timestamp_is_set(t->loader_time) && !strextend(&text, FORMAT_TIMESPAN(t->loader_time, USEC_PER_MSEC), " (loader) + ")) return log_oom(); - if (t->kernel_done_time > 0 && !strextend(&text, FORMAT_TIMESPAN(t->kernel_done_time, USEC_PER_MSEC), " (kernel) + ")) + if (timestamp_is_set(t->kernel_done_time) && !strextend(&text, FORMAT_TIMESPAN(t->kernel_done_time, USEC_PER_MSEC), " (kernel) + ")) return log_oom(); - if (t->initrd_time > 0 && !strextend(&text, FORMAT_TIMESPAN(t->userspace_time - t->initrd_time, USEC_PER_MSEC), " (initrd) + ")) + if (timestamp_is_set(t->initrd_time) && !strextend(&text, FORMAT_TIMESPAN(t->userspace_time - t->initrd_time, USEC_PER_MSEC), " (initrd) + ")) return log_oom(); if (!strextend(&text, FORMAT_TIMESPAN(t->finish_time - t->userspace_time, USEC_PER_MSEC), " (userspace) ")) return log_oom(); - if (t->kernel_done_time > 0) + if (timestamp_is_set(t->kernel_done_time)) if (!strextend(&text, "= ", FORMAT_TIMESPAN(t->firmware_time + t->finish_time, USEC_PER_MSEC), " ")) return log_oom(); if (unit_id && timestamp_is_set(activated_time)) { - usec_t base = t->userspace_time > 0 ? t->userspace_time : t->reverse_offset; + usec_t base = timestamp_is_set(t->userspace_time) ? t->userspace_time : t->reverse_offset; if (!strextend(&text, "\n", unit_id, " reached after ", FORMAT_TIMESPAN(activated_time - base, USEC_PER_MSEC), " in userspace.")) return log_oom(); diff --git a/src/core/socket.c b/src/core/socket.c index 0bd1b126526..d54d9e2db23 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -716,7 +716,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) { prefix, strna(s->user), prefix, strna(s->group)); - if (s->keep_alive_time > 0) + if (timestamp_is_set(s->keep_alive_time)) fprintf(f, "%sKeepAliveTimeSec: %s\n", prefix, FORMAT_TIMESPAN(s->keep_alive_time, USEC_PER_SEC)); @@ -973,7 +973,7 @@ static void socket_apply_socket_options(Socket *s, SocketPort *p, int fd) { log_unit_warning_errno(UNIT(s), r, "SO_KEEPALIVE failed: %m"); } - if (s->keep_alive_time > 0) { + if (timestamp_is_set(s->keep_alive_time)) { r = setsockopt_int(fd, SOL_TCP, TCP_KEEPIDLE, s->keep_alive_time / USEC_PER_SEC); if (r < 0) log_unit_warning_errno(UNIT(s), r, "TCP_KEEPIDLE failed: %m"); -- 2.47.3