diff --git a/man/busctl.xml b/man/busctl.xml index 27327ee192..0938582c8b 100644 --- a/man/busctl.xml +++ b/man/busctl.xml @@ -392,15 +392,15 @@ - When used with the call 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 is used, as the - tool does not wait for any reply message then. When not - specified or when set to 0, the default of - 25s is assumed. + When used with the call command, specifies the maximum time to wait for + method call completion. When used with the monitor command, since version v257, + specifies the maximum time to wait for messages before automatically exiting. 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 is used, + when combined with the call command, as the tool does not wait for any reply + message then. When not specified or when set to 0, the default of 25s is + assumed for the call command, and it is disabled for the + monitor command. diff --git a/shell-completion/zsh/_busctl b/shell-completion/zsh/_busctl index d8d7adfb4c..c8c4f96ed1 100644 --- a/shell-completion/zsh/_busctl +++ b/shell-completion/zsh/_busctl @@ -282,6 +282,6 @@ _arguments \ '--expect-reply=[Expect a method call reply]:boolean:(1 0)' \ '--auto-start=[Auto-start destination service]:boolean:(1 0)' \ '--allow-interactive-authorization=[Allow interactive authorization for operation]:boolean:(1 0)' \ - '--timeout=[Maximum time to wait for method call completion]:timeout (seconds)' \ + '--timeout=[Maximum time to wait for method call completion and monitoring]:timeout (seconds)' \ '--augment-creds=[Extend credential data with data read from /proc/$PID]:boolean:(1 0)' \ '*::busctl command:_busctl_commands' diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c index 4a5fac7606..31104f36c5 100644 --- a/src/busctl/busctl.c +++ b/src/busctl/busctl.c @@ -1373,7 +1373,12 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f if (r > 0) continue; - r = sd_bus_wait(bus, UINT64_MAX); + r = sd_bus_wait(bus, arg_timeout > 0 ? arg_timeout : UINT64_MAX); + if (r == 0 && arg_timeout > 0) { + if (!arg_quiet && arg_json_format_flags == SD_JSON_FORMAT_OFF) + log_info("Timed out waiting for messages, exiting."); + return 0; + } if (r < 0) return log_error_errno(r, "Failed to wait for bus: %m"); } diff --git a/test/units/TEST-74-AUX-UTILS.busctl.sh b/test/units/TEST-74-AUX-UTILS.busctl.sh index aaf96d08c1..6e997b46c6 100755 --- a/test/units/TEST-74-AUX-UTILS.busctl.sh +++ b/test/units/TEST-74-AUX-UTILS.busctl.sh @@ -108,3 +108,5 @@ busctl get-property -j \ # Invalid argument (! busctl set-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \ KExecWatchdogUSec t "foo") + +busctl --quiet --timeout 1 --match "interface=org.freedesktop.systemd1.Manager" monitor >/dev/null