chiark / gitweb /
shared: move unit-specific code from bus-util.h to bus-unit-util.h
[elogind.git] / src / shared / bus-util.c
index 5fa39ce8c694a5292ef275260bbda176ce94d6e0..0ab5755068251ed1fb8592e92c22c398434918fa 100644 (file)
@@ -847,7 +847,7 @@ int bus_print_property(const char *name, sd_bus_message *property, bool all) {
                         if (r < 0)
                                 return r;
 
-                        while((r = sd_bus_message_read_basic(property, SD_BUS_TYPE_STRING, &str)) > 0) {
+                        while ((r = sd_bus_message_read_basic(property, SD_BUS_TYPE_STRING, &str)) > 0) {
                                 _cleanup_free_ char *escaped = NULL;
 
                                 if (first)
@@ -1072,7 +1072,7 @@ static int map_basic(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_
         }
 
         case SD_BUS_TYPE_UINT32: {
-                uint64_t u;
+                uint32_t u;
                 uint32_t *p = userdata;
 
                 r = sd_bus_message_read_basic(m, type, &u);
@@ -1423,7 +1423,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
                 return bus_log_create_error(r);
 
         field = strndupa(assignment, eq - assignment);
-        eq ++;
+        eq++;
 
         if (streq(field, "CPUQuota")) {
 
@@ -2041,20 +2041,21 @@ 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* const* extra_args) {
+        _cleanup_free_ char *service_shell_quoted = NULL;
+        const char *systemctl = "systemctl", *journalctl = "journalctl";
 
         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]) {
+                _cleanup_free_ char *t;
 
-        systemctl_extra_args = strstrip(systemctl_extra_args);
+                t = strv_join((char**) extra_args, " ");
+                systemctl = strjoina("systemctl ", t ? : "<args>");
+                journalctl = strjoina("journalctl ", t ? : "<args>");
+        }
 
         if (!isempty(result)) {
                 unsigned i;
@@ -2064,30 +2065,34 @@ 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,
+                                  service_shell_quoted ?: "<service>",
+                                  journalctl);
                         goto finish;
                 }
         }
 
-        log_error("Job for %s failed. See \"%s status %s\" and \"journalctl -xe\" for details.\n",
+        log_error("Job for %s failed.\n"
+                  "See \"%s status %s\" and \"%s -xe\" for details.\n",
                   service,
-                  systemctl_extra_args,
-                  strna(service_shell_quoted));
+                  systemctl,
+                  service_shell_quoted ?: "<service>",
+                  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\" 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,
+                         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);
@@ -2138,7 +2143,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);
@@ -2198,14 +2203,16 @@ int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, Un
                 return bus_log_parse_error(r);
 
         while ((r = sd_bus_message_read(m, "(sss)", &type, &path, &source)) > 0) {
-                if (!quiet) {
-                        if (streq(type, "symlink"))
-                                log_info("Created symlink from %s to %s.", path, source);
-                        else
-                                log_info("Removed symlink %s.", path);
+                /* We expect only "success" changes to be sent over the bus.
+                   Hence, reject anything negative. */
+                UnitFileChangeType ch = unit_file_change_type_from_string(type);
+
+                if (ch < 0) {
+                        log_notice("Manager reported unknown change type \"%s\" for path \"%s\", ignoring.", type, path);
+                        continue;
                 }
 
-                r = unit_file_changes_add(changes, n_changes, streq(type, "symlink") ? UNIT_FILE_SYMLINK : UNIT_FILE_UNLINK, path, source);
+                r = unit_file_changes_add(changes, n_changes, ch, path, source);
                 if (r < 0)
                         return r;
         }
@@ -2216,6 +2223,7 @@ int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, Un
         if (r < 0)
                 return bus_log_parse_error(r);
 
+        unit_file_dump_changes(0, NULL, *changes, *n_changes, false);
         return 0;
 }