]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/analyze/analyze.c
Merge pull request #8676 from keszybz/drop-license-boilerplate
[thirdparty/systemd.git] / src / analyze / analyze.c
index 2d65fdbdb8e574470a8ca185ec0554799b8eccc3..f69264d637743017eab2f06408381fa36a8f8082 100644 (file)
@@ -4,19 +4,6 @@
 
   Copyright 2010-2013 Lennart Poettering
   Copyright 2013 Simon Peeters
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
 #include <getopt.h>
@@ -131,13 +118,24 @@ struct host_info {
         char *architecture;
 };
 
-static int acquire_bus(bool need_full_bus, sd_bus **bus) {
+
+static int acquire_systemd_bus(sd_bus **bus) {
+        bool user = arg_scope != UNIT_FILE_SYSTEM;
+
+        return bus_connect_transport_systemd(arg_transport, arg_host, user, bus);
+}
+
+static int acquire_full_bus(bool *use_full_bus, sd_bus **bus) {
         bool user = arg_scope != UNIT_FILE_SYSTEM;
 
-        if (need_full_bus)
-                return bus_connect_transport(arg_transport, arg_host, user, bus);
-        else
-                return bus_connect_transport_systemd(arg_transport, arg_host, user, bus);
+        if (*use_full_bus) {
+                if (bus_connect_transport(arg_transport, arg_host, user, bus) == 0)
+                        return 0;
+
+                *use_full_bus = false;
+        }
+
+        return acquire_systemd_bus(bus);
 }
 
 static int bus_get_uint64_property(sd_bus *bus, const char *path, const char *interface, const char *property, uint64_t *val) {
@@ -292,7 +290,11 @@ static int acquire_boot_times(sd_bus *bus, struct boot_times **bt) {
                 return -EIO;
 
         if (times.finish_time <= 0) {
-                log_error("Bootup is not yet finished. Please try again later.");
+                log_error("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_scope == UNIT_FILE_SYSTEM ? "" : " --user");
                 return -EINPROGRESS;
         }
 
@@ -473,7 +475,9 @@ static int acquire_host_info(sd_bus *bus, struct host_info **hi) {
                                    "org.freedesktop.hostname1",
                                    "/org/freedesktop/hostname1",
                                    hostname_map,
+                                   BUS_MAP_STRDUP,
                                    &error,
+                                   NULL,
                                    host);
         if (r < 0)
                 log_debug_errno(r, "Failed to get host information from systemd-hostnamed: %s", bus_error_message(&error, r));
@@ -482,13 +486,14 @@ static int acquire_host_info(sd_bus *bus, struct host_info **hi) {
                                    "org.freedesktop.systemd1",
                                    "/org/freedesktop/systemd1",
                                    manager_map,
+                                   BUS_MAP_STRDUP,
                                    &error,
+                                   NULL,
                                    host);
         if (r < 0)
                 return log_error_errno(r, "Failed to get host information from systemd: %s", bus_error_message(&error, r));
 
-        *hi = host;
-        host = NULL;
+        *hi = TAKE_PTR(host);
 
         return 0;
 }
@@ -598,11 +603,12 @@ static int analyze_plot(int argc, char *argv[], void *userdata) {
         struct unit_times *times;
         struct boot_times *boot;
         int n, m = 1, y = 0, r;
+        bool use_full_bus = true;
         double width;
         _cleanup_free_ char *pretty_times = NULL;
         struct unit_times *u;
 
-        r = acquire_bus(true, &bus);
+        r = acquire_full_bus(&use_full_bus, &bus);
         if (r < 0)
                 return log_error_errno(r, "Failed to create bus connection: %m");
 
@@ -614,9 +620,11 @@ static int analyze_plot(int argc, char *argv[], void *userdata) {
         if (n < 0)
                 return n;
 
-        n = acquire_host_info(bus, &host);
-        if (n < 0)
-                return n;
+        if (use_full_bus) {
+                n = acquire_host_info(bus, &host);
+                if (n < 0)
+                        return n;
+        }
 
         n = acquire_time_data(bus, &times);
         if (n <= 0)
@@ -714,14 +722,15 @@ static int analyze_plot(int argc, char *argv[], void *userdata) {
 
         svg("<rect class=\"background\" width=\"100%%\" height=\"100%%\" />\n");
         svg("<text x=\"20\" y=\"50\">%s</text>", pretty_times);
-        svg("<text x=\"20\" y=\"30\">%s %s (%s %s %s) %s %s</text>",
-            isempty(host->os_pretty_name) ? "Linux" : host->os_pretty_name,
-            strempty(host->hostname),
-            strempty(host->kernel_name),
-            strempty(host->kernel_release),
-            strempty(host->kernel_version),
-            strempty(host->architecture),
-            strempty(host->virtualization));
+        if (use_full_bus)
+                svg("<text x=\"20\" y=\"30\">%s %s (%s %s %s) %s %s</text>",
+                    isempty(host->os_pretty_name) ? "Linux" : host->os_pretty_name,
+                    strempty(host->hostname),
+                    strempty(host->kernel_name),
+                    strempty(host->kernel_release),
+                    strempty(host->kernel_version),
+                    strempty(host->architecture),
+                    strempty(host->virtualization));
 
         svg("<g transform=\"translate(%.3f,100)\">\n", 20.0 + (SCALE_X * boot->firmware_time));
         svg_graph_box(m, -(double) boot->firmware_time, boot->finish_time);
@@ -1008,7 +1017,7 @@ static int analyze_critical_chain(int argc, char *argv[], void *userdata) {
         Hashmap *h;
         int n, r;
 
-        r = acquire_bus(false, &bus);
+        r = acquire_systemd_bus(&bus);
         if (r < 0)
                 return log_error_errno(r, "Failed to create bus connection: %m");
 
@@ -1027,7 +1036,7 @@ static int analyze_critical_chain(int argc, char *argv[], void *userdata) {
         }
         unit_times_hashmap = h;
 
-        pager_open(arg_no_pager, false);
+        (void) pager_open(arg_no_pager, false);
 
         puts("The time after the unit is active or started is printed after the \"@\" character.\n"
              "The time the unit takes to start is printed after the \"+\" character.\n");
@@ -1050,7 +1059,7 @@ static int analyze_blame(int argc, char *argv[], void *userdata) {
         unsigned i;
         int n, r;
 
-        r = acquire_bus(false, &bus);
+        r = acquire_systemd_bus(&bus);
         if (r < 0)
                 return log_error_errno(r, "Failed to create bus connection: %m");
 
@@ -1060,7 +1069,7 @@ static int analyze_blame(int argc, char *argv[], void *userdata) {
 
         qsort(times, n, sizeof(struct unit_times), compare_unit_time);
 
-        pager_open(arg_no_pager, false);
+        (void) pager_open(arg_no_pager, false);
 
         for (i = 0; i < (unsigned) n; i++) {
                 char ts[FORMAT_TIMESPAN_MAX];
@@ -1078,7 +1087,7 @@ static int analyze_time(int argc, char *argv[], void *userdata) {
         _cleanup_free_ char *buf = NULL;
         int r;
 
-        r = acquire_bus(false, &bus);
+        r = acquire_systemd_bus(&bus);
         if (r < 0)
                 return log_error_errno(r, "Failed to create bus connection: %m");
 
@@ -1212,7 +1221,7 @@ static int dot(int argc, char *argv[], void *userdata) {
         int r;
         UnitInfo u;
 
-        r = acquire_bus(false, &bus);
+        r = acquire_systemd_bus(&bus);
         if (r < 0)
                 return log_error_errno(r, "Failed to create bus connection: %m");
 
@@ -1279,11 +1288,11 @@ static int dump(int argc, char *argv[], void *userdata) {
         const char *text = NULL;
         int r;
 
-        r = acquire_bus(false, &bus);
+        r = acquire_systemd_bus(&bus);
         if (r < 0)
                 return log_error_errno(r, "Failed to create bus connection: %m");
 
-        pager_open(arg_no_pager, false);
+        (void) pager_open(arg_no_pager, false);
 
         r = sd_bus_call_method(
                         bus,
@@ -1295,7 +1304,7 @@ static int dump(int argc, char *argv[], void *userdata) {
                         &reply,
                         NULL);
         if (r < 0)
-                return log_error_errno(r, "Failed issue method call: %s", bus_error_message(&error, r));
+                return log_error_errno(r, "Failed to issue method call: %s", bus_error_message(&error, r));
 
         r = sd_bus_message_read(reply, "s", &text);
         if (r < 0)
@@ -1313,7 +1322,7 @@ static int set_log_level(int argc, char *argv[], void *userdata) {
         assert(argc == 2);
         assert(argv);
 
-        r = acquire_bus(false, &bus);
+        r = acquire_systemd_bus(&bus);
         if (r < 0)
                 return log_error_errno(r, "Failed to create bus connection: %m");
 
@@ -1338,7 +1347,7 @@ static int get_log_level(int argc, char *argv[], void *userdata) {
         _cleanup_free_ char *level = NULL;
         int r;
 
-        r = acquire_bus(false, &bus);
+        r = acquire_systemd_bus(&bus);
         if (r < 0)
                 return log_error_errno(r, "Failed to create bus connection: %m");
 
@@ -1369,7 +1378,7 @@ static int set_log_target(int argc, char *argv[], void *userdata) {
         assert(argc == 2);
         assert(argv);
 
-        r = acquire_bus(false, &bus);
+        r = acquire_systemd_bus(&bus);
         if (r < 0)
                 return log_error_errno(r, "Failed to create bus connection: %m");
 
@@ -1394,7 +1403,7 @@ static int get_log_target(int argc, char *argv[], void *userdata) {
         _cleanup_free_ char *target = NULL;
         int r;
 
-        r = acquire_bus(false, &bus);
+        r = acquire_systemd_bus(&bus);
         if (r < 0)
                 return log_error_errno(r, "Failed to create bus connection: %m");
 
@@ -1445,7 +1454,7 @@ static void dump_syscall_filter(const SyscallFilterSet *set) {
 static int dump_syscall_filters(int argc, char *argv[], void *userdata) {
         bool first = true;
 
-        pager_open(arg_no_pager, false);
+        (void) pager_open(arg_no_pager, false);
 
         if (strv_isempty(strv_skip(argv, 1))) {
                 int i;
@@ -1515,7 +1524,7 @@ static int test_calendar(int argc, char *argv[], void *userdata) {
 
                 r = calendar_spec_to_string(spec, &t);
                 if (r < 0) {
-                        ret = log_error_errno(r, "Failed to fomat calendar specification '%s': %m", *p);
+                        ret = log_error_errno(r, "Failed to format calendar specification '%s': %m", *p);
                         continue;
                 }
 
@@ -1556,7 +1565,7 @@ static int service_watchdogs(int argc, char *argv[], void *userdata) {
         assert(IN_SET(argc, 1, 2));
         assert(argv);
 
-        r = acquire_bus(false, &bus);
+        r = acquire_systemd_bus(&bus);
         if (r < 0)
                 return log_error_errno(r, "Failed to create bus connection: %m");
 
@@ -1607,7 +1616,7 @@ static int do_verify(int argc, char *argv[], void *userdata) {
 
 static int help(int argc, char *argv[], void *userdata) {
 
-        pager_open(arg_no_pager, false);
+        (void) pager_open(arg_no_pager, false);
 
         printf("%s [OPTIONS...] {COMMAND} ...\n\n"
                "Profile systemd, show unit dependencies, check unit files.\n\n"