summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-02-15 11:57:48 -0500
committerSven Eden <yamakuzure@gmx.net>2017-06-16 10:12:57 +0200
commitc73ebfa70c9741872ec1ff3b33bc880ede576b56 (patch)
tree6500bc71916ed22ce022f55f0f983a7d4f126b96 /src/shared
parent64fa8a7f8b2170cf7076e0c0ff4cd778714f385e (diff)
systemctl: include -M or -H arguments in the hint
https://github.com/elogind/elogind/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 elogind-networkd.service Job for elogind-networkd.service failed because start of the service was attempted too often. See "systemctl -M fedora-rawhide status elogind-networkd.service" and "journalctl -M fedora-rawhide -xe" for details. To force a start use "systemctl -M fedora-rawhide reset-failed elogind-networkd.service" followed by "systemctl -M fedora-rawhide start elogind-networkd.service" again.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/bus-util.c46
-rw-r--r--src/shared/bus-util.h2
2 files changed, 27 insertions, 21 deletions
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
index 5fa39ce8c..7ab687737 100644
--- a/src/shared/bus-util.c
+++ b/src/shared/bus-util.c
@@ -2041,20 +2041,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;
@@ -2064,30 +2067,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);
@@ -2138,7 +2144,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);
diff --git a/src/shared/bus-util.h b/src/shared/bus-util.h
index e81d3313a..3cda868f7 100644
--- a/src/shared/bus-util.h
+++ b/src/shared/bus-util.h
@@ -195,7 +195,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);