]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: fix style to avoid modification of array passed by caller 2630/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 16 Feb 2016 00:06:53 +0000 (19:06 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 16 Feb 2016 00:06:53 +0000 (19:06 -0500)
Followup for 4524439edb7d.

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

index 1fcf3f6a7f4afd993ea5608e6572ec9e761384b9..c87eaf63d843eeb4b1bacf023db131798dd8f58a 100644 (file)
@@ -2028,8 +2028,8 @@ 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, *_journalctl;
+static void log_job_error_with_service_result(const char* service, const char *result, const char* const* extra_args) {
+        _cleanup_free_ char *service_shell_quoted = NULL;
         const char *systemctl = "systemctl", *journalctl = "journalct";
 
         assert(service);
@@ -2037,13 +2037,11 @@ static void log_job_error_with_service_result(const char* service, const char *r
         service_shell_quoted = shell_maybe_quote(service);
 
         if (extra_args && extra_args[1]) {
-                assert(extra_args[0] == NULL);
+                _cleanup_free_ char *t;
 
-                extra_args[0] = "systemctl";
-                systemctl = _systemctl = strv_join((char**) extra_args, " ");
-
-                extra_args[0] = "journalctl";
-                journalctl = _journalctl = strv_join((char**) extra_args, " ");
+                t = strv_join((char**) extra_args, " ");
+                systemctl = strjoina("systemctl ", t ?: "<args>", NULL);
+                journalctl = strjoina("journalctl ", t ?: "<args>", NULL);
         }
 
         if (!isempty(result)) {
@@ -2058,29 +2056,30 @@ static void log_job_error_with_service_result(const char* service, const char *r
                                   "See \"%s status %s\" and \"%s -xe\" for details.\n",
                                   service,
                                   explanations[i].explanation,
-                                  systemctl ?: "systemctl <args>",
+                                  systemctl,
                                   service_shell_quoted ?: "<service>",
-                                  journalctl ?: "journalctl <args>");
+                                  journalctl);
                         goto finish;
                 }
         }
 
-        log_error("Job for %s failed. See \"%s status %s\" and \"%s -xe\" for details.\n",
+        log_error("Job for %s failed.\n"
+                  "See \"%s status %s\" and \"%s -xe\" for details.\n",
                   service,
-                  systemctl ?: "systemctl <args>",
+                  systemctl,
                   service_shell_quoted ?: "<service>",
-                  journalctl ?: "journalctl <args>");
+                  journalctl);
 
 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\"\n"
                          "followed by \"%1$s start %2$s\" again.",
-                         systemctl ?: "systemctl <args>",
+                         systemctl,
                          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* const* extra_args) {
         int r = 0;
 
         assert(d->result);
@@ -2131,7 +2130,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* const* extra_args) {
         int r = 0;
 
         assert(d);
index 26d338beec02f8e2113dcb8a7963b31f1bb4370b..fcda1b2c6c7638093596cc8dcd85db20aea71a9d 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* const* 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 44c13cf4d77bbf742f2f2f54d12145859bf7dbad..c75d12c13630db7714f8e85bbe82ec62be9485d8 100644 (file)
@@ -2778,10 +2778,9 @@ static int start_unit(int argc, char *argv[], void *userdata) {
         }
 
         if (!arg_no_block) {
-                int q, arg_count = 1;
-                const char* extra_args[5] = {NULL};
+                int q, arg_count = 0;
+                const char* extra_args[4] = {};
 
-                /* leave first empty for the actual command name*/
                 if (arg_scope != UNIT_FILE_SYSTEM)
                         extra_args[arg_count++] = "--user";