Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


sd_bus_get_fd(3) — Linux manual page

NAME |SYNOPSIS |DESCRIPTION |RETURN VALUE |NOTES |HISTORY |SEE ALSO |COLOPHON

SD_BUS_GET_FD(3)              sd_bus_get_fdSD_BUS_GET_FD(3)

NAME        top

       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

SYNOPSIS        top

#include <systemd/sd-bus.h>int sd_bus_get_fd(sd_bus *bus);int sd_bus_get_events(sd_bus *bus);int sd_bus_get_timeout(sd_bus *bus, uint64_t *timeout_usec);

DESCRIPTION        top

sd_bus_get_fd()returns the file descriptor used to communicate       from a message bus object. This descriptor can be used withpoll(3) or a similar function to wait for I/O events on the       specified bus connection object. If the bus object was configured       with thesd_bus_set_fd()function, then theinput_fd file       descriptor used in that call is returned.sd_bus_get_events()returns the I/O events to wait for, suitable       for passing topoll()or a similar call. Returns a combination ofPOLLIN,POLLOUT, ... events, or negative on error.sd_bus_get_timeout()returns theabsolute timeout in μs, from       which the relative timeout to pass topoll()(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 beUINT64_MAXin 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 ofCLOCK_MONOTONICand specified in       microseconds. When converting this value in order to pass it as       third argument topoll()(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, useppoll(2) instead of       plainpoll(), which understands timeouts with nano-second       granularity).       These three functions are useful to hook up a bus connection       object with an external or manual event loop involvingpoll()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 bysd_bus_get_fd()should be polled for the       events indicated bysd_bus_get_events(), and the I/O call should       block for that up to the timeout returned bysd_bus_get_timeout().       After each I/O polling call the bus connection needs to process       incoming or outgoing data, by invokingsd_bus_process(3).       Note that these functions are only one of three supported ways to       implement I/O event handling for bus connections. Alternatively       usesd_bus_attach_event(3) to attach a bus connection to ansd-event(3) event loop. Or usesd_bus_wait(3) as a simple       synchronous, blocking I/O waiting call.

RETURN VALUE        top

       On success,sd_bus_get_fd()returns the file descriptor used for       communication. On failure, it returns a negative errno-style error       code.       On success,sd_bus_get_events()returns the I/O event mask to use       for I/O event watching. On failure, it returns a negative       errno-style error code.       On success,sd_bus_get_timeout()returns a non-negative integer.       On failure, it returns a negative errno-style error code.Errors       Returned errors may indicate the following problems:-EINVAL           An invalid bus object was passed.-ECHILD           The bus connection was allocated in a parent process and is           being reused in a child process afterfork().-ENOTCONN           The bus connection has been terminated.-EPERM           Two distinct file descriptors were passed for input and output           usingsd_bus_set_fd(), whichsd_bus_get_fd()cannot return.-ENOPKG           The bus cannot be resolved.

NOTES        top

       Functions described here are available as a shared library, which       can be compiled against and linked to with thelibsystemd pkg-config(1) file.       The code described here usesgetenv(3), which is declared to be       not multi-thread-safe. This means that the code calling the       functions described here must not callsetenv(3) from a parallel       thread. It is recommended to only do calls tosetenv()from an       early phase of the program when no other threads have been       started.

HISTORY        top

sd_bus_get_fd(),sd_bus_get_events(), andsd_bus_get_timeout()       were added in version 221.

SEE ALSO        top

systemd(1),sd-bus(3),sd_bus_process(3),sd_bus_attach_event(3),sd_bus_wait(3),sd_bus_set_fd(3),poll(3)

COLOPHON        top

       This page is part of thesystemd (systemd system and service       manager) project.  Information about the project can be found at       ⟨http://www.freedesktop.org/wiki/Software/systemd⟩.  If you have a       bug report for this manual page, see       ⟨http://www.freedesktop.org/wiki/Software/systemd/#bugreports⟩.       This page was obtained from the project's upstream Git repository       ⟨https://github.com/systemd/systemd.git⟩ on 2025-08-11.  (At that       time, the date of the most recent commit that was found in the       repository was 2025-08-11.)  If you discover any rendering       problems in this HTML version of the page, or you believe there is       a better or more up-to-date source for the page, or you have       corrections or improvements to the information in this COLOPHON       (which isnot part of the original manual page), send a mail to       man-pages@man7.orgsystemd 258~rc2SD_BUS_GET_FD(3)

Pages that refer to this page:sd-bus(3)sd_bus_attach_event(3)sd_bus_process(3)sd_bus_set_fd(3)sd_bus_wait(3)systemd.directives(7)systemd.index(7)



HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp