messaging: Fix receiving file descriptors
authorVolker Lendecke <vl@samba.org>
Thu, 21 Jan 2021 17:33:58 +0000 (18:33 +0100)
committerVolker Lendecke <vl@samba.org>
Fri, 19 Mar 2021 08:18:26 +0000 (08:18 +0000)
commitcf0c773ca56e0ae1b3123997d7910e0e0e248184
treea9cb038f272ee0cc9c8df6b90fd0d2780f865483
parent72540222c2290dc041fb01018de7febe44a4ac0d
messaging: Fix receiving file descriptors

Don't close unconsumed file descriptors in messaging_recv_cb(). Via
multiple registrations on different tevent contexts we might call
messaging_recv_cb() multiple times: All but the first tevent context
handled in the loop in msg_dgm_ref_recv() will not see file
descriptors anymore, it will just get a -1, even if the first
reference had no receiver interested in the fds.

Change the API such that consumers can set the file descriptor to -1
if it's consumed. If nobody wanted them, do the close where they were
created via recvmsg, in messages_dgm.c.

If you want multiple handlers to consume the file descriptors, you
should dup() them in the filter function handed to
messaging_filtered_read_send and save the duplicate in your private
data for later consumption.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Fri Mar 19 08:18:26 UTC 2021 on sn-devel-184
lib/messaging/messages_dgm.c
source3/lib/messages.c