]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
docs: add man pages for sd_device_enumerator_[new,ref,unref,unrefp] (#37586)
authorShubhendra Kushwaha <shubhendrakushwaha94@gmail.com>
Sat, 24 May 2025 20:01:27 +0000 (01:31 +0530)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 28 May 2025 18:16:16 +0000 (19:16 +0100)
For #20929.

(cherry picked from commit ac8ed83947237956b867de9cfbf5fcd26de8ea96)
(cherry picked from commit 17e5c276b90f45bd0ed496352d254105ecdea935)

man/meson.build
man/rules/meson.build
man/sd_device_enumerator_new-example.c [new file with mode: 0644]
man/sd_device_enumerator_new.xml [new file with mode: 0644]

index 20a073442e64b78be5488bc290106a23b9b73d5a..5c3fe6dca3fed1a97882671163d2e52be8877c5f 100644 (file)
@@ -272,6 +272,7 @@ simple_examples = files(
         'sd-bus-container-read.c',
         'sd_bus_error-example.c',
         'sd_bus_service_reconnect.c',
+        'sd_device_enumerator_new-example.c',
         'send-unit-files-changed.c',
         'vtable-example.c',
 )
index a9a2a25c0d791242921bb0a8a452288359e0e52f..ac3a71edecd380dbc7f8e9492c5ad5d5d28c81b8 100644 (file)
@@ -519,6 +519,12 @@ manpages = [
    'sd_bus_track_unrefp'],
   ''],
  ['sd_bus_wait', '3', [], ''],
+ ['sd_device_enumerator_new',
+  '3',
+  ['sd_device_enumerator_ref',
+   'sd_device_enumerator_unref',
+   'sd_device_enumerator_unrefp'],
+  ''],
  ['sd_device_get_syspath',
   '3',
   ['sd_device_get_devname',
diff --git a/man/sd_device_enumerator_new-example.c b/man/sd_device_enumerator_new-example.c
new file mode 100644 (file)
index 0000000..301d603
--- /dev/null
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: MIT-0 */
+
+#include <stdio.h>
+#include <systemd/sd-device.h>
+
+int main(void) {
+    sd_device_enumerator *enumerator;
+    int r;
+
+    r = sd_device_enumerator_new(&enumerator);
+    if (r < 0) {
+        fprintf(stderr, "Failed to create enumerator: %s\n", strerror(-r));
+        return 1;
+    }
+
+    sd_device_enumerator_ref(enumerator);
+    sd_device_enumerator_unref(enumerator);
+
+    sd_device_enumerator_unref(enumerator);
+
+    return 0;
+}
diff --git a/man/sd_device_enumerator_new.xml b/man/sd_device_enumerator_new.xml
new file mode 100644 (file)
index 0000000..34f52e6
--- /dev/null
@@ -0,0 +1,151 @@
+<?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_device_enumerator_new" xmlns:xi="http://www.w3.org/2001/XInclude">
+  <refentryinfo>
+    <title>sd_device_enumerator_new</title>
+    <productname>systemd</productname>
+  </refentryinfo>
+
+  <refmeta>
+    <refentrytitle>sd_device_enumerator_new</refentrytitle>
+    <manvolnum>3</manvolnum>
+  </refmeta>
+
+  <refnamediv>
+    <refname>sd_device_enumerator_new</refname>
+    <refname>sd_device_enumerator_ref</refname>
+    <refname>sd_device_enumerator_unref</refname>
+    <refname>sd_device_enumerator_unrefp</refname>
+    <refpurpose>Create, reference, and release a device enumerator object</refpurpose>
+  </refnamediv>
+
+  <refsynopsisdiv>
+    <funcsynopsis>
+      <funcsynopsisinfo>#include &lt;systemd/sd-device.h&gt;</funcsynopsisinfo>
+
+      <funcprototype>
+        <funcdef>int <function>sd_device_enumerator_new</function></funcdef>
+        <paramdef>sd_device_enumerator **<parameter>ret</parameter></paramdef>
+      </funcprototype>
+
+      <funcprototype>
+        <funcdef>sd_device_enumerator* <function>sd_device_enumerator_ref</function></funcdef>
+        <paramdef>sd_device_enumerator *<parameter>enumerator</parameter></paramdef>
+      </funcprototype>
+
+      <funcprototype>
+        <funcdef>sd_device_enumerator* <function>sd_device_enumerator_unref</function></funcdef>
+        <paramdef>sd_device_enumerator *<parameter>enumerator</parameter></paramdef>
+      </funcprototype>
+
+      <funcprototype>
+        <funcdef>void <function>sd_device_enumerator_unrefp</function></funcdef>
+        <paramdef>sd_device_enumerator **<parameter>enumerator</parameter></paramdef>
+      </funcprototype>
+    </funcsynopsis>
+  </refsynopsisdiv>
+
+  <refsect1>
+    <title>Description</title>
+    <para>The <function>sd_device_enumerator</function> family of functions provides a way to iterate
+    over devices recognized by <citerefentry><refentrytitle>systemd-udevd</refentrytitle><manvolnum>8</manvolnum>
+    </citerefentry>. The enumerator allows filtering and matching devices by subsystem, properties and
+    other attributes.</para>
+
+    <para><function>sd_device_enumerator_new()</function> creates a new device enumerator object and
+    stores the result in the pointer referenced by <parameter>ret</parameter>. Returns 0 on success,
+    or a negative errno-style error code on failure.</para>
+
+    <para><function>sd_device_enumerator_ref()</function> increases the reference count of the
+    specified <parameter>enumerator</parameter> by one.</para>
+
+    <para><function>sd_device_enumerator_unref()</function> decreases the reference count of the
+    <parameter>enumerator</parameter> by one. When the reference count reaches zero, the enumerator
+    object is destroyed and cannot be used anymore, so further calls to <function>sd_device_enumerator_unref()
+    </function> or <function>sd_device_enumerator_unrefp()</function> are illegal.</para>
+
+    <para><function>sd_device_enumerator_unrefp()</function> is similar to
+    <function>sd_device_enumerator_unref()</function> but takes a pointer to a
+    pointer to an <type>sd_device_enumerator</type> object. This call is useful in
+    conjunction with GCC's and LLVM's <ulink
+    url="https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up
+    Variable Attribute</ulink>. Note that this function is defined as an
+    inline function. Use a declaration like the following, in order to
+    allocate a <type>sd_device_enumerator</type> object that is freed automatically as the code
+    block is left:</para>
+
+    <programlisting>{
+  __attribute__((cleanup(sd_device_enumerator_unrefp))) sd_device_enumerator *enumerator = NULL;
+  int r;
+  …
+  r = sd_device_enumerator_new(&amp;enumerator);
+  if (r &lt; 0)
+    fprintf(stderr, "Failed to allocate sd_device_enumerator: %s\n", strerror(-r));
+  …
+}</programlisting>
+
+    <para><function>sd_device_enumerator_ref()</function> and <function>sd_device_enumerator_unref()</function>
+    execute no operation if the <parameter>enumerator</parameter> is <constant>NULL</constant>.
+    <function>sd_device_enumerator_unrefp()</function> will first dereference
+    its argument, which must not be <constant>NULL</constant>, and will execute no operation if
+    <emphasis>that</emphasis> is <constant>NULL</constant>.</para>
+  </refsect1>
+
+  <refsect1>
+    <title>Return Value</title>
+
+    <para><function>sd_device_enumerator_new()</function> returns 0 on success or a negative
+    errno-style error code on failure.</para>
+
+    <para><function>sd_device_enumerator_ref()</function> always returns the enumerator pointer.</para>
+    <para><function>sd_device_enumerator_unref()</function> always returns <constant>NULL</constant>.</para>
+
+    <refsect2>
+      <title>Errors</title>
+
+      <para>Returned errors may indicate the following problems:</para>
+
+      <variablelist>
+        <varlistentry>
+          <term><constant>-ENOMEM</constant></term>
+
+          <listitem><para>Memory allocation failed.</para></listitem>
+        </varlistentry>
+        <varlistentry>
+          <term><constant>-EINVAL</constant></term>
+
+          <listitem><para>The argument is invalid.</para></listitem>
+        </varlistentry>
+      </variablelist>
+    </refsect2>
+  </refsect1>
+
+  <refsect1>
+    <title>Example</title>
+    <example>
+      <title>Using sd_device_enumerator_new()</title>
+      <programlisting><xi:include href="sd_device_enumerator_new-example.c" parse="text"/></programlisting>
+    </example>
+  </refsect1>
+
+  <refsect1>
+    <title>History</title>
+    <para><function>sd_device_enumerator_new()</function>, <function>sd_device_enumerator_ref()</function>,
+    <function>sd_device_enumerator_unref()</function>, and <function>sd_device_enumerator_unrefp()</function>
+    were added in version 240.</para>
+  </refsect1>
+
+  <refsect1>
+    <title>See Also</title>
+    <para><simplelist type="inline">
+      <member><citerefentry><refentrytitle>sd_device_ref</refentrytitle><manvolnum>3</manvolnum>
+      </citerefentry></member>
+      <member><citerefentry><refentrytitle>sd_device_enumerator_add_match_parent</refentrytitle>
+      <manvolnum>3</manvolnum></citerefentry></member>
+    </simplelist></para>
+  </refsect1>
+
+</refentry>