chiark / gitweb /
remove unused variable
[elogind.git] / src / run / run.c
index 567fd97e3c2536d47572acb205ad5b9ce645a74b..2e0cd1a6d228792064ff6b2279cd1f904a9f1e09 100644 (file)
@@ -28,6 +28,7 @@
 #include "build.h"
 #include "unit-name.h"
 #include "path-util.h"
+#include "bus-error.h"
 
 static bool arg_scope = false;
 static bool arg_remain_after_exit = false;
@@ -85,7 +86,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "send-sighup",       no_argument,       NULL, ARG_SEND_SIGHUP },
                 { "host",              required_argument, NULL, 'H'             },
                 { "machine",           required_argument, NULL, 'M'             },
-                { NULL,                0,                 NULL, 0               },
+                {},
         };
 
         int c;
@@ -98,8 +99,7 @@ static int parse_argv(int argc, char *argv[]) {
                 switch (c) {
 
                 case 'h':
-                        help();
-                        return 0;
+                        return help();
 
                 case ARG_VERSION:
                         puts(PACKAGE_STRING);
@@ -152,8 +152,7 @@ static int parse_argv(int argc, char *argv[]) {
                         return -EINVAL;
 
                 default:
-                        log_error("Unknown option code %c", c);
-                        return -EINVAL;
+                        assert_not_reached("Unhandled option");
                 }
         }
 
@@ -179,6 +178,10 @@ static int message_start_transient_unit_new(sd_bus *bus, const char *name, sd_bu
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         int r;
 
+        assert(bus);
+        assert(name);
+        assert(ret);
+
         log_info("Running as unit %s.", name);
 
         r = sd_bus_message_new_method_call(
@@ -227,11 +230,18 @@ static int message_start_transient_unit_new(sd_bus *bus, const char *name, sd_bu
 static int message_start_transient_unit_send(sd_bus *bus, sd_bus_message *m, sd_bus_error *error, sd_bus_message **reply) {
         int r;
 
+        assert(bus);
+        assert(m);
+
         r = sd_bus_message_close_container(m);
         if (r < 0)
                 return r;
 
-        return sd_bus_send_with_reply_and_block(bus, m, 0, error, reply);
+        r = sd_bus_message_append(m, "a(sa(sv))", 0);
+        if (r < 0)
+                return r;
+
+        return sd_bus_call(bus, m, 0, error, reply);
 }
 
 static int start_transient_service(
@@ -239,7 +249,7 @@ static int start_transient_service(
                 char **argv,
                 sd_bus_error *error) {
 
-        _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
+        _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         _cleanup_free_ char *name = NULL;
         char **i;
         int r;
@@ -317,7 +327,7 @@ static int start_transient_service(
         if (r < 0)
                 return r;
 
-        return  message_start_transient_unit_send(bus, m, error, &reply);
+        return message_start_transient_unit_send(bus, m, error, NULL);
 }
 
 static int start_transient_scope(
@@ -325,10 +335,12 @@ static int start_transient_scope(
                 char **argv,
                 sd_bus_error *error) {
 
-        _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
+        _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         _cleanup_free_ char *name = NULL;
         int r;
 
+        assert(bus);
+
         if (arg_unit)
                 name = unit_name_mangle_with_suffix(arg_unit, ".scope");
         else
@@ -344,7 +356,7 @@ static int start_transient_scope(
         if (r < 0)
                 return r;
 
-        r = message_start_transient_unit_send(bus, m, error, &reply);
+        r = message_start_transient_unit_send(bus, m, error, NULL);
         if (r < 0)
                 return r;
 
@@ -354,7 +366,7 @@ static int start_transient_scope(
 }
 
 int main(int argc, char* argv[]) {
-        sd_bus_error error = SD_BUS_ERROR_NULL;
+        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_bus_unref_ sd_bus *bus = NULL;
         _cleanup_free_ char *description = NULL, *command = NULL;
         int r;
@@ -393,11 +405,8 @@ int main(int argc, char* argv[]) {
                 r = start_transient_scope(bus, argv + optind, &error);
         else
                 r = start_transient_service(bus, argv + optind, &error);
-        if (r < 0) {
-                log_error("Failed start transient unit: %s", error.message ? error.message : strerror(-r));
-                sd_bus_error_free(&error);
-                goto finish;
-        }
+        if (r < 0)
+                log_error("Failed start transient unit: %s", bus_error_message(&error, r));
 
 finish:
         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;