It’s a pity that (as this gist documents) there are quite a few footguns and landmines scattered about that particular subsystem.
If you use AF_UNIX+SOCK_SEQPACKET sockets, the number of pitfalls decrease significantly, but that won't work for MacOS (but does anything even work on MacOS anyways?).
One major pitfall if you use AF_UNIX+SOCK_SEQPACKET is that you can no longer differentiate receipt of 0-sized messages versus stream EOF.
SOCK_DGRAM allows 0-byte datagrams. There's no EOF given the socket isn't even connection-oriented (although FreeBSD might report ECONNRESET on socketpair() sockets).
SOCK_SEQPACKET allows 0-byte datagrams, but won't differentiate 0-sized datagrams from EOF.
I vaguely recall that Linux was uncommon in allowing multiple FDs to be passed in one message, specifically that the BSDs did not support such behaviour. I guess given the other fixed BSD bug, that that limitation was removed from t he BSDs.
Passing file descriptors through a socket is really powerful. Unix sockets themselves, controlled by filesystem privileges, are really powerful.
It’s a pity that (as this gist documents) there are quite a few footguns and landmines scattered about that particular subsystem.
If you use AF_UNIX+SOCK_SEQPACKET sockets, the number of pitfalls decrease significantly, but that won't work for MacOS (but does anything even work on MacOS anyways?).
One major pitfall if you use AF_UNIX+SOCK_SEQPACKET is that you can no longer differentiate receipt of 0-sized messages versus stream EOF.
Isn't AF_UNIX+SOCK_DGRAM enough?
It depends on use-case.
SOCK_DGRAM allows 0-byte datagrams. There's no EOF given the socket isn't even connection-oriented (although FreeBSD might report ECONNRESET on socketpair() sockets).
SOCK_SEQPACKET allows 0-byte datagrams, but won't differentiate 0-sized datagrams from EOF.
On MacOS, I use AF_UNIX+SOCK_DGRAM, but then depending on the project I have to add completely voluntary (code becomes less robust) messages to artificially signal EOF: https://gitlab.com/emilua/emilua/-/commit/a245629fa374c7fdf839f911c5f597e4cea6e949
I vaguely recall that Linux was uncommon in allowing multiple FDs to be passed in one message, specifically that the BSDs did not support such behaviour. I guess given the other fixed BSD bug, that that limitation was removed from t he BSDs.