daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
803fb7
From 8946c35e525c2a14b12ed425f11af152e37d8583 Mon Sep 17 00:00:00 2001
803fb7
From: Michal Sekletar <msekleta@redhat.com>
803fb7
Date: Fri, 10 Apr 2015 15:56:52 +0200
803fb7
Subject: [PATCH] bus-util: be more verbose if dbus job fails
803fb7
803fb7
Users might have hard time figuring out why exactly their systemctl request
803fb7
failed. If dbus job fails try to figure out more details about failure by
803fb7
examining Result property of the service.
803fb7
803fb7
https://bugzilla.redhat.com/show_bug.cgi?id=1016680
803fb7
803fb7
Cherry-picked from: d5cad22109749faffb7563e4b2a3a728486d47b5
803fb7
Resolves: #1016680
803fb7
---
de8967
 src/libsystemd/sd-bus/bus-util.c | 79 +++++++++++++++++++++++++++++---
803fb7
 1 file changed, 72 insertions(+), 7 deletions(-)
803fb7
803fb7
diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c
803fb7
index b0a5a7592..2e6d88962 100644
803fb7
--- a/src/libsystemd/sd-bus/bus-util.c
803fb7
+++ b/src/libsystemd/sd-bus/bus-util.c
803fb7
@@ -30,6 +30,7 @@
803fb7
 #include "path-util.h"
803fb7
 #include "missing.h"
803fb7
 #include "set.h"
803fb7
+#include "unit-name.h"
803fb7
 
803fb7
 #include "sd-bus.h"
803fb7
 #include "bus-error.h"
803fb7
@@ -1690,6 +1691,68 @@ static int bus_process_wait(sd_bus *bus) {
803fb7
         }
803fb7
 }
803fb7
 
803fb7
+static int bus_job_get_service_result(BusWaitForJobs *d, char **result) {
803fb7
+        _cleanup_free_ char *dbus_path = NULL;
803fb7
+
803fb7
+        assert(d);
803fb7
+        assert(d->name);
803fb7
+        assert(result);
803fb7
+
803fb7
+        dbus_path = unit_dbus_path_from_name(d->name);
803fb7
+        if (!dbus_path)
803fb7
+                return -ENOMEM;
803fb7
+
803fb7
+        return sd_bus_get_property_string(d->bus,
803fb7
+                                          "org.freedesktop.systemd1",
803fb7
+                                          dbus_path,
803fb7
+                                          "org.freedesktop.systemd1.Service",
803fb7
+                                          "Result",
803fb7
+                                          NULL,
803fb7
+                                          result);
803fb7
+}
803fb7
+
803fb7
+static const struct {
803fb7
+        const char *result, *explanation;
803fb7
+} explanations [] = {
803fb7
+        { "resources", "configured resource limit was exceeded" },
803fb7
+        { "timeout", "timeout was exceeded" },
803fb7
+        { "exit-code", "control process exited with error code" },
803fb7
+        { "signal", "fatal signal was delivered to the control process" },
803fb7
+        { "core-dump", "fatal signal was delivered to the control process. Core dumped" },
803fb7
+        { "watchdog", "service failed to send watchdog ping" },
803fb7
+        { "start-limit", "start of the service was attempted too often too quickly" }
803fb7
+};
803fb7
+
803fb7
+static void log_job_error_with_service_result(const char* service, const char *result) {
803fb7
+        unsigned i;
803fb7
+        _cleanup_free_ char *service_shell_quoted = NULL;
803fb7
+
803fb7
+        assert(service);
803fb7
+        assert(result);
803fb7
+
803fb7
+        service_shell_quoted = shell_maybe_quote(service);
803fb7
+
803fb7
+        for (i = 0; i < ELEMENTSOF(explanations); ++i)
803fb7
+                if (streq(result, explanations[i].result))
803fb7
+                        break;
803fb7
+
803fb7
+        if (i < ELEMENTSOF(explanations))
803fb7
+                log_error("Job for %s failed because %s. See \"systemctl status %s\" and \"journalctl -xe\" for details.\n",
803fb7
+                          service,
803fb7
+                          explanations[i].explanation,
803fb7
+                          strna(service_shell_quoted));
803fb7
+        else
803fb7
+                log_error("Job for %s failed. See \"systemctl status %s\" and \"journalctl -xe\" for details.\n",
803fb7
+                          service,
803fb7
+                          strna(service_shell_quoted));
803fb7
+
803fb7
+        /* For some results maybe additional explanation is required */
803fb7
+        if (streq_ptr(result, "start-limit"))
803fb7
+                log_info("To force a start please invoke \"systemctl reset-failed %s\" followed by \"systemctl start %s\" again.",
803fb7
+                         strna(service_shell_quoted),
803fb7
+                         strna(service_shell_quoted));
803fb7
+}
803fb7
+
803fb7
 static int check_wait_response(BusWaitForJobs *d, bool quiet) {
803fb7
         int r = 0;
803fb7
 
803fb7
@@ -1709,15 +1772,17 @@ static int check_wait_response(BusWaitForJobs *d, bool quiet) {
803fb7
                 else if (streq(d->result, "unsupported"))
803fb7
                         log_error("Operation on or unit type of %s not supported on this system.", strna(d->name));
803fb7
                 else if (!streq(d->result, "done") && !streq(d->result, "skipped")) {
803fb7
-                        _cleanup_free_ char *quoted = NULL;
803fb7
+                        if (d->name) {
803fb7
+                                int q;
803fb7
+                                _cleanup_free_ char *result = NULL;
803fb7
 
803fb7
-                        if (d->name)
803fb7
-                                quoted = shell_maybe_quote(d->name);
803fb7
+                                q = bus_job_get_service_result(d, &result);
803fb7
+                                if (q < 0)
803fb7
+                                        log_debug_errno(q, "Failed to get Result property of service %s: %m", d->name);
803fb7
 
803fb7
-                        if (quoted)
803fb7
-                                log_error("Job for %s failed. See 'systemctl status %s' and 'journalctl -xe' for details.", d->name, quoted);
803fb7
-                        else
803fb7
-                                log_error("Job failed. See 'journalctl -xe' for details.");
803fb7
+                                log_job_error_with_service_result(d->name, result);
803fb7
+                        } else
803fb7
+                                log_error("Job failed. See \"journalctl -xe\" for details.");
803fb7
                 }
803fb7
         }
803fb7