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 after fork(). πŸ‘Ά
    • Added in version 248.
  • -EBADF β€” an invalid file descriptor was passed to sd_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 uses getenv(3), which is declared to be not multi-thread-safe. that means code calling the functions described here must not call setenv(3) from a parallel thread. the recommendation is to only do calls to setenv() 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