diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-11-21 20:31:50 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-11-21 20:31:50 +0100 |
commit | a44b10818a531787c359f6446d218a975503f032 (patch) | |
tree | bc297ddf7ec862f68ed9c7f3ad5e80d943417c2c | |
parent | 38051578360c211e88ef4082ce5746adb52a500e (diff) |
busctl: add --timeout= option to specify method call timeout
-rw-r--r-- | man/busctl.xml | 16 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/busctl.c | 19 |
2 files changed, 32 insertions, 3 deletions
diff --git a/man/busctl.xml b/man/busctl.xml index e0af30e6f5..c47a329fea 100644 --- a/man/busctl.xml +++ b/man/busctl.xml @@ -216,6 +216,22 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. </listitem> </varlistentry> + <varlistentry> + <term><option>--timeout=</option><replaceable>SECS</replaceable></term> + + <listitem> + <para>When used with the <command>call</command> command + specifies the maximum time to wait for method call + completion. If no time unit is specified assumes + seconds. The usual other units are understood, too (ms, us, + s, min, h, d, w, month, y). Note that this timeout does not + apply if <option>--expect-reply=no</option> is used as the + tool does not wait for any reply message then. When not + specified or when set to 0 the default of + <literal>25s</literal> is assumed.</para> + </listitem> + </varlistentry> + <xi:include href="user-system-options.xml" xpointer="user" /> <xi:include href="user-system-options.xml" xpointer="system" /> <xi:include href="user-system-options.xml" xpointer="host" /> diff --git a/src/libsystemd/sd-bus/busctl.c b/src/libsystemd/sd-bus/busctl.c index 145b3198c1..2cea21ed59 100644 --- a/src/libsystemd/sd-bus/busctl.c +++ b/src/libsystemd/sd-bus/busctl.c @@ -56,6 +56,7 @@ 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 usec_t arg_timeout = 0; static void pager_open_if_enabled(void) { @@ -1494,7 +1495,7 @@ static int call(sd_bus *bus, char *argv[]) { return 0; } - r = sd_bus_call(bus, m, 0, &error, &reply); + r = sd_bus_call(bus, m, arg_timeout, &error, &reply); if (r < 0) { log_error("%s", bus_error_message(&error, r)); return r; @@ -1627,7 +1628,7 @@ static int set_property(sd_bus *bus, char *argv[]) { return -EINVAL; } - r = sd_bus_call(bus, m, 0, &error, NULL); + r = sd_bus_call(bus, m, arg_timeout, &error, NULL); if (r < 0) { log_error("%s", bus_error_message(&error, r)); return r; @@ -1659,7 +1660,8 @@ static int help(void) { " --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" + " Allow interactive authorization for operation\n" + " --timeout=SECS Maximum time to wait for method call completion\n\n" "Commands:\n" " list List bus names\n" " status SERVICE Show service name status\n" @@ -1699,6 +1701,7 @@ static int parse_argv(int argc, char *argv[]) { ARG_EXPECT_REPLY, ARG_AUTO_START, ARG_ALLOW_INTERACTIVE_AUTHORIZATION, + ARG_TIMEOUT, }; static const struct option options[] = { @@ -1723,6 +1726,7 @@ static int parse_argv(int argc, char *argv[]) { { "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 }, + { "timeout", required_argument, NULL, ARG_TIMEOUT }, {}, }; @@ -1856,6 +1860,15 @@ static int parse_argv(int argc, char *argv[]) { arg_allow_interactive_authorization = !!r; break; + case ARG_TIMEOUT: + r = parse_sec(optarg, &arg_timeout); + if (r < 0) { + log_error("Failed to parse --timeout= parameter."); + return r; + } + + break; + case '?': return -EINVAL; |