mirror of
https://github.com/systemd/systemd.git
synced 2025-03-08 08:58:27 +03:00
busctl: add support for --timeout to monitor verb
Useful in scripts when you want to exit successfully after a certain time
This commit is contained in:
parent
f548bc4011
commit
989e843e75
@ -392,15 +392,15 @@
|
||||
<term><option>--timeout=<replaceable>SECS</replaceable></option></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>
|
||||
<para>When used with the <command>call</command> command, specifies the maximum time to wait for
|
||||
method call completion. When used with the <command>monitor</command> 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 <option>--expect-reply=no</option> is used,
|
||||
when combined with the <command>call</command> command, 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 for the <command>call</command> command, and it is disabled for the
|
||||
<command>monitor</command> command.</para>
|
||||
|
||||
<xi:include href="version-info.xml" xpointer="v218"/>
|
||||
</listitem>
|
||||
|
@ -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'
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user