Merge pull request #15503 from DaanDeMeyer/sd-bus-get-docs

sd-bus: Add sd_bus_get_scope/tid/unique_name docs
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-04-21 09:16:29 +02:00
committed by GitHub
4 changed files with 153 additions and 86 deletions
+3
View File
@@ -379,6 +379,9 @@ manpages = [
'3',
['sd_bus_get_allow_interactive_authorization',
'sd_bus_get_description',
'sd_bus_get_scope',
'sd_bus_get_tid',
'sd_bus_get_unique_name',
'sd_bus_is_anonymous',
'sd_bus_is_trusted',
'sd_bus_set_allow_interactive_authorization',
+3
View File
@@ -80,6 +80,9 @@
<citerefentry><refentrytitle>sd_bus_get_fd</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_method_call_timeout</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_n_queued_read</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_scope</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_tid</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_unique_name</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_is_bus_client</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_is_server</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+58 -48
View File
@@ -26,7 +26,8 @@
<refname>sd_bus_get_events</refname>
<refname>sd_bus_get_timeout</refname>
<refpurpose>Get the file descriptor, I/O events and time-out to wait for from a message bus object</refpurpose>
<refpurpose>Get the file descriptor, I/O events and time-out to wait for from a message bus
object</refpurpose>
</refnamediv>
<refsynopsisdiv>
@@ -61,65 +62,74 @@
<refsect1>
<title>Description</title>
<para><function>sd_bus_get_fd()</function> returns the file descriptor used to communicate from a message bus
object. This descriptor can be used with <citerefentry
project='man-pages'><refentrytitle>poll</refentrytitle><manvolnum>3</manvolnum></citerefentry> or a similar
function to wait for I/O events on the specified bus connection object. If the bus object was configured with the
<function>sd_bus_set_fd()</function> function, then the <parameter>input_fd</parameter> file descriptor used in
that call is returned.</para>
<para><function>sd_bus_get_fd()</function> returns the file descriptor used to communicate from
a message bus object. This descriptor can be used with
<citerefentry project='man-pages'><refentrytitle>poll</refentrytitle><manvolnum>3</manvolnum></citerefentry>
or a similar function to wait for I/O events on the specified bus connection object. If the bus
object was configured with the <function>sd_bus_set_fd()</function> function, then the
<parameter>input_fd</parameter> file descriptor used in that call is returned.</para>
<para><function>sd_bus_set_fd()</function> sets the file descriptors used to communicate from a message bus
object. Both <parameter>input_fd</parameter> and <parameter>output_fd</parameter> must be valid file descriptors.
The same file descriptor may be used as both the input and the output file descriptor. This function must be called
before the bus is started.</para>
<para><function>sd_bus_set_fd()</function> sets the file descriptors used to communicate from a
message bus object. Both <parameter>input_fd</parameter> and <parameter>output_fd</parameter>
must be valid file descriptors. The same file descriptor may be used as both the input and the
output file descriptor. This function must be called before the bus is started.</para>
<para><function>sd_bus_get_events()</function> returns the I/O events to wait for, suitable for passing to
<function>poll()</function> or a similar call. Returns a combination of <constant>POLLIN</constant>,
<constant>POLLOUT</constant>, … events, or negative on error.</para>
<para><function>sd_bus_get_events()</function> returns the I/O events to wait for, suitable for
passing to <function>poll()</function> or a similar call. Returns a combination of
<constant>POLLIN</constant>, <constant>POLLOUT</constant>, … events, or negative on error.
</para>
<para><function>sd_bus_get_timeout()</function> returns the time-out in µs to pass to to
<function>poll()</function> or a similar call when waiting for events on the specified bus connection. The returned
time-out may be zero, in which case a subsequent I/O polling call should be invoked in non-blocking mode. The
returned timeout may be <constant>UINT64_MAX</constant> in which case the I/O polling call may block indefinitely,
without any applied time-out. Note that the returned time-out should be considered only a maximum sleeping time. It
is permissible (and even expected) that shorter time-outs are used by the calling program, in case other event
sources are polled in the same event loop. Note that the returned time-value is relative and specified in
microseconds. When converting this value in order to pass it as third argument to <function>poll()</function>
(which expects milliseconds), care should be taken to use a division that rounds up to ensure the I/O polling
operation doesn't sleep for shorter than necessary, which might result in unintended busy looping (alternatively,
use <citerefentry project='man-pages'><refentrytitle>ppoll</refentrytitle><manvolnum>3</manvolnum></citerefentry>
instead of plain <function>poll()</function>, which understands time-outs with nano-second granularity).</para>
<function>poll()</function> or a similar call when waiting for events on the specified bus
connection. The returned time-out may be zero, in which case a subsequent I/O polling call
should be invoked in non-blocking mode. The returned timeout may be
<constant>UINT64_MAX</constant> in which case the I/O polling call may block indefinitely,
without any applied time-out. Note that the returned time-out should be considered only a
maximum sleeping time. It is permissible (and even expected) that shorter time-outs are used by
the calling program, in case other event sources are polled in the same event loop. Note that
the returned time-value is relative and specified in microseconds. When converting this value in
order to pass it as third argument to <function>poll()</function> (which expects milliseconds),
care should be taken to use a division that rounds up to ensure the I/O polling operation
doesn't sleep for shorter than necessary, which might result in unintended busy looping
(alternatively, use
<citerefentry project='man-pages'><refentrytitle>ppoll</refentrytitle><manvolnum>3</manvolnum></citerefentry>
instead of plain <function>poll()</function>, which understands time-outs with nano-second
granularity).</para>
<para>These three functions are useful to hook up a bus connection object with an external or manual event loop
involving <function>poll()</function> or a similar I/O polling call. Before each invocation of the I/O polling
call, all three functions should be invoked: the file descriptor returned by <function>sd_bus_get_fd()</function>
should be polled for the events indicated by <function>sd_bus_get_events()</function>, and the I/O call should
block for that up to the time-out returned by <function>sd_bus_get_timeout()</function>. After each I/O polling
<para>These three functions are useful to hook up a bus connection object with an external or
manual event loop involving <function>poll()</function> or a similar I/O polling call. Before
each invocation of the I/O polling call, all three functions should be invoked: the file
descriptor returned by <function>sd_bus_get_fd()</function> should be polled for the events
indicated by <function>sd_bus_get_events()</function>, and the I/O call should block for that up
to the time-out returned by <function>sd_bus_get_timeout()</function>. After each I/O polling
call the bus connection needs to process incoming or outgoing data, by invoking
<citerefentry><refentrytitle>sd_bus_process</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
<citerefentry><refentrytitle>sd_bus_process</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
</para>
<para>Note that these function are only one of three supported ways to implement I/O event handling for bus
connections. Alternatively use
<citerefentry><refentrytitle>sd_bus_attach_event</refentrytitle><manvolnum>3</manvolnum></citerefentry> to attach a
bus connection to an <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>
event loop. Or use <citerefentry><refentrytitle>sd_bus_wait</refentrytitle><manvolnum>3</manvolnum></citerefentry>
<para>Note that these functions are only one of three supported ways to implement I/O event
handling for bus connections. Alternatively use
<citerefentry><refentrytitle>sd_bus_attach_event</refentrytitle><manvolnum>3</manvolnum></citerefentry>
to attach a bus connection to an
<citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>
event loop. Or use
<citerefentry><refentrytitle>sd_bus_wait</refentrytitle><manvolnum>3</manvolnum></citerefentry>
as a simple synchronous, blocking I/O waiting call.</para>
</refsect1>
<refsect1>
<title>Return Value</title>
<para>On success, <function>sd_bus_get_fd()</function> returns the file descriptor used for communication. On failure,
it returns a negative errno-style error code.</para>
<para>On success, <function>sd_bus_get_fd()</function> returns the file descriptor used for
communication. On failure, it returns a negative errno-style error code.</para>
<para>On success, <function>sd_bus_set_fd()</function> returns a non-negative integer. On failure, it returns a
negative errno-style error code.</para>
<para>On success, <function>sd_bus_set_fd()</function> returns a non-negative integer. On
failure, it returns a negative errno-style error code.</para>
<para>On success, <function>sd_bus_get_events()</function> returns the I/O event mask to use for I/O event watching.
On failure, it returns a negative errno-style error code.</para>
<para>On success, <function>sd_bus_get_events()</function> returns the I/O event mask to use for
I/O event watching. On failure, it returns a negative errno-style error code.</para>
<para>On success, <function>sd_bus_get_timeout()</function> returns a non-negative integer. On failure, it returns a
negative errno-style error code.</para>
<para>On success, <function>sd_bus_get_timeout()</function> returns a non-negative integer. On
failure, it returns a negative errno-style error code.</para>
<refsect2>
<title>Errors</title>
@@ -136,8 +146,8 @@
<varlistentry>
<term><constant>-ECHILD</constant></term>
<listitem><para>The bus connection was allocated in a parent process and is being reused in a child
process after <function>fork()</function>.</para></listitem>
<listitem><para>The bus connection was allocated in a parent process and is being reused
in a child process after <function>fork()</function>.</para></listitem>
</varlistentry>
<varlistentry>
@@ -157,8 +167,8 @@
<varlistentry>
<term><constant>-EBADF</constant></term>
<listitem><para>An invalid file descriptor was passed to <function>sd_bus_set_fd()</function>.
</para></listitem>
<listitem><para>An invalid file descriptor was passed to
<function>sd_bus_set_fd()</function>.</para></listitem>
</varlistentry>
<varlistentry>
+89 -38
View File
@@ -24,6 +24,9 @@
<refname>sd_bus_is_trusted</refname>
<refname>sd_bus_set_allow_interactive_authorization</refname>
<refname>sd_bus_get_allow_interactive_authorization</refname>
<refname>sd_bus_get_scope</refname>
<refname>sd_bus_get_tid</refname>
<refname>sd_bus_get_unique_name</refname>
<refpurpose>Set or query properties of a bus object</refpurpose>
</refnamediv>
@@ -76,59 +79,94 @@
<funcdef>int <function>sd_bus_get_allow_interactive_authorization</function></funcdef>
<paramdef>sd_bus *<parameter>bus</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_bus_get_scope</function></funcdef>
<paramdef>sd_bus *<parameter>bus</parameter></paramdef>
<paramdef>const char **<parameter>scope</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_bus_get_tid</function></funcdef>
<paramdef>sd_bus *<parameter>bus</parameter></paramdef>
<paramdef>pid_t *<parameter>tid</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_bus_get_unique_name</function></funcdef>
<paramdef>sd_bus *<parameter>bus</parameter></paramdef>
<paramdef>const char **<parameter>unique</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para><function>sd_bus_set_description()</function> sets the description string
that is used in logging to the specified string. The string is copied internally
and freed when the bus object is deallocated. The
<parameter>description</parameter> argument may be <constant>NULL</constant>, in
which case the description is unset. This function must be called before the bus
is started.</para>
<para><function>sd_bus_set_description()</function> sets the description string that is used in
logging to the specified string. The string is copied internally and freed when the bus object
is deallocated. The <parameter>description</parameter> argument may be
<constant>NULL</constant>, in which case the description is unset. This function must be called
before the bus is started.</para>
<para><function>sd_bus_get_description()</function> returns a description string
in <parameter>description</parameter>. This string may have been previously set
with <function>sd_bus_set_description()</function> or
<para><function>sd_bus_get_description()</function> returns a description string in
<parameter>description</parameter>. This string may have been previously set with
<function>sd_bus_set_description()</function> or
<citerefentry><refentrytitle>sd_bus_open_with_description</refentrytitle><manvolnum>3</manvolnum></citerefentry>
or similar. If not set this way, a default string like <literal>system</literal>
or <literal>user</literal> will be returned for the system or user buses,
and <constant>NULL</constant> otherwise.</para>
or similar. If not set this way, a default string like <literal>system</literal> or
<literal>user</literal> will be returned for the system or user buses, and
<constant>NULL</constant> otherwise.</para>
<para><function>sd_bus_set_anonymous()</function> enables or disables "anonymous
authentication", i.e. lack of authentication, of the bus peer. This function must
be called before the bus is started. See the <ulink
url="view-source:https://dbus.freedesktop.org/doc/dbus-specification.html#auth-mechanisms">Authentication
Mechanisms</ulink> section of the D-Bus specification for details.</para>
<para><function>sd_bus_set_anonymous()</function> enables or disables "anonymous authentication",
i.e. lack of authentication, of the bus peer. This function must be called before the bus is
started. See the
<ulink url="view-source:https://dbus.freedesktop.org/doc/dbus-specification.html#auth-mechanisms">
Authentication Mechanisms</ulink> section of the D-Bus specification for details.</para>
<para><function>sd_bus_is_anonymous()</function> returns true if the bus connection allows anonymous
authentication (in the sense described in previous paragraph).</para>
<para><function>sd_bus_is_anonymous()</function> returns true if the bus connection allows
anonymous authentication (in the sense described in previous paragraph).</para>
<para><function>sd_bus_set_trusted()</function> sets the "trusted" state on the
<parameter>bus</parameter> object. If true, all connections on the bus are
trusted and access to all privileged and unprivileged methods is granted. This
function must be called before the bus is started.</para>
<parameter>bus</parameter> object. If true, all connections on the bus are trusted and access to
all privileged and unprivileged methods is granted. This function must be called before the bus
is started.</para>
<para><function>sd_bus_is_trusted()</function> returns true if the bus connection is trusted (in the
sense described in previous paragraph).</para>
<para><function>sd_bus_is_trusted()</function> returns true if the bus connection is trusted (in
the sense described in previous paragraph).</para>
<para><function>sd_bus_set_allow_interactive_authorization()</function>
enables or disables interactive authorization for method calls. If true,
messages are marked with the
<para><function>sd_bus_set_allow_interactive_authorization()</function> enables or disables
interactive authorization for method calls. If true, messages are marked with the
<constant>ALLOW_INTERACTIVE_AUTHORIZATION</constant> flag specified by the
<ulink
url="view-source:https://dbus.freedesktop.org/doc/dbus-specification.html">D-Bus</ulink>
specification, informing the receiving side that the caller is prepared to
wait for interactive authorization, which might take a considerable time to
complete. If this flag is set, the user may be queried for passwords or
confirmation via <ulink
url="http://www.freedesktop.org/wiki/Software/polkit">polkit</ulink> or a
similar framework.</para>
<ulink url="view-source:https://dbus.freedesktop.org/doc/dbus-specification.html">D-Bus</ulink>
specification, informing the receiving side that the caller is prepared to wait for interactive
authorization, which might take a considerable time to complete. If this flag is set, the user
may be queried for passwords or confirmation via
<ulink url="http://www.freedesktop.org/wiki/Software/polkit">polkit</ulink> or a similar
framework.</para>
<para><function>sd_bus_get_allow_interactive_authorization()</function> returns
true if interactive authorization is allowed and false if not.</para>
<para><function>sd_bus_get_allow_interactive_authorization()</function> returns true if
interactive authorization is allowed and false if not.</para>
<para><function>sd_bus_get_scope()</function> stores the scope of the given bus object in
<parameter>scope</parameter>. The scope of the system bus is <literal>system</literal>. The
scope of a user session bus is <literal>user</literal>. If the given bus object is not the
system or a user session bus, <function>sd_bus_get_scope()</function> returns an error.</para>
<para><function>sd_bus_get_tid()</function> stores the kernel thread id of the thread associated
with the given bus object in <parameter>tid</parameter>. If <parameter>bus</parameter> is a
default bus object obtained by calling one of the functions of the
<citerefentry><refentrytitle>sd_bus_default</refentrytitle><manvolnum>3</manvolnum></citerefentry>
family of functions, it stores the thread id of the thread the bus object was created in.
Otherwise, if the bus object is attached to an event loop, it stores the thread id of the
thread the event loop object was created in. If <parameter>bus</parameter> is not a default bus
object and is not attached to an event loop, <function>sd_bus_get_tid()</function> returns an
error.</para>
<para><function>sd_bus_get_unique_name()</function> stores the unique name of the bus object on
the bus in <parameter>unique</parameter>. See
<ulink url="https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus">
The D-Bus specification</ulink> for more information on bus names. Note that the caller does not
own the string stored in <parameter>unique</parameter> and should not free it.</para>
</refsect1>
<refsect1>
@@ -172,8 +210,21 @@
<listitem><para>Memory allocation failed.</para></listitem>
</varlistentry>
</variablelist>
<varlistentry>
<term><constant>-ENODATA</constant></term>
<listitem><para>The bus object passed to <function>sd_bus_get_scope()</function> was not a
system or user session bus.</para></listitem>
</varlistentry>
<varlistentry>
<term><constant>-ENXIO</constant></term>
<listitem><para>The bus object passed to <function>sd_bus_get_tid()</function> was not a
default bus object and is not attached to an event loop.</para></listitem>
</varlistentry>
</variablelist>
</refsect2>
</refsect1>