Blame SOURCES/0182-bus-util-be-more-verbose-if-dbus-job-fails.patch

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