| 1 |
'\" t |
| 2 |
.TH "SD_BUS_GET_FD" "3" "" "systemd 261~rc3" "sd_bus_get_fd" |
| 3 |
.\" ----------------------------------------------------------------- |
| 4 |
.\" * Define some portability stuff |
| 5 |
.\" ----------------------------------------------------------------- |
| 6 |
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7 |
.\" http://bugs.debian.org/507673 |
| 8 |
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html |
| 9 |
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10 |
.ie \n(.g .ds Aq \(aq |
| 11 |
.el .ds Aq ' |
| 12 |
.\" ----------------------------------------------------------------- |
| 13 |
.\" * set default formatting |
| 14 |
.\" ----------------------------------------------------------------- |
| 15 |
.\" disable hyphenation |
| 16 |
.nh |
| 17 |
.\" disable justification (adjust text to left margin only) |
| 18 |
.ad l |
| 19 |
.\" ----------------------------------------------------------------- |
| 20 |
.\" * MAIN CONTENT STARTS HERE * |
| 21 |
.\" ----------------------------------------------------------------- |
| 22 |
.SH "NAME" |
| 23 |
sd_bus_get_fd, sd_bus_get_events, sd_bus_get_timeout \- Get the file descriptor, I/O events and timeout to wait for from a message bus object |
| 24 |
.SH "SYNOPSIS" |
| 25 |
.sp |
| 26 |
.ft B |
| 27 |
.nf |
| 28 |
#include <systemd/sd\-bus\&.h> |
| 29 |
.fi |
| 30 |
.ft |
| 31 |
.HP \w'int\ sd_bus_get_fd('u |
| 32 |
.BI "int sd_bus_get_fd(sd_bus\ *" "bus" ");" |
| 33 |
.HP \w'int\ sd_bus_get_events('u |
| 34 |
.BI "int sd_bus_get_events(sd_bus\ *" "bus" ");" |
| 35 |
.HP \w'int\ sd_bus_get_timeout('u |
| 36 |
.BI "int sd_bus_get_timeout(sd_bus\ *" "bus" ", uint64_t\ *" "timeout_usec" ");" |
| 37 |
.SH "DESCRIPTION" |
| 38 |
.PP |
| 39 |
\fBsd_bus_get_fd()\fR |
| 40 |
returns the file descriptor used to communicate from a message bus object\&. This descriptor can be used with |
| 41 |
\fBpoll\fR(3) |
| 42 |
or a similar function to wait for I/O events on the specified bus connection object\&. If the bus object was configured with the |
| 43 |
\fBsd_bus_set_fd()\fR |
| 44 |
function, then the |
| 45 |
\fIinput_fd\fR |
| 46 |
file descriptor used in that call is returned\&. |
| 47 |
.PP |
| 48 |
\fBsd_bus_get_events()\fR |
| 49 |
returns the I/O events to wait for, suitable for passing to |
| 50 |
\fBpoll()\fR |
| 51 |
or a similar call\&. Returns a combination of |
| 52 |
\fBPOLLIN\fR, |
| 53 |
\fBPOLLOUT\fR, \&... events, or negative on error\&. |
| 54 |
.PP |
| 55 |
\fBsd_bus_get_timeout()\fR |
| 56 |
returns the |
| 57 |
\fIabsolute\fR |
| 58 |
timeout in μs, from which the relative timeout to pass to |
| 59 |
\fBpoll()\fR |
| 60 |
(or a similar call) can be derived, when waiting for events on the specified bus connection\&. The returned timeout may be zero, in which case a subsequent I/O polling call should be invoked in non\-blocking mode\&. The returned timeout may be |
| 61 |
\fBUINT64_MAX\fR |
| 62 |
in which case the I/O polling call may block indefinitely, without any applied timeout\&. Note that the returned timeout should be considered only a maximum sleeping time\&. It is permissible (and even expected) that shorter timeouts 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 absolute, based of |
| 63 |
\fBCLOCK_MONOTONIC\fR |
| 64 |
and specified in microseconds\&. When converting this value in order to pass it as third argument to |
| 65 |
\fBpoll()\fR |
| 66 |
(which expects relative milliseconds), care should be taken to convert to a relative time and use a division that rounds up to ensure the I/O polling operation does not sleep for shorter than necessary, which might result in unintended busy looping (alternatively, use |
| 67 |
\fBppoll\fR(2) |
| 68 |
instead of plain |
| 69 |
\fBpoll()\fR, which understands timeouts with nano\-second granularity)\&. |
| 70 |
.PP |
| 71 |
These three functions are useful to hook up a bus connection object with an external or manual event loop involving |
| 72 |
\fBpoll()\fR |
| 73 |
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 |
| 74 |
\fBsd_bus_get_fd()\fR |
| 75 |
should be polled for the events indicated by |
| 76 |
\fBsd_bus_get_events()\fR, and the I/O call should block for that up to the timeout returned by |
| 77 |
\fBsd_bus_get_timeout()\fR\&. After each I/O polling call the bus connection needs to process incoming or outgoing data, by invoking |
| 78 |
\fBsd_bus_process\fR(3)\&. |
| 79 |
.PP |
| 80 |
Note that these functions are only one of three supported ways to implement I/O event handling for bus connections\&. Alternatively use |
| 81 |
\fBsd_bus_attach_event\fR(3) |
| 82 |
to attach a bus connection to an |
| 83 |
\fBsd-event\fR(3) |
| 84 |
event loop\&. Or use |
| 85 |
\fBsd_bus_wait\fR(3) |
| 86 |
as a simple synchronous, blocking I/O waiting call\&. |
| 87 |
.SH "RETURN VALUE" |
| 88 |
.PP |
| 89 |
On success, |
| 90 |
\fBsd_bus_get_fd()\fR |
| 91 |
returns the file descriptor used for communication\&. On failure, it returns a negative errno\-style error code\&. |
| 92 |
.PP |
| 93 |
On success, |
| 94 |
\fBsd_bus_get_events()\fR |
| 95 |
returns the I/O event mask to use for I/O event watching\&. On failure, it returns a negative errno\-style error code\&. |
| 96 |
.PP |
| 97 |
On success, |
| 98 |
\fBsd_bus_get_timeout()\fR |
| 99 |
returns a non\-negative integer\&. On failure, it returns a negative errno\-style error code\&. |
| 100 |
.SS "Errors" |
| 101 |
.PP |
| 102 |
Returned errors may indicate the following problems: |
| 103 |
.PP |
| 104 |
\fB\-EINVAL\fR |
| 105 |
.RS 4 |
| 106 |
An invalid bus object was passed\&. |
| 107 |
.RE |
| 108 |
.PP |
| 109 |
\fB\-ECHILD\fR |
| 110 |
.RS 4 |
| 111 |
The bus connection was allocated in a parent process and is being reused in a child process after |
| 112 |
\fBfork()\fR\&. |
| 113 |
.RE |
| 114 |
.PP |
| 115 |
\fB\-ENOTCONN\fR |
| 116 |
.RS 4 |
| 117 |
The bus connection has been terminated\&. |
| 118 |
.RE |
| 119 |
.PP |
| 120 |
\fB\-EPERM\fR |
| 121 |
.RS 4 |
| 122 |
Two distinct file descriptors were passed for input and output using |
| 123 |
\fBsd_bus_set_fd()\fR, which |
| 124 |
\fBsd_bus_get_fd()\fR |
| 125 |
cannot return\&. |
| 126 |
.RE |
| 127 |
.PP |
| 128 |
\fB\-ENOPKG\fR |
| 129 |
.RS 4 |
| 130 |
The bus cannot be resolved\&. |
| 131 |
.RE |
| 132 |
.SH "NOTES" |
| 133 |
.PP |
| 134 |
Functions described here are available as a shared library, which can be compiled against and linked to with the |
| 135 |
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1) |
| 136 |
file\&. |
| 137 |
.PP |
| 138 |
The code described here uses |
| 139 |
\fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call |
| 140 |
\fBsetenv\fR(3) |
| 141 |
from a parallel thread\&. It is recommended to only do calls to |
| 142 |
\fBsetenv()\fR |
| 143 |
from an early phase of the program when no other threads have been started\&. |
| 144 |
.SH "HISTORY" |
| 145 |
.PP |
| 146 |
\fBsd_bus_get_fd()\fR, |
| 147 |
\fBsd_bus_get_events()\fR, and |
| 148 |
\fBsd_bus_get_timeout()\fR |
| 149 |
were added in version 221\&. |
| 150 |
.SH "SEE ALSO" |
| 151 |
.PP |
| 152 |
\fBsystemd\fR(1), \fBsd-bus\fR(3), \fBsd_bus_process\fR(3), \fBsd_bus_attach_event\fR(3), \fBsd_bus_wait\fR(3), \fBsd_bus_set_fd\fR(3), \fBpoll\fR(3) |