]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-varlink: add api for resetting timeout to default
authorLennart Poettering <lennart@poettering.net>
Fri, 5 Sep 2025 12:22:07 +0000 (14:22 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 18 Sep 2025 13:56:11 +0000 (15:56 +0200)
We currently don't expose the literal default time-out as API. Let's at
least provide users with a way to reset the time-out to the default.

man/rules/meson.build
man/sd_varlink_set_relative_timeout.xml [new file with mode: 0644]
src/libsystemd/sd-varlink/sd-varlink.c

index 62841837560d2eacde8927bd8d4bc889b3463e6c..50432f0b8d856b1521cb201e80e72b95531d34ff 100644 (file)
@@ -917,6 +917,7 @@ manpages = [
  ['sd_varlink_push_fd', '3', ['sd_varlink_push_dup_fd'], ''],
  ['sd_varlink_send', '3', ['sd_varlink_sendb', 'sd_varlink_sendbo'], ''],
  ['sd_varlink_set_description', '3', ['sd_varlink_get_description'], ''],
+ ['sd_varlink_set_relative_timeout', '3', [], ''],
  ['sd_watchdog_enabled', '3', [], ''],
  ['shutdown', '8', [], ''],
  ['smbios-type-11', '7', [], ''],
diff --git a/man/sd_varlink_set_relative_timeout.xml b/man/sd_varlink_set_relative_timeout.xml
new file mode 100644 (file)
index 0000000..06c87a6
--- /dev/null
@@ -0,0 +1,88 @@
+<?xml version='1.0'?>
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+  "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
+
+<refentry id="sd_varlink_set_relative_timeout" xmlns:xi="http://www.w3.org/2001/XInclude">
+
+  <refentryinfo>
+    <title>sd_varlink_set_relative_timeout</title>
+    <productname>systemd</productname>
+  </refentryinfo>
+
+  <refmeta>
+    <refentrytitle>sd_varlink_set_relative_timeout</refentrytitle>
+    <manvolnum>3</manvolnum>
+  </refmeta>
+
+  <refnamediv>
+    <refname>sd_varlink_set_relative_timeout</refname>
+
+    <refpurpose>Set method call time-out</refpurpose>
+  </refnamediv>
+
+  <refsynopsisdiv>
+    <funcsynopsis>
+      <funcsynopsisinfo>#include &lt;systemd/sd-varlink.h&gt;</funcsynopsisinfo>
+
+      <funcprototype>
+        <funcdef>int <function>sd_varlink_set_relative_timeout</function></funcdef>
+        <paramdef>sd_varlink *<parameter>link</parameter></paramdef>
+        <paramdef>uint64_t <parameter>usec</parameter></paramdef>
+      </funcprototype>
+
+    </funcsynopsis>
+  </refsynopsisdiv>
+
+  <refsect1>
+    <title>Description</title>
+
+    <para><function>sd_varlink_set_relative_timeout()</function> sets the relative timeout in µs to enforce
+    on Varlink method calls. A default time-out of 45s (currently) applies, which may be changed with this
+    call. Set to <constant>UINT64_MAX</constant> to disable the time-out, and to 0 to revert to revert back
+    to the default time-out. The time-out begins whenever a method call is started, and if no response is
+    received by the time the time-out elapses a synthetic <constant>io.systemd.TimedOut</constant> error is
+    raised as client-generated reply to the method call.</para>
+
+    <para>This call is particularly useful for method calls issued via
+    <function>sd_varlink_observe()</function> that shall remain open continously for a long time.</para>
+  </refsect1>
+
+  <refsect1>
+    <title>Return Value</title>
+
+    <para>On success, <function>sd_varlink_set_relative_timeout()</function> returns a non-negative integer. On
+    failure, it returns a negative errno-style error code.</para>
+
+    <refsect2>
+      <title>Errors</title>
+
+      <para>Returned errors may indicate the following problems:</para>
+
+      <variablelist>
+        <varlistentry>
+          <term><constant>-EINVAL</constant></term>
+
+          <listitem><para>An argument is invalid.</para></listitem>
+        </varlistentry>
+      </variablelist>
+    </refsect2>
+  </refsect1>
+
+  <xi:include href="libsystemd-pkgconfig.xml" />
+
+  <refsect1>
+    <title>History</title>
+    <para><function>sd_varlink_set_relative_timeout()</function> was added in version 257.</para>
+  </refsect1>
+
+  <refsect1>
+    <title>See Also</title>
+
+    <para><simplelist type="inline">
+      <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
+      <member><citerefentry><refentrytitle>sd-varlink</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
+    </simplelist></para>
+  </refsect1>
+
+</refentry>
index 1666162e890592c076aea58ad5d2f7cfbbc8d2ba..ee2272f94338350dbe1fa98305aa9e4901a01928 100644 (file)
@@ -2911,9 +2911,9 @@ _public_ int sd_varlink_get_peer_pidfd(sd_varlink *v) {
 
 _public_ int sd_varlink_set_relative_timeout(sd_varlink *v, uint64_t timeout) {
         assert_return(v, -EINVAL);
-        assert_return(timeout > 0, -EINVAL);
 
-        v->timeout = timeout;
+        /* If set to 0, reset to default value */
+        v->timeout = timeout == 0 ? VARLINK_DEFAULT_TIMEOUT_USEC : timeout;
         return 0;
 }