On Sun, Aug 8, 2021 at 10:13 AM mid <midsm...@protonmail.com> wrote:
...

> I have tried sending the file descriptors associated with the connection
> to process B via sendmsg, thinking that maybe the
> file descriptors are reference-counted. It's a logical
> assumption, but it didn't work - the connection closed with
> process A.
>

File descriptors sent via sendmsg() on a unix domain socket of SCM_RIGHTS
control messages *are* reference-counted.

If you think you've done that and it's not behaving as expected, then first
check and report errors on *all* the system calls, and that the returned
data fields on things like recvmsg() have the values you expect.  If
sendmsg() is failing or you're accidentally discarding the fds in the
recvmsg() by not providing the space needed then yeah, the fds will be
closed because the last reference is gone.

If you're 100% sure you have it right, then it should be easy to provide a
program that demonstrates
1) passing an fd between processes
2) using it *successfully* in the receiving process
3) the sending process exiting
3) attempts to us it failing the receiving process

No?


Philip

(Replies not on the list will be deleted)

Reply via email to