]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/analyze/analyze.c
Merge pull request #18596 from keszybz/systemctl-quiet-legend
[thirdparty/systemd.git] / src / analyze / analyze.c
index 55d32fee22ad7bce09ae1670f1094f04cf9b5ae5..ae2d9fc752ca17745229b63282d2c7f1e0f20fb6 100644 (file)
@@ -93,7 +93,7 @@ static usec_t arg_base_time = USEC_INFINITY;
 STATIC_DESTRUCTOR_REGISTER(arg_dot_from_patterns, strv_freep);
 STATIC_DESTRUCTOR_REGISTER(arg_dot_to_patterns, strv_freep);
 
-struct boot_times {
+typedef struct BootTimes {
         usec_t firmware_time;
         usec_t loader_time;
         usec_t kernel_time;
@@ -125,9 +125,9 @@ struct boot_times {
          * (so it is stored here for reference).
          */
         usec_t reverse_offset;
-};
+} BootTimes;
 
-struct unit_times {
+typedef struct UnitTimes {
         bool has_data;
         char *name;
         usec_t activating;
@@ -135,9 +135,9 @@ struct unit_times {
         usec_t deactivated;
         usec_t deactivating;
         usec_t time;
-};
+} UnitTimes;
 
-struct host_info {
+typedef struct HostInfo {
         char *hostname;
         char *kernel_name;
         char *kernel_release;
@@ -145,7 +145,7 @@ struct host_info {
         char *os_pretty_name;
         char *virtualization;
         char *architecture;
-};
+} HostInfo;
 
 static int acquire_bus(sd_bus **bus, bool *use_full_bus) {
         bool user = arg_scope != UNIT_FILE_SYSTEM;
@@ -210,19 +210,16 @@ static int bus_get_unit_property_strv(sd_bus *bus, const char *path, const char
         return 0;
 }
 
-static int compare_unit_start(const struct unit_times *a, const struct unit_times *b) {
+static int compare_unit_start(const UnitTimes *a, const UnitTimes *b) {
         return CMP(a->activating, b->activating);
 }
 
-static void unit_times_free(struct unit_times *t) {
-        struct unit_times *p;
-
-        for (p = t; p->has_data; p++)
+static UnitTimes* unit_times_free_array(UnitTimes *t) {
+        for (UnitTimes *p = t; p && p->has_data; p++)
                 free(p->name);
-        free(t);
+        return mfree(t);
 }
-
-DEFINE_TRIVIAL_CLEANUP_FUNC(struct unit_times *, unit_times_free);
+DEFINE_TRIVIAL_CLEANUP_FUNC(UnitTimes*, unit_times_free_array);
 
 static void subtract_timestamp(usec_t *a, usec_t b) {
         assert(a);
@@ -233,30 +230,30 @@ static void subtract_timestamp(usec_t *a, usec_t b) {
         }
 }
 
-static int acquire_boot_times(sd_bus *bus, struct boot_times **bt) {
+static int acquire_boot_times(sd_bus *bus, BootTimes **bt) {
         static const struct bus_properties_map property_map[] = {
-                { "FirmwareTimestampMonotonic",               "t", NULL, offsetof(struct boot_times, firmware_time)                 },
-                { "LoaderTimestampMonotonic",                 "t", NULL, offsetof(struct boot_times, loader_time)                   },
-                { "KernelTimestamp",                          "t", NULL, offsetof(struct boot_times, kernel_time)                   },
-                { "InitRDTimestampMonotonic",                 "t", NULL, offsetof(struct boot_times, initrd_time)                   },
-                { "UserspaceTimestampMonotonic",              "t", NULL, offsetof(struct boot_times, userspace_time)                },
-                { "FinishTimestampMonotonic",                 "t", NULL, offsetof(struct boot_times, finish_time)                   },
-                { "SecurityStartTimestampMonotonic",          "t", NULL, offsetof(struct boot_times, security_start_time)           },
-                { "SecurityFinishTimestampMonotonic",         "t", NULL, offsetof(struct boot_times, security_finish_time)          },
-                { "GeneratorsStartTimestampMonotonic",        "t", NULL, offsetof(struct boot_times, generators_start_time)         },
-                { "GeneratorsFinishTimestampMonotonic",       "t", NULL, offsetof(struct boot_times, generators_finish_time)        },
-                { "UnitsLoadStartTimestampMonotonic",         "t", NULL, offsetof(struct boot_times, unitsload_start_time)          },
-                { "UnitsLoadFinishTimestampMonotonic",        "t", NULL, offsetof(struct boot_times, unitsload_finish_time)         },
-                { "InitRDSecurityStartTimestampMonotonic",    "t", NULL, offsetof(struct boot_times, initrd_security_start_time)    },
-                { "InitRDSecurityFinishTimestampMonotonic",   "t", NULL, offsetof(struct boot_times, initrd_security_finish_time)   },
-                { "InitRDGeneratorsStartTimestampMonotonic",  "t", NULL, offsetof(struct boot_times, initrd_generators_start_time)  },
-                { "InitRDGeneratorsFinishTimestampMonotonic", "t", NULL, offsetof(struct boot_times, initrd_generators_finish_time) },
-                { "InitRDUnitsLoadStartTimestampMonotonic",   "t", NULL, offsetof(struct boot_times, initrd_unitsload_start_time)   },
-                { "InitRDUnitsLoadFinishTimestampMonotonic",  "t", NULL, offsetof(struct boot_times, initrd_unitsload_finish_time)  },
+                { "FirmwareTimestampMonotonic",               "t", NULL, offsetof(BootTimes, firmware_time)                 },
+                { "LoaderTimestampMonotonic",                 "t", NULL, offsetof(BootTimes, loader_time)                   },
+                { "KernelTimestamp",                          "t", NULL, offsetof(BootTimes, kernel_time)                   },
+                { "InitRDTimestampMonotonic",                 "t", NULL, offsetof(BootTimes, initrd_time)                   },
+                { "UserspaceTimestampMonotonic",              "t", NULL, offsetof(BootTimes, userspace_time)                },
+                { "FinishTimestampMonotonic",                 "t", NULL, offsetof(BootTimes, finish_time)                   },
+                { "SecurityStartTimestampMonotonic",          "t", NULL, offsetof(BootTimes, security_start_time)           },
+                { "SecurityFinishTimestampMonotonic",         "t", NULL, offsetof(BootTimes, security_finish_time)          },
+                { "GeneratorsStartTimestampMonotonic",        "t", NULL, offsetof(BootTimes, generators_start_time)         },
+                { "GeneratorsFinishTimestampMonotonic",       "t", NULL, offsetof(BootTimes, generators_finish_time)        },
+                { "UnitsLoadStartTimestampMonotonic",         "t", NULL, offsetof(BootTimes, unitsload_start_time)          },
+                { "UnitsLoadFinishTimestampMonotonic",        "t", NULL, offsetof(BootTimes, unitsload_finish_time)         },
+                { "InitRDSecurityStartTimestampMonotonic",    "t", NULL, offsetof(BootTimes, initrd_security_start_time)    },
+                { "InitRDSecurityFinishTimestampMonotonic",   "t", NULL, offsetof(BootTimes, initrd_security_finish_time)   },
+                { "InitRDGeneratorsStartTimestampMonotonic",  "t", NULL, offsetof(BootTimes, initrd_generators_start_time)  },
+                { "InitRDGeneratorsFinishTimestampMonotonic", "t", NULL, offsetof(BootTimes, initrd_generators_finish_time) },
+                { "InitRDUnitsLoadStartTimestampMonotonic",   "t", NULL, offsetof(BootTimes, initrd_unitsload_start_time)   },
+                { "InitRDUnitsLoadFinishTimestampMonotonic",  "t", NULL, offsetof(BootTimes, initrd_unitsload_finish_time)  },
                 {},
         };
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
-        static struct boot_times times;
+        static BootTimes times;
         static bool cached = false;
         int r;
 
@@ -294,7 +291,7 @@ static int acquire_boot_times(sd_bus *bus, struct boot_times **bt) {
         } else {
                 /*
                  * User-instance-specific or container-system-specific timestamps processing
-                 * (see comment to reverse_offset in struct boot_times).
+                 * (see comment to reverse_offset in BootTimes).
                  */
                 times.reverse_offset = times.userspace_time;
 
@@ -317,9 +314,9 @@ finish:
         return 0;
 }
 
-static void free_host_info(struct host_info *hi) {
+static HostInfo* free_host_info(HostInfo *hi) {
         if (!hi)
-                return;
+                return NULL;
 
         free(hi->hostname);
         free(hi->kernel_name);
@@ -328,23 +325,23 @@ static void free_host_info(struct host_info *hi) {
         free(hi->os_pretty_name);
         free(hi->virtualization);
         free(hi->architecture);
-        free(hi);
+        return mfree(hi);
 }
 
-DEFINE_TRIVIAL_CLEANUP_FUNC(struct host_info *, free_host_info);
+DEFINE_TRIVIAL_CLEANUP_FUNC(HostInfo *, free_host_info);
 
-static int acquire_time_data(sd_bus *bus, struct unit_times **out) {
+static int acquire_time_data(sd_bus *bus, UnitTimes **out) {
         static const struct bus_properties_map property_map[] = {
-                { "InactiveExitTimestampMonotonic",  "t", NULL, offsetof(struct unit_times, activating)   },
-                { "ActiveEnterTimestampMonotonic",   "t", NULL, offsetof(struct unit_times, activated)    },
-                { "ActiveExitTimestampMonotonic",    "t", NULL, offsetof(struct unit_times, deactivating) },
-                { "InactiveEnterTimestampMonotonic", "t", NULL, offsetof(struct unit_times, deactivated)  },
+                { "InactiveExitTimestampMonotonic",  "t", NULL, offsetof(UnitTimes, activating)   },
+                { "ActiveEnterTimestampMonotonic",   "t", NULL, offsetof(UnitTimes, activated)    },
+                { "ActiveExitTimestampMonotonic",    "t", NULL, offsetof(UnitTimes, deactivating) },
+                { "InactiveEnterTimestampMonotonic", "t", NULL, offsetof(UnitTimes, deactivated)  },
                 {},
         };
         _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_freep) struct unit_times *unit_times = NULL;
-        struct boot_times *boot_times = NULL;
+        _cleanup_(unit_times_free_arrayp) UnitTimes *unit_times = NULL;
+        BootTimes *boot_times = NULL;
         size_t allocated = 0, c = 0;
         UnitInfo u;
         int r;
@@ -362,7 +359,7 @@ static int acquire_time_data(sd_bus *bus, struct unit_times **out) {
                 return bus_log_parse_error(r);
 
         while ((r = bus_parse_unit_info(reply, &u)) > 0) {
-                struct unit_times *t;
+                UnitTimes *t;
 
                 if (!GREEDY_REALLOC(unit_times, allocated, c + 2))
                         return log_oom();
@@ -415,28 +412,28 @@ static int acquire_time_data(sd_bus *bus, struct unit_times **out) {
         return c;
 }
 
-static int acquire_host_info(sd_bus *bus, struct host_info **hi) {
+static int acquire_host_info(sd_bus *bus, HostInfo **hi) {
         static const struct bus_properties_map hostname_map[] = {
-                { "Hostname",                  "s", NULL, offsetof(struct host_info, hostname)       },
-                { "KernelName",                "s", NULL, offsetof(struct host_info, kernel_name)    },
-                { "KernelRelease",             "s", NULL, offsetof(struct host_info, kernel_release) },
-                { "KernelVersion",             "s", NULL, offsetof(struct host_info, kernel_version) },
-                { "OperatingSystemPrettyName", "s", NULL, offsetof(struct host_info, os_pretty_name) },
+                { "Hostname",                  "s", NULL, offsetof(HostInfo, hostname)       },
+                { "KernelName",                "s", NULL, offsetof(HostInfo, kernel_name)    },
+                { "KernelRelease",             "s", NULL, offsetof(HostInfo, kernel_release) },
+                { "KernelVersion",             "s", NULL, offsetof(HostInfo, kernel_version) },
+                { "OperatingSystemPrettyName", "s", NULL, offsetof(HostInfo, os_pretty_name) },
                 {}
         };
 
         static const struct bus_properties_map manager_map[] = {
-                { "Virtualization", "s", NULL, offsetof(struct host_info, virtualization) },
-                { "Architecture",   "s", NULL, offsetof(struct host_info, architecture)   },
+                { "Virtualization", "s", NULL, offsetof(HostInfo, virtualization) },
+                { "Architecture",   "s", NULL, offsetof(HostInfo, architecture)   },
                 {}
         };
 
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *system_bus = NULL;
-        _cleanup_(free_host_infop) struct host_info *host;
+        _cleanup_(free_host_infop) HostInfo *host = NULL;
         int r;
 
-        host = new0(struct host_info, 1);
+        host = new0(HostInfo, 1);
         if (!host)
                 return log_oom();
 
@@ -483,7 +480,7 @@ manager:
 
 static int pretty_boot_time(sd_bus *bus, char **_buf) {
         char ts[FORMAT_TIMESPAN_MAX];
-        struct boot_times *t;
+        BootTimes *t;
         static char buf[4096];
         size_t size;
         char *ptr;
@@ -560,14 +557,12 @@ static int pretty_boot_time(sd_bus *bus, char **_buf) {
 }
 
 static void svg_graph_box(double height, double begin, double end) {
-        long long i;
-
         /* outside box, fill */
         svg("<rect class=\"box\" x=\"0\" y=\"0\" width=\"%.03f\" height=\"%.03f\" />\n",
             SCALE_X * (end - begin),
             SCALE_Y * height);
 
-        for (i = ((long long) (begin / 100000)) * 100000; i <= end; i += 100000) {
+        for (long long i = ((long long) (begin / 100000)) * 100000; i <= end; i += 100000) {
                 /* lines for each second */
                 if (i % 5000000 == 0)
                         svg("  <line class=\"sec5\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n"
@@ -595,7 +590,7 @@ static void svg_graph_box(double height, double begin, double end) {
         }
 }
 
-static int plot_unit_times(struct unit_times *u, double width, int y) {
+static int plot_unit_times(UnitTimes *u, double width, int y) {
         char ts[FORMAT_TIMESPAN_MAX];
         bool b;
 
@@ -618,13 +613,13 @@ static int plot_unit_times(struct unit_times *u, double width, int y) {
 }
 
 static int analyze_plot(int argc, char *argv[], void *userdata) {
-        _cleanup_(free_host_infop) struct host_info *host = NULL;
+        _cleanup_(free_host_infop) HostInfo *host = NULL;
         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
-        _cleanup_(unit_times_freep) struct unit_times *times = NULL;
+        _cleanup_(unit_times_free_arrayp) UnitTimes *times = NULL;
         _cleanup_free_ char *pretty_times = NULL;
         bool use_full_bus = arg_scope == UNIT_FILE_SYSTEM;
-        struct boot_times *boot;
-        struct unit_times *u;
+        BootTimes *boot;
+        UnitTimes *u;
         int n, m = 1, y = 0, r;
         double width;
 
@@ -838,13 +833,12 @@ static int list_dependencies_print(
                 unsigned level,
                 unsigned branches,
                 bool last,
-                struct unit_times *times,
-                struct boot_times *boot) {
+                UnitTimes *times,
+                BootTimes *boot) {
 
-        unsigned i;
         char ts[FORMAT_TIMESPAN_MAX], ts2[FORMAT_TIMESPAN_MAX];
 
-        for (i = level; i != 0; i--)
+        for (unsigned i = level; i != 0; i--)
                 printf("%s", special_glyph(branches & (1 << (i-1)) ? SPECIAL_GLYPH_TREE_VERTICAL : SPECIAL_GLYPH_TREE_SPACE));
 
         printf("%s", special_glyph(last ? SPECIAL_GLYPH_TREE_RIGHT : SPECIAL_GLYPH_TREE_BRANCH));
@@ -883,7 +877,7 @@ static Hashmap *unit_times_hashmap;
 
 static int list_dependencies_compare(char *const *a, char *const *b) {
         usec_t usa = 0, usb = 0;
-        struct unit_times *times;
+        UnitTimes *times;
 
         times = hashmap_get(unit_times_hashmap, *a);
         if (times)
@@ -895,7 +889,7 @@ static int list_dependencies_compare(char *const *a, char *const *b) {
         return CMP(usb, usa);
 }
 
-static bool times_in_range(const struct unit_times *times, const struct boot_times *boot) {
+static bool times_in_range(const UnitTimes *times, const BootTimes *boot) {
         return times && times->activated > 0 && times->activated <= boot->finish_time;
 }
 
@@ -905,8 +899,8 @@ static int list_dependencies_one(sd_bus *bus, const char *name, unsigned level,
         int r;
         usec_t service_longest = 0;
         int to_print = 0;
-        struct unit_times *times;
-        struct boot_times *boot;
+        UnitTimes *times;
+        BootTimes *boot;
 
         if (strv_extend(units, name))
                 return log_oom();
@@ -971,13 +965,13 @@ static int list_dependencies_one(sd_bus *bus, const char *name, unsigned level,
 static int list_dependencies(sd_bus *bus, const char *name) {
         _cleanup_strv_free_ char **units = NULL;
         char ts[FORMAT_TIMESPAN_MAX];
-        struct unit_times *times;
+        UnitTimes *times;
         int r;
         const char *id;
         _cleanup_free_ char *path = NULL;
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
-        struct boot_times *boot;
+        BootTimes *boot;
 
         assert(bus);
 
@@ -1022,7 +1016,7 @@ static int list_dependencies(sd_bus *bus, const char *name) {
 
 static int analyze_critical_chain(int argc, char *argv[], void *userdata) {
         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
-        _cleanup_(unit_times_freep) struct unit_times *times = NULL;
+        _cleanup_(unit_times_free_arrayp) UnitTimes *times = NULL;
         Hashmap *h;
         int n, r;
 
@@ -1038,7 +1032,7 @@ static int analyze_critical_chain(int argc, char *argv[], void *userdata) {
         if (!h)
                 return log_oom();
 
-        for (struct unit_times *u = times; u->has_data; u++) {
+        for (UnitTimes *u = times; u->has_data; u++) {
                 r = hashmap_put(h, u->name, u);
                 if (r < 0)
                         return log_error_errno(r, "Failed to add entry to hashmap: %m");
@@ -1063,7 +1057,7 @@ static int analyze_critical_chain(int argc, char *argv[], void *userdata) {
 
 static int analyze_blame(int argc, char *argv[], void *userdata) {
         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
-        _cleanup_(unit_times_freep) struct unit_times *times = NULL;
+        _cleanup_(unit_times_free_arrayp) UnitTimes *times = NULL;
         _cleanup_(table_unrefp) Table *table = NULL;
         TableCell *cell;
         int n, r;
@@ -1104,7 +1098,7 @@ static int analyze_blame(int argc, char *argv[], void *userdata) {
         if (r < 0)
                 return r;
 
-        for (struct unit_times *u = times; u->has_data; u++) {
+        for (UnitTimes *u = times; u->has_data; u++) {
                 if (u->time <= 0)
                         continue;
 
@@ -1278,7 +1272,7 @@ static int dot(int argc, char *argv[], void *userdata) {
         if (r < 0)
                 return r;
 
-        r = bus_call_method(bus, bus_systemd_mgr, "ListUnits", &error, &reply, "");
+        r = bus_call_method(bus, bus_systemd_mgr, "ListUnits", &error, &reply, NULL);
         if (r < 0)
                 log_error_errno(r, "Failed to list units: %s", bus_error_message(&error, r));
 
@@ -1717,7 +1711,7 @@ static int dump_syscall_filters(int argc, char *argv[], void *userdata) {
         if (strv_isempty(strv_skip(argv, 1))) {
                 _cleanup_set_free_ Set *kernel = NULL, *known = NULL;
                 const char *sys;
-                int i, k;
+                int k;
 
                 NULSTR_FOREACH(sys, syscall_filter_sets[SYSCALL_FILTER_SET_KNOWN].value)
                         if (set_put_strdup(&known, sys) < 0)
@@ -1725,7 +1719,7 @@ static int dump_syscall_filters(int argc, char *argv[], void *userdata) {
 
                 k = load_kernel_syscalls(&kernel);
 
-                for (i = 0; i < _SYSCALL_FILTER_SET_MAX; i++) {
+                for (int i = 0; i < _SYSCALL_FILTER_SET_MAX; i++) {
                         const SyscallFilterSet *set = syscall_filter_sets + i;
                         if (!first)
                                 puts("");