diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-10-28 13:36:00 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-10-29 16:49:55 +0100 |
commit | 312dad32c1f7a9ec482d438f8001423281bcc725 (patch) | |
tree | e2b0b27ea958ea94836cfdd5833da4398d776d3e /src/busctl | |
parent | NEWS: be less misleading since systemd-run does not support ExtraFileDescript... (diff) | |
download | systemd-312dad32c1f7a9ec482d438f8001423281bcc725.tar.xz systemd-312dad32c1f7a9ec482d438f8001423281bcc725.zip |
busctl: fix timeout calculation for "busctl monitor"
The --timeout= logic was implemented incorrectly, as it would not put a
a limit on the runtime of the operation, but only on the IO sleep.
However, spurious wakeups are possible, hence the timer would be reset
too often.
Fix that, by determining the absolute timestamp early, and checking
against that.
Follow-up for: 989e843e7543b21b91de4368da44692d674722a5
See: #34048
Diffstat (limited to 'src/busctl')
-rw-r--r-- | src/busctl/busctl.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c index 4eeb4a98e5..2abf730102 100644 --- a/src/busctl/busctl.c +++ b/src/busctl/busctl.c @@ -1268,6 +1268,9 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f if (r < 0) return r; + usec_t end = arg_timeout > 0 ? + usec_add(now(CLOCK_MONOTONIC), arg_timeout) : USEC_INFINITY; + /* upgrade connection; it's not used for anything else after this call */ r = sd_bus_message_new_method_call(bus, &message, @@ -1382,8 +1385,8 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f if (r > 0) continue; - r = sd_bus_wait(bus, arg_timeout > 0 ? arg_timeout : UINT64_MAX); - if (r == 0 && arg_timeout > 0) { + r = sd_bus_wait(bus, arg_timeout > 0 ? usec_sub_unsigned(end, now(CLOCK_MONOTONIC)) : UINT64_MAX); + if (r == 0 && arg_timeout > 0 && now(CLOCK_MONOTONIC) >= end) { if (!arg_quiet && !sd_json_format_enabled(arg_json_format_flags)) log_info("Timed out waiting for messages, exiting."); return 0; |