X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd%2Fsd-bus%2Fbusctl.c;h=b2c7be20ae58fd2b3a6c2d05e7ad3e55967afefe;hb=705a415f684f8e9ee19983e5859de00bbb1477cb;hp=145b3198c1fd3abe120684e8763416e1aaf66d66;hpb=38051578360c211e88ef4082ce5746adb52a500e;p=elogind.git diff --git a/src/libsystemd/sd-bus/busctl.c b/src/libsystemd/sd-bus/busctl.c index 145b3198c..b2c7be20a 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) { @@ -66,6 +67,9 @@ static void pager_open_if_enabled(void) { pager_open(false); } +#define NAME_IS_ACQUIRED INT_TO_PTR(1) +#define NAME_IS_ACTIVATABLE INT_TO_PTR(2) + static int list_bus_names(sd_bus *bus, char **argv) { _cleanup_strv_free_ char **acquired = NULL, **activatable = NULL; _cleanup_free_ char **merged = NULL; @@ -98,7 +102,7 @@ static int list_bus_names(sd_bus *bus, char **argv) { STRV_FOREACH(i, acquired) { max_i = MAX(max_i, strlen(*i)); - r = hashmap_put(names, *i, INT_TO_PTR(1)); + r = hashmap_put(names, *i, NAME_IS_ACQUIRED); if (r < 0) { log_error("Failed to add to hashmap: %s", strerror(-r)); return r; @@ -108,7 +112,7 @@ static int list_bus_names(sd_bus *bus, char **argv) { STRV_FOREACH(i, activatable) { max_i = MAX(max_i, strlen(*i)); - r = hashmap_put(names, *i, INT_TO_PTR(2)); + r = hashmap_put(names, *i, NAME_IS_ACTIVATABLE); if (r < 0 && r != -EEXIST) { log_error("Failed to add to hashmap: %s", strerror(-r)); return r; @@ -136,7 +140,7 @@ static int list_bus_names(sd_bus *bus, char **argv) { _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; sd_id128_t mid; - if (hashmap_get(names, *i) == INT_TO_PTR(2)) { + if (hashmap_get(names, *i) == NAME_IS_ACTIVATABLE) { /* Activatable */ printf("%-*s", (int) max_i, *i); @@ -1494,7 +1498,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 +1631,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 +1663,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 +1704,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 +1729,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 +1863,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;