From 38051578360c211e88ef4082ce5746adb52a500e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 21 Nov 2014 20:13:26 +0100 Subject: [PATCH] busctl: add options to control message header flags when invoking methods --- man/busctl.xml | 50 ++++++++++++++++++++++++++++-- src/libsystemd/sd-bus/busctl.c | 69 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 115 insertions(+), 4 deletions(-) diff --git a/man/busctl.xml b/man/busctl.xml index e9b758a..e0af30e 100644 --- a/man/busctl.xml +++ b/man/busctl.xml @@ -156,12 +156,14 @@ along with systemd; If not, see . - When used with the call command suppresses - display of the response message. + When used with the call command + suppresses display of the response message payload. Note that even + if this option is specified errors returned will still be + printed and the tool will indicate success or failure with + the process exit code. - @@ -172,6 +174,48 @@ along with systemd; If not, see . + + BOOL + + + When used with the call command + specifies whether busctl shall wait for + completion of the method call, output the returned method + response data, and return success or failure via the process + exit code. If this is set to no the + method call will be issued but no response is expected, the + tool terminates immediately, and thus no response can be + shown, and no success or failure is returned via the exit + code. To only suppress output of the reply message payload + use above. Defaults to + yes. + + + + + BOOL + + + When used with the call command specifies + whether the method call should implicitly activate the + called service should it not be running yet but is + configured to be auto-started. Defaults to + yes. + + + + + BOOL + + + When used with the call command + specifies whether the services may enforce interactive + authorization while executing the operation, if the security + policy is configured for this. Defaults to + yes. + + + diff --git a/src/libsystemd/sd-bus/busctl.c b/src/libsystemd/sd-bus/busctl.c index 7f5124f..145b319 100644 --- a/src/libsystemd/sd-bus/busctl.c +++ b/src/libsystemd/sd-bus/busctl.c @@ -53,6 +53,9 @@ static size_t arg_snaplen = 4096; static bool arg_list = false; static bool arg_quiet = false; static bool arg_verbose = false; +static bool arg_expect_reply = true; +static bool arg_auto_start = true; +static bool arg_allow_interactive_authorization = true; static void pager_open_if_enabled(void) { @@ -1454,6 +1457,18 @@ static int call(sd_bus *bus, char *argv[]) { if (r < 0) return bus_log_create_error(r); + r = sd_bus_message_set_expect_reply(m, arg_expect_reply); + if (r < 0) + return bus_log_create_error(r); + + r = sd_bus_message_set_auto_start(m, arg_auto_start); + if (r < 0) + return bus_log_create_error(r); + + r = sd_bus_message_set_allow_interactive_authorization(m, arg_allow_interactive_authorization); + if (r < 0) + return bus_log_create_error(r); + if (!isempty(argv[5])) { char **p; @@ -1469,6 +1484,16 @@ static int call(sd_bus *bus, char *argv[]) { } } + if (!arg_expect_reply) { + r = sd_bus_send(bus, m, NULL); + if (r < 0) { + log_error("Failed to send message."); + return r; + } + + return 0; + } + r = sd_bus_call(bus, m, 0, &error, &reply); if (r < 0) { log_error("%s", bus_error_message(&error, r)); @@ -1630,7 +1655,11 @@ static int help(void) { " --match=MATCH Only show matching messages\n" " --list Don't show tree, but simple object path list\n" " --quiet Don't show method call reply\n" - " --verbose Show result values in long format\n\n" + " --verbose Show result values in long format\n" + " --expect-reply=BOOL Expect a method call reply\n" + " --auto-start=BOOL Auto-start destination service\n" + " --allow-interactive-authorization=BOOL\n" + " Allow interactive authorization for operation\n\n" "Commands:\n" " list List bus names\n" " status SERVICE Show service name status\n" @@ -1667,6 +1696,9 @@ static int parse_argv(int argc, char *argv[]) { ARG_SIZE, ARG_LIST, ARG_VERBOSE, + ARG_EXPECT_REPLY, + ARG_AUTO_START, + ARG_ALLOW_INTERACTIVE_AUTHORIZATION, }; static const struct option options[] = { @@ -1688,6 +1720,9 @@ static int parse_argv(int argc, char *argv[]) { { "list", no_argument, NULL, ARG_LIST }, { "quiet", no_argument, NULL, 'q' }, { "verbose", no_argument, NULL, ARG_VERBOSE }, + { "expect-reply", required_argument, NULL, ARG_EXPECT_REPLY }, + { "auto-start", required_argument, NULL, ARG_AUTO_START }, + { "allow-interactive-authorization", required_argument, NULL, ARG_ALLOW_INTERACTIVE_AUTHORIZATION }, {}, }; @@ -1789,6 +1824,38 @@ static int parse_argv(int argc, char *argv[]) { arg_verbose = true; break; + case ARG_EXPECT_REPLY: + r = parse_boolean(optarg); + if (r < 0) { + log_error("Failed to parse --expect-reply= parameter."); + return r; + } + + arg_expect_reply = !!r; + break; + + + case ARG_AUTO_START: + r = parse_boolean(optarg); + if (r < 0) { + log_error("Failed to parse --auto-start= parameter."); + return r; + } + + arg_auto_start = !!r; + break; + + + case ARG_ALLOW_INTERACTIVE_AUTHORIZATION: + r = parse_boolean(optarg); + if (r < 0) { + log_error("Failed to parse --allow-interactive-authorization= parameter."); + return r; + } + + arg_allow_interactive_authorization = !!r; + break; + case '?': return -EINVAL; -- 2.7.4