busctl: handle --limit-messages option under the wait verb
Main focus was to not introduce breaking change or duplicated argument. The `--limit-messages=` option that is used under the `monitor` verb is reused here. However, both `wait` and `monitor` have contradicting default behaviors, so it's not the cleanest thing to do. There was some post-commit discussion about the API in #33961, but the final name adopted in #34928 wasn't that flexible either to fit nicely here in the `wait` verbe. Additionally, there wasn't consideration in #34555 for having uniform behavrious, so we ended with `wait` verb and `--limit-messages=` option, rather than `receive` verb with default of continuously receving signals withtout exit so `--limit-messages=` make more sence and be expectable.
This commit is contained in:
+28
-3
@@ -72,6 +72,7 @@ static bool arg_watch_bind = false;
|
||||
static usec_t arg_timeout = 0;
|
||||
static const char *arg_destination = NULL;
|
||||
static uint64_t arg_limit_messages = UINT64_MAX;
|
||||
static uint64_t arg_limit_signals = 1;
|
||||
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_matches, strv_freep);
|
||||
|
||||
@@ -1931,8 +1932,24 @@ static int get_property(int argc, char **argv, void *userdata) {
|
||||
}
|
||||
|
||||
static int on_bus_signal(sd_bus_message *msg, void *userdata, sd_bus_error *ret_error) {
|
||||
return sd_event_exit(sd_bus_get_event(sd_bus_message_get_bus(ASSERT_PTR(msg))),
|
||||
bus_message_dump(msg, /* flags= */ 0));
|
||||
int r;
|
||||
|
||||
r = bus_message_dump(msg, /* flags= */ 0);
|
||||
if (r < 0)
|
||||
return sd_event_exit(sd_bus_get_event(sd_bus_message_get_bus(ASSERT_PTR(msg))), r);
|
||||
|
||||
if (arg_limit_signals != UINT64_MAX) {
|
||||
arg_limit_signals--;
|
||||
|
||||
if (arg_limit_signals == 0) {
|
||||
if (!arg_quiet && !sd_json_format_enabled(arg_json_format_flags))
|
||||
log_info("Received requested maximum number of signals, exiting.");
|
||||
|
||||
return sd_event_exit(sd_bus_get_event(sd_bus_message_get_bus(ASSERT_PTR(msg))), 0);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int wait_signal(int argc, char **argv, void *userdata) {
|
||||
@@ -2353,7 +2370,14 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
|
||||
case 'N':
|
||||
if (isempty(optarg)) {
|
||||
arg_limit_messages = UINT64_MAX; /* Reset to default */
|
||||
/* Reset to default */
|
||||
arg_limit_messages = UINT64_MAX;
|
||||
arg_limit_signals = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (streq(optarg, "infinity")) {
|
||||
arg_limit_signals = arg_limit_messages = UINT64_MAX;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2363,6 +2387,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
if (arg_limit_messages == 0)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--limit-messages= parameter cannot be 0");
|
||||
|
||||
arg_limit_signals = arg_limit_messages;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
|
||||
Reference in New Issue
Block a user