chiark / gitweb /
analyze: set white backgound
[elogind.git] / src / analyze / systemd-analyze.c
index 2748b3afc96656cc2304e1d25dfafed345f8d4aa..0cc4de76cd823bbd2cb1408cb36037155f8428a6 100644 (file)
@@ -384,9 +384,9 @@ static int pretty_boot_time(DBusConnection *bus, char **_buf) {
 
         size = strpcpyf(&ptr, size, "%s (userspace) ", format_timespan(ts, sizeof(ts), t->finish_time - t->userspace_time, USEC_PER_MSEC));
         if (t->kernel_time > 0)
-                size = strpcpyf(&ptr, size, "= %s", format_timespan(ts, sizeof(ts), t->firmware_time + t->finish_time, USEC_PER_MSEC));
+                strpcpyf(&ptr, size, "= %s", format_timespan(ts, sizeof(ts), t->firmware_time + t->finish_time, USEC_PER_MSEC));
         else
-                size = strpcpyf(&ptr, size, "= %s", format_timespan(ts, sizeof(ts), t->finish_time - t->userspace_time, USEC_PER_MSEC));
+                strpcpyf(&ptr, size, "= %s", format_timespan(ts, sizeof(ts), t->finish_time - t->userspace_time, USEC_PER_MSEC));
 
         ptr = strdup(buf);
         if (!ptr)
@@ -507,6 +507,7 @@ static int analyze_plot(DBusConnection *bus) {
         /* style sheet */
         svg("<defs>\n  <style type=\"text/css\">\n    <![CDATA[\n"
             "      rect       { stroke-width: 1; stroke-opacity: 0; }\n"
+            "      rect.background   { fill: rgb(255,255,255); }\n"
             "      rect.activating   { fill: rgb(255,0,0); fill-opacity: 0.7; }\n"
             "      rect.active       { fill: rgb(200,150,150); fill-opacity: 0.7; }\n"
             "      rect.deactivating { fill: rgb(150,100,100); fill-opacity: 0.7; }\n"
@@ -528,6 +529,7 @@ static int analyze_plot(DBusConnection *bus) {
             "      text.sec   { font-size: 10px; }\n"
             "    ]]>\n   </style>\n</defs>\n\n");
 
+        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</text>",
             isempty(osname) ? "Linux" : osname,
@@ -768,7 +770,7 @@ static int list_dependencies_one(DBusConnection *bus, const char *name, unsigned
         if (r < 0)
                 return r;
 
-        qsort(deps, strv_length(deps), sizeof (char*), list_dependencies_compare);
+        qsort_safe(deps, strv_length(deps), sizeof (char*), list_dependencies_compare);
 
         r = acquire_boot_times(bus, &boot);
         if (r < 0)
@@ -818,18 +820,18 @@ static int list_dependencies_one(DBusConnection *bus, const char *name, unsigned
                 if (strv_contains(*units, *c)) {
                         r = list_dependencies_print("...", level + 1, (branches << 1) | (to_print ? 1 : 0),
                                                     true, NULL, boot);
+                        if (r < 0)
+                                return r;
                         continue;
                 }
 
                 r = list_dependencies_one(bus, *c, level + 1, units,
                                           (branches << 1) | (to_print ? 1 : 0));
-                if(r < 0)
+                if (r < 0)
                         return r;
 
-
-                if(!to_print)
+                if (!to_print)
                         break;
-
         }
         return 0;
 }
@@ -1184,6 +1186,11 @@ static int dump(DBusConnection *bus, char **args) {
 
         dbus_error_init(&error);
 
+        if (!strv_isempty(args)) {
+                log_error("Too many arguments.");
+                return -E2BIG;
+        }
+
         pager_open_if_enabled();
 
         r = bus_method_call_with_reply(
@@ -1210,6 +1217,54 @@ static int dump(DBusConnection *bus, char **args) {
         return 0;
 }
 
+static int set_log_level(DBusConnection *bus, char **args) {
+        _cleanup_dbus_error_free_ DBusError error;
+        _cleanup_dbus_message_unref_ DBusMessage *m = NULL, *reply = NULL;
+        DBusMessageIter iter, sub;
+        const char* property = "LogLevel";
+        const char* interface = "org.freedesktop.systemd1.Manager";
+        const char* value;
+
+        assert(bus);
+        assert(args);
+
+        if (strv_length(args) != 1) {
+                log_error("This command expects one argument only.");
+                return -E2BIG;
+        }
+
+        value = args[0];
+        dbus_error_init(&error);
+
+        m = dbus_message_new_method_call("org.freedesktop.systemd1",
+                                         "/org/freedesktop/systemd1",
+                                         "org.freedesktop.DBus.Properties",
+                                         "Set");
+        if (!m)
+                return log_oom();
+
+        dbus_message_iter_init_append(m, &iter);
+
+        if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &interface) ||
+            !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &property) ||
+            !dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, "s", &sub))
+                return log_oom();
+
+        if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &value))
+                return log_oom();
+
+        if (!dbus_message_iter_close_container(&iter, &sub))
+                return log_oom();
+
+        reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
+        if (!reply) {
+                log_error("Failed to issue method call: %s", bus_error_message(&error));
+                return -EIO;
+        }
+
+        return 0;
+}
+
 static void analyze_help(void) {
 
         pager_open_if_enabled();
@@ -1236,6 +1291,7 @@ static void analyze_help(void) {
                "  critical-chain      Print a tree of the time critical chain of units\n"
                "  plot                Output SVG graphic showing service initialization\n"
                "  dot                 Output dependency graph in dot(1) format\n"
+               "  set-log-level LEVEL Set logging threshold for systemd\n"
                "  dump                Output state serialization of service manager\n",
                program_invocation_short_name);
 
@@ -1368,6 +1424,8 @@ int main(int argc, char *argv[]) {
                 r = dot(bus, argv+optind+1);
         else if (streq(argv[optind], "dump"))
                 r = dump(bus, argv+optind+1);
+        else if (streq(argv[optind], "set-log-level"))
+                r = set_log_level(bus, argv+optind+1);
         else
                 log_error("Unknown operation '%s'.", argv[optind]);