SD_BUS_SET_FD(3)
π SD_BUS_SET_FD β bestie, let's talk file descriptors
okay so this is the page for sd_bus_set_fd out of the sd_bus_set_fd manual, and honestly it's a whole vibe: you're basically hand-feeding your bus connection the file descriptors it's gonna chat over. iconic behavior, honestly. π¦
β¨ NAME β¨
sd_bus_set_fd β set the file descriptors to use for bus communication π
β¨ SYNOPSIS β¨
#include <systemd/sd-bus.h>
int sd_bus_set_fd(sd_bus *bus, int input_fd, int output_fd);
β¨ DESCRIPTION β¨
so sd_bus_set_fd() does exactly what it says on the tin: it sets the file descriptors your bus connection object uses to actually talk. π
both input_fd and output_fd have to be valid file descriptors, and they need to refer to stream-based file objects β think a stream socket, a pair of pipes or FIFOs, or honestly even a TTY device, no cap. input_fd must be readable π and output_fd must be writable βοΈ.
the same file descriptor may be used as both the input and the output fd β and tbh that's typically what happens, that's the normal slay. π
β οΈ timing matters, bestie: this function must be called before the bus connection is started via sd_bus_start(3). not after. before.
the bus connection object will take possession of the file descriptors you passed in, and it'll close them automatically when it's freed. so like⦠they're its kids now. 𫢠if you don't want that, use sd_bus_set_close_on_exit(3) to turn off this behaviour.
β¨ RETURN VALUE β¨
on success, sd_bus_set_fd() returns a non-negative integer (we love a win β¨). on failure, it returns a negative errno-style error code (we do not love that π).
πΈ Errors
the errors it might throw at you mean the following:
-EINVALβ an invalid bus object was passed. π«- Added in version 248.
-ECHILDβ the bus connection was allocated in a parent process and is being reused in a child process afterfork(). πΆ- Added in version 248.
-EBADFβ an invalid file descriptor was passed tosd_bus_set_fd(). π- Added in version 248.
-ENOPKGβ the bus cannot be resolved. π§©- Added in version 248.
-EPERMβ the bus connection has already been started. π- Added in version 248.
β¨ NOTES β¨
the functions described here are available as a shared library, and you can compile against and link to them with the libsystemd pkg-config(1) file. π
all functions listed here are thread-agnostic, and only a single thread may operate on a given object at any given time β³. different threads may access the same object at different times, and multiple independent objects may be used from different threads in parallel. so like, share the toy but not at the same time, yk? π§Έ
π heads up: the code described here usesgetenv(3), which is declared to be not multi-thread-safe. that means code calling the functions described here must not callsetenv(3)from a parallel thread. the recommendation is to only do calls tosetenv()from an early phase of the program, when no other threads have been started. main character energy only at the beginning of the program, periodt. π
β¨ HISTORY β¨
sd_bus_set_fd() was added in version 248. β
β¨ SEE ALSO β¨
systemd(1), sd-bus(3), sd_bus_get_fd(3), sd_bus_start(3) πΈ
okay that's the whole page, bestie β go set those fds and slay π this was page SD_BUS_SET_FD(3) from systemd 261.3, signing off πβ¨
π¦ where this page comes from
- ubuntu stonking: libsystemd-dev 261.3-0ubuntu3 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms