SENDFD(1)

πŸ“¦ version 2024.12.07, in nixpkgs unstable

✨ sendfd β€” The sendfd program ✨

okay so bestie, welcome to the manual page for The sendfd program β€” header has that lil () after it, and that's the vibe. the actual command is sendfd, and she is here to hand off file descriptors like an absolute queen. πŸ’…

πŸŒ€ SYNOPSIS πŸŒ€

sendfd socket fd [...] [: command arg ...]

πŸ’– DESCRIPTION πŸ’–

okay so sendfd passes one or more inherited file descriptors over a Unix-domain socket. the sockets in question can be ones opened with s6-ipcclient (https://skarnet.org/software/s6/s6-ipcclient.html), s6-ipcserver (https://skarnet.org/software/s6/s6-ipcserver.html), or ucspi-unix (https://untroubled.org/ucspi-unix/) β€” yes bestie, those exact links, keep them. πŸ¦‹

another process that has a descriptor for the other end of the socket can receive the descriptors using the fd_xfer_recv(), fd_xfer_child(), or fd_xfer_ucspi() library functions. πŸ’Œ

ngl, this part is crucial: the received descriptors will not necessarily have the same numeric values, but they will refer to the same open file handles, as if by dup(). so the numbers can change; the actual open file handle energy does not. periodt. ✨

after passing the descriptors, sendfd execs the given command, if any. and yes β€” a colon separates the file descriptors from the command. : is the divider, the little boundary line, the "fds on this side, command on that side" moment. πŸŽ€

πŸ’« why would you use this? πŸ’«

this is useful, for example, in network clients that want to use UCSPI client programs to establish connections, but which can't have all connections opened at startup. highkey a whole mood. 😭

when the client is ready to open a new connection, it can create a socket using socketpair(), and then spawn tcpclient (or any other UCSPI client), with sendfd given to tcpclient as a subcommand to pass the new connection descriptor back to the original process over the socketpair() socket. literally the group chat of file descriptors β€” the new connection gets passed back home. 🫢


πŸ’– footer check: The sendfd program() β€” that's the footer this page ends on, and no separate source/version/date is listed, so that's the whole page, bestie. no cap, slay. πŸŽ€βœ¨

πŸ“¦ where this page comes from