diff options
author | Volker Lendecke <vl@samba.org> | 2021-01-21 18:33:58 +0100 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2021-03-19 08:18:26 +0000 |
commit | cf0c773ca56e0ae1b3123997d7910e0e0e248184 (patch) | |
tree | a9cb038f272ee0cc9c8df6b90fd0d2780f865483 /lib/messaging | |
parent | 72540222c2290dc041fb01018de7febe44a4ac0d (diff) | |
download | samba-cf0c773ca56e0ae1b3123997d7910e0e0e248184.tar.gz |
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
Diffstat (limited to 'lib/messaging')
-rw-r--r-- | lib/messaging/messages_dgm.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/messaging/messages_dgm.c b/lib/messaging/messages_dgm.c index 733cd19d3b8..ef065def4d9 100644 --- a/lib/messaging/messages_dgm.c +++ b/lib/messaging/messages_dgm.c @@ -1323,6 +1323,18 @@ static int messaging_dgm_in_msg_destructor(struct messaging_dgm_in_msg *m) return 0; } +static void messaging_dgm_close_unconsumed(int *fds, size_t num_fds) +{ + size_t i; + + for (i=0; i<num_fds; i++) { + if (fds[i] != -1) { + close(fds[i]); + fds[i] = -1; + } + } +} + /* * Deal with identification of fragmented messages and * re-assembly into full messages sent, then calls the @@ -1349,6 +1361,7 @@ static void messaging_dgm_recv(struct messaging_dgm_context *ctx, if (cookie == 0) { ctx->recv_cb(ev, buf, buflen, fds, num_fds, ctx->recv_cb_private_data); + messaging_dgm_close_unconsumed(fds, num_fds); return; } @@ -1412,6 +1425,7 @@ static void messaging_dgm_recv(struct messaging_dgm_context *ctx, ctx->recv_cb(ev, msg->buf, msg->msglen, fds, num_fds, ctx->recv_cb_private_data); + messaging_dgm_close_unconsumed(fds, num_fds); TALLOC_FREE(msg); return; |