X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Frun%2Frun.c;h=f4c70050894c9fd4cbeff60a554b9bcca6eabfe2;hb=94676f3e9352cbf1f72e0a512ee0d2ed83ff676d;hp=fc7a3fc521ecfb85f1d9e98b3f340378874e3bb0;hpb=d21ed1ead18d16d35c30299a69d3366847f8a039;p=elogind.git diff --git a/src/run/run.c b/src/run/run.c index fc7a3fc52..f4c700508 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -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; @@ -46,8 +47,8 @@ static int help(void) { " -h --help Show this help\n" " --version Show package version\n" " --user Run as user unit\n" - " -H --host=[USER@]HOST Operate on remote host\n" - " -M --machine=CONTAINER Operate on local container\n" + " -H --host=[USER@]HOST Operate on remote host\n" + " -M --machine=CONTAINER Operate on local container\n" " --scope Run this as scope rather than service\n" " --unit=UNIT Run under the specified unit name\n" " --description=TEXT Description for unit\n" @@ -64,6 +65,7 @@ static int parse_argv(int argc, char *argv[]) { enum { ARG_VERSION = 0x100, ARG_USER, + ARG_SYSTEM, ARG_SCOPE, ARG_UNIT, ARG_DESCRIPTION, @@ -75,6 +77,7 @@ static int parse_argv(int argc, char *argv[]) { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, ARG_VERSION }, { "user", no_argument, NULL, ARG_USER }, + { "system", no_argument, NULL, ARG_SYSTEM }, { "scope", no_argument, NULL, ARG_SCOPE }, { "unit", required_argument, NULL, ARG_UNIT }, { "description", required_argument, NULL, ARG_DESCRIPTION }, @@ -83,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; @@ -96,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); @@ -108,6 +110,10 @@ static int parse_argv(int argc, char *argv[]) { arg_user = true; break; + case ARG_SYSTEM: + arg_user = false; + break; + case ARG_SCOPE: arg_scope = true; break; @@ -146,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"); } } @@ -358,12 +363,12 @@ int main(int argc, char* argv[]) { r = parse_argv(argc, argv); if (r <= 0) - goto fail; + goto finish; r = find_binary(argv[optind], &command); if (r < 0) { log_error("Failed to find executable %s: %s", argv[optind], strerror(-r)); - goto fail; + goto finish; } argv[optind] = command; @@ -371,7 +376,7 @@ int main(int argc, char* argv[]) { description = strv_join(argv + optind, " "); if (!description) { r = log_oom(); - goto fail; + goto finish; } arg_description = description; @@ -380,7 +385,7 @@ int main(int argc, char* argv[]) { r = bus_open_transport(arg_transport, arg_host, arg_user, &bus); if (r < 0) { log_error("Failed to create bus connection: %s", strerror(-r)); - goto fail; + goto finish; } if (arg_scope) @@ -390,9 +395,9 @@ int main(int argc, char* argv[]) { if (r < 0) { log_error("Failed start transient unit: %s", error.message ? error.message : strerror(-r)); sd_bus_error_free(&error); - goto fail; + goto finish; } -fail: +finish: return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }