]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: include -M or -H arguments in the hint 2622/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 15 Feb 2016 16:57:48 +0000 (11:57 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 15 Feb 2016 20:23:45 +0000 (15:23 -0500)
https://github.com/systemd/systemd/issues/2431

Some newlines are added, but the output will still exceed 80 columns in many
cases. The fallback for oom conditions is changed from "n/a" to something
"<service>", and a similar pattern is used for the new code. This way we
have a realistic fallback for oom, which seems nicer than making the whole
function return an error code which would then have to be propagated.

$ systemctl -M fedora-rawhide restart systemd-networkd.service
Job for systemd-networkd.service failed because start of the service was attempted too often.
See "systemctl -M fedora-rawhide status systemd-networkd.service" and "journalctl -M fedora-rawhide -xe" for details.
To force a start use "systemctl -M fedora-rawhide reset-failed systemd-networkd.service"
followed by "systemctl -M fedora-rawhide start systemd-networkd.service" again.

src/shared/bus-util.c
src/shared/bus-util.h
src/systemctl/systemctl.c

index 38557f0b8df0ae26e4ac04a05c4dd3e89932161c..1fcf3f6a7f4afd993ea5608e6572ec9e761384b9 100644 (file)
@@ -2028,20 +2028,23 @@ static const struct {
         { "start-limit", "start of the service was attempted too often" }
 };
 
-static void log_job_error_with_service_result(const char* service, const char *result, const char *extra_args) {
-        _cleanup_free_ char *service_shell_quoted = NULL, *systemctl_extra_args = NULL;
+static void log_job_error_with_service_result(const char* service, const char *result, const char** extra_args) {
+        _cleanup_free_ char *service_shell_quoted = NULL, *_systemctl, *_journalctl;
+        const char *systemctl = "systemctl", *journalctl = "journalct";
 
         assert(service);
 
         service_shell_quoted = shell_maybe_quote(service);
 
-        systemctl_extra_args = strjoin("systemctl ", extra_args, " ", NULL);
-        if (!systemctl_extra_args) {
-                log_oom();
-                return;
-        }
+        if (extra_args && extra_args[1]) {
+                assert(extra_args[0] == NULL);
 
-        systemctl_extra_args = strstrip(systemctl_extra_args);
+                extra_args[0] = "systemctl";
+                systemctl = _systemctl = strv_join((char**) extra_args, " ");
+
+                extra_args[0] = "journalctl";
+                journalctl = _journalctl = strv_join((char**) extra_args, " ");
+        }
 
         if (!isempty(result)) {
                 unsigned i;
@@ -2051,30 +2054,33 @@ static void log_job_error_with_service_result(const char* service, const char *r
                                 break;
 
                 if (i < ELEMENTSOF(explanations)) {
-                        log_error("Job for %s failed because %s. See \"%s status %s\" and \"journalctl -xe\" for details.\n",
+                        log_error("Job for %s failed because %s.\n"
+                                  "See \"%s status %s\" and \"%s -xe\" for details.\n",
                                   service,
                                   explanations[i].explanation,
-                                  systemctl_extra_args,
-                                  strna(service_shell_quoted));
-
+                                  systemctl ?: "systemctl <args>",
+                                  service_shell_quoted ?: "<service>",
+                                  journalctl ?: "journalctl <args>");
                         goto finish;
                 }
         }
 
-        log_error("Job for %s failed. See \"%s status %s\" and \"journalctl -xe\" for details.\n",
+        log_error("Job for %s failed. See \"%s status %s\" and \"%s -xe\" for details.\n",
                   service,
-                  systemctl_extra_args,
-                  strna(service_shell_quoted));
+                  systemctl ?: "systemctl <args>",
+                  service_shell_quoted ?: "<service>",
+                  journalctl ?: "journalctl <args>");
 
 finish:
         /* For some results maybe additional explanation is required */
         if (streq_ptr(result, "start-limit"))
-                log_info("To force a start use \"%1$s reset-failed %2$s\" followed by \"%1$s start %2$s\" again.",
-                         systemctl_extra_args,
-                         strna(service_shell_quoted));
+                log_info("To force a start use \"%1$s reset-failed %2$s\"\n"
+                         "followed by \"%1$s start %2$s\" again.",
+                         systemctl ?: "systemctl <args>",
+                         service_shell_quoted ?: "<service>");
 }
 
-static int check_wait_response(BusWaitForJobs *d, bool quiet, const char *extra_args) {
+static int check_wait_response(BusWaitForJobs *d, bool quiet, const char** extra_args) {
         int r = 0;
 
         assert(d->result);
@@ -2125,7 +2131,7 @@ static int check_wait_response(BusWaitForJobs *d, bool quiet, const char *extra_
         return r;
 }
 
-int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet, const char *extra_args) {
+int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet, const char** extra_args) {
         int r = 0;
 
         assert(d);
index 204da5568269cf1a4c1f00bce978fc8e2c8798ff..26d338beec02f8e2113dcb8a7963b31f1bb4370b 100644 (file)
@@ -180,7 +180,7 @@ typedef struct BusWaitForJobs BusWaitForJobs;
 int bus_wait_for_jobs_new(sd_bus *bus, BusWaitForJobs **ret);
 void bus_wait_for_jobs_free(BusWaitForJobs *d);
 int bus_wait_for_jobs_add(BusWaitForJobs *d, const char *path);
-int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet, const char *extra_args);
+int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet, const char** extra_args);
 int bus_wait_for_jobs_one(BusWaitForJobs *d, const char *path, bool quiet);
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(BusWaitForJobs*, bus_wait_for_jobs_free);
index 908ccabf8ac0387883ff4e0abd5a57c8eb61f5d5..44c13cf4d77bbf742f2f2f54d12145859bf7dbad 100644 (file)
@@ -2778,9 +2778,23 @@ static int start_unit(int argc, char *argv[], void *userdata) {
         }
 
         if (!arg_no_block) {
-                int q;
+                int q, arg_count = 1;
+                const char* extra_args[5] = {NULL};
+
+                /* leave first empty for the actual command name*/
+                if (arg_scope != UNIT_FILE_SYSTEM)
+                        extra_args[arg_count++] = "--user";
+
+                assert(IN_SET(arg_transport, BUS_TRANSPORT_LOCAL, BUS_TRANSPORT_REMOTE, BUS_TRANSPORT_MACHINE));
+                if (arg_transport == BUS_TRANSPORT_REMOTE) {
+                        extra_args[arg_count++] = "-H";
+                        extra_args[arg_count++] = arg_host;
+                } else if (arg_transport == BUS_TRANSPORT_MACHINE) {
+                        extra_args[arg_count++] = "-M";
+                        extra_args[arg_count++] = arg_host;
+                }
 
-                q = bus_wait_for_jobs(w, arg_quiet, arg_scope != UNIT_FILE_SYSTEM ? "--user" : NULL);
+                q = bus_wait_for_jobs(w, arg_quiet, extra_args);
                 if (q < 0)
                         return q;