tevent: revalidate fde->flags after poll()
authorStefan Metzmacher <metze@samba.org>
Fri, 1 Mar 2013 15:43:35 +0000 (16:43 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 1 Mar 2013 19:59:54 +0000 (11:59 -0800)
This is important to avoid races between threads if the poll_mt
backend is used.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/tevent/tevent_poll.c

index 867d951ee1b1bcee2e35e503501d31d37ad2713e..aa4c50c0c5ec39651d4eea2224d2043ad325ce45 100644 (file)
@@ -594,6 +594,12 @@ static int poll_event_loop_poll(struct tevent_context *ev,
                if (pfd->revents & POLLOUT) {
                        flags |= TEVENT_FD_WRITE;
                }
+               /*
+                * Note that fde->flags could be changed when using
+                * the poll_mt backend together with threads,
+                * that why we need to check pfd->revents and fde->flags
+                */
+               flags &= fde->flags;
                if (flags != 0) {
                        fde->handler(ev, fde, flags, fde->private_data);
                        return 0;