core/dbus-job, systemctl: shorten some code
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 17 Nov 2016 02:01:11 +0000 (21:01 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 17 Nov 2016 02:01:11 +0000 (21:01 -0500)
src/core/dbus-job.c
src/systemctl/systemctl.c

index 087a08d..effc45d 100644 (file)
@@ -258,40 +258,35 @@ static int bus_job_track_handler(sd_bus_track *t, void *userdata) {
 }
 
 static int bus_job_allocate_bus_track(Job *j) {
-        int r;
 
         assert(j);
 
         if (j->bus_track)
                 return 0;
 
-        r = sd_bus_track_new(j->unit->manager->api_bus, &j->bus_track, bus_job_track_handler, j);
-        if (r < 0)
-                return r;
-
-        return 0;
+        return sd_bus_track_new(j->unit->manager->api_bus, &j->bus_track, bus_job_track_handler, j);
 }
 
 int bus_job_coldplug_bus_track(Job *j) {
         int r = 0;
+        _cleanup_strv_free_ char **deserialized_clients = NULL;
 
         assert(j);
 
-        if (strv_isempty(j->deserialized_clients))
-                goto finish;
+        deserialized_clients = j->deserialized_clients;
+        j->deserialized_clients = NULL;
+
+        if (strv_isempty(deserialized_clients))
+                return 0;
 
         if (!j->manager->api_bus)
-                goto finish;
+                return 0;
 
         r = bus_job_allocate_bus_track(j);
         if (r < 0)
-                goto finish;
-
-        r = bus_track_add_name_many(j->bus_track, j->deserialized_clients);
+                return r;
 
-finish:
-        j->deserialized_clients = strv_free(j->deserialized_clients);
-        return r;
+        return bus_track_add_name_many(j->bus_track, deserialized_clients);
 }
 
 int bus_job_track_sender(Job *j, sd_bus_message *m) {
index 5fbda23..4fd8d7b 100644 (file)
@@ -2197,7 +2197,7 @@ finish:
         return r;
 }
 
-static void output_waiting_jobs(sd_bus *bus, uint32_t id, const char *method, const char *prefix) {
+static int output_waiting_jobs(sd_bus *bus, uint32_t id, const char *method, const char *prefix) {
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
         const char *name, *type, *state, *job_path, *unit_path;
@@ -2215,29 +2215,23 @@ static void output_waiting_jobs(sd_bus *bus, uint32_t id, const char *method, co
                         &error,
                         &reply,
                         "u", id);
-        if (r < 0) {
-                log_debug_errno(r, "Failed to get waiting jobs for job %" PRIu32, id);
-                return;
-        }
+        if (r < 0)
+                return log_debug_errno(r, "Failed to get waiting jobs for job %" PRIu32, id);
 
         r = sd_bus_message_enter_container(reply, 'a', "(usssoo)");
-        if (r < 0) {
-                bus_log_parse_error(r);
-                return;
-        }
+        if (r < 0)
+                return bus_log_parse_error(r);
 
         while ((r = sd_bus_message_read(reply, "(usssoo)", &other_id, &name, &type, &state, &job_path, &unit_path)) > 0)
                 printf("%s %u (%s/%s)\n", prefix, other_id, name, type);
-        if (r < 0) {
-                bus_log_parse_error(r);
-                return;
-        }
+        if (r < 0)
+                return bus_log_parse_error(r);
 
         r = sd_bus_message_exit_container(reply);
-        if (r < 0) {
-                bus_log_parse_error(r);
-                return;
-        }
+        if (r < 0)
+                return bus_log_parse_error(r);
+
+        return 0;
 }
 
 struct job_info {