]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
analyze: make blame command work even the default target not reached
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 9 Apr 2023 18:37:51 +0000 (03:37 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 9 Apr 2023 18:41:15 +0000 (03:41 +0900)
src/analyze/analyze-blame.c
src/analyze/analyze-critical-chain.c
src/analyze/analyze-plot.c
src/analyze/analyze-time-data.c
src/analyze/analyze-time-data.h

index c9112685f8323d7bf88b65db8873c218382db8f4..81e5c590b9cc248453a61f46a533959c432b73f3 100644 (file)
@@ -16,7 +16,7 @@ int verb_blame(int argc, char *argv[], void *userdata) {
         if (r < 0)
                 return bus_log_connect_error(r, arg_transport);
 
-        n = acquire_time_data(bus, &times);
+        n = acquire_time_data(bus, /* require_finished = */ false, &times);
         if (n <= 0)
                 return n;
 
index f782f95d5f229b9359537d6bff1c4542db514c71..f80f3ddb63c2e2ae7d05f5ebf6c76ab2c8f88687 100644 (file)
@@ -93,7 +93,7 @@ static int list_dependencies_one(sd_bus *bus, const char *name, unsigned level,
 
         typesafe_qsort(deps, strv_length(deps), list_dependencies_compare);
 
-        r = acquire_boot_times(bus, &boot);
+        r = acquire_boot_times(bus, /* require_finished = */ true, &boot);
         if (r < 0)
                 return r;
 
@@ -178,7 +178,7 @@ static int list_dependencies(sd_bus *bus, const char *name) {
 
         times = hashmap_get(unit_times_hashmap, id);
 
-        r = acquire_boot_times(bus, &boot);
+        r = acquire_boot_times(bus, /* require_finished = */ true, &boot);
         if (r < 0)
                 return r;
 
@@ -205,7 +205,7 @@ int verb_critical_chain(int argc, char *argv[], void *userdata) {
         if (r < 0)
                 return bus_log_connect_error(r, arg_transport);
 
-        n = acquire_time_data(bus, &times);
+        n = acquire_time_data(bus, /* require_finished = */ true, &times);
         if (n <= 0)
                 return n;
 
index e44b9c11f62affded0ce27177e0204ece9853451..ef40e64631d5d268aec0d7ac3b831d0dc8498359 100644 (file)
@@ -439,7 +439,7 @@ int verb_plot(int argc, char *argv[], void *userdata) {
         if (r < 0)
                 return bus_log_connect_error(r, arg_transport);
 
-        n = acquire_boot_times(bus, &boot);
+        n = acquire_boot_times(bus, /* require_finished = */ true, &boot);
         if (n < 0)
                 return n;
 
@@ -453,7 +453,7 @@ int verb_plot(int argc, char *argv[], void *userdata) {
                         return n;
         }
 
-        n = acquire_time_data(bus, &times);
+        n = acquire_time_data(bus, /* require_finished = */ true, &times);
         if (n <= 0)
                 return n;
 
index 07843f74bc21b12865f02771772c2c13dd4fb7a1..baee3cedbb531985f5ee9f9fa31374efccbebb34 100644 (file)
@@ -17,7 +17,16 @@ static void subtract_timestamp(usec_t *a, usec_t b) {
         }
 }
 
-int acquire_boot_times(sd_bus *bus, BootTimes **ret) {
+static int log_not_finished(usec_t finish_time) {
+        return log_error_errno(SYNTHETIC_ERRNO(EINPROGRESS),
+                               "Bootup is not yet finished (org.freedesktop.systemd1.Manager.FinishTimestampMonotonic=%"PRIu64").\n"
+                               "Please try again later.\n"
+                               "Hint: Use 'systemctl%s list-jobs' to see active jobs",
+                               finish_time,
+                               arg_runtime_scope == RUNTIME_SCOPE_SYSTEM ? "" : " --user");
+}
+
+int acquire_boot_times(sd_bus *bus, bool require_finished, BootTimes **ret) {
         static const struct bus_properties_map property_map[] = {
                 { "FirmwareTimestampMonotonic",               "t", NULL, offsetof(BootTimes, firmware_time)                 },
                 { "LoaderTimestampMonotonic",                 "t", NULL, offsetof(BootTimes, loader_time)                   },
@@ -44,8 +53,14 @@ int acquire_boot_times(sd_bus *bus, BootTimes **ret) {
         static bool cached = false;
         int r;
 
-        if (cached)
-                goto finish;
+        if (cached) {
+                if (require_finished && times.finish_time <= 0)
+                        return log_not_finished(times.finish_time);
+
+                if (ret)
+                        *ret = &times;
+                return 0;
+        }
 
         assert_cc(sizeof(usec_t) == sizeof(uint64_t));
 
@@ -61,13 +76,8 @@ int acquire_boot_times(sd_bus *bus, BootTimes **ret) {
         if (r < 0)
                 return log_error_errno(r, "Failed to get timestamp properties: %s", bus_error_message(&error, r));
 
-        if (times.finish_time <= 0)
-                return log_error_errno(SYNTHETIC_ERRNO(EINPROGRESS),
-                                       "Bootup is not yet finished (org.freedesktop.systemd1.Manager.FinishTimestampMonotonic=%"PRIu64").\n"
-                                       "Please try again later.\n"
-                                       "Hint: Use 'systemctl%s list-jobs' to see active jobs",
-                                       times.finish_time,
-                                       arg_runtime_scope == RUNTIME_SCOPE_SYSTEM ? "" : " --user");
+        if (require_finished && times.finish_time <= 0)
+                return log_not_finished(times.finish_time);
 
         if (arg_runtime_scope == RUNTIME_SCOPE_SYSTEM && times.security_start_time > 0) {
                 /* security_start_time is set when systemd is not running under container environment. */
@@ -85,7 +95,8 @@ int acquire_boot_times(sd_bus *bus, BootTimes **ret) {
                 times.firmware_time = times.loader_time = times.kernel_time = times.initrd_time =
                         times.userspace_time = times.security_start_time = times.security_finish_time = 0;
 
-                subtract_timestamp(&times.finish_time, times.reverse_offset);
+                if (times.finish_time > 0)
+                        subtract_timestamp(&times.finish_time, times.reverse_offset);
 
                 subtract_timestamp(&times.generators_start_time, times.reverse_offset);
                 subtract_timestamp(&times.generators_finish_time, times.reverse_offset);
@@ -96,8 +107,8 @@ int acquire_boot_times(sd_bus *bus, BootTimes **ret) {
 
         cached = true;
 
-finish:
-        *ret = &times;
+        if (ret)
+                *ret = &times;
         return 0;
 }
 
@@ -132,7 +143,7 @@ int pretty_boot_time(sd_bus *bus, char **ret) {
         BootTimes *t;
         int r;
 
-        r = acquire_boot_times(bus, &t);
+        r = acquire_boot_times(bus, /* require_finished = */ true, &t);
         if (r < 0)
                 return r;
 
@@ -214,7 +225,7 @@ UnitTimes* unit_times_free_array(UnitTimes *t) {
         return mfree(t);
 }
 
-int acquire_time_data(sd_bus *bus, UnitTimes **out) {
+int acquire_time_data(sd_bus *bus, bool require_finished, UnitTimes **out) {
         static const struct bus_properties_map property_map[] = {
                 { "InactiveExitTimestampMonotonic",  "t", NULL, offsetof(UnitTimes, activating)   },
                 { "ActiveEnterTimestampMonotonic",   "t", NULL, offsetof(UnitTimes, activated)    },
@@ -225,12 +236,12 @@ int acquire_time_data(sd_bus *bus, UnitTimes **out) {
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_(unit_times_free_arrayp) UnitTimes *unit_times = NULL;
-        BootTimes *boot_times = NULL;
+        BootTimes *boot_times;
         size_t c = 0;
         UnitInfo u;
         int r;
 
-        r = acquire_boot_times(bus, &boot_times);
+        r = acquire_boot_times(bus, require_finished, &boot_times);
         if (r < 0)
                 return r;
 
index 02ee16a7141bbfe69509eb974c1aa7b87a810fae..79240745cb36c2dbfde091915f48a262b142c0f4 100644 (file)
@@ -47,10 +47,10 @@ typedef struct UnitTimes {
         usec_t time;
 } UnitTimes;
 
-int acquire_boot_times(sd_bus *bus, BootTimes **ret);
+int acquire_boot_times(sd_bus *bus, bool require_finished, BootTimes **ret);
 int pretty_boot_time(sd_bus *bus, char **ret);
 
 UnitTimes* unit_times_free_array(UnitTimes *t);
 DEFINE_TRIVIAL_CLEANUP_FUNC(UnitTimes*, unit_times_free_array);
 
-int acquire_time_data(sd_bus *bus, UnitTimes **out);
+int acquire_time_data(sd_bus *bus, bool require_finished, UnitTimes **out);