From ecc54f900fa6aaf1b97ef85b1101cf7badf33cec Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 14 May 2007 00:57:48 +0000 Subject: r22830: merged the latest lib/events updates from ctdb to Samba4. This includes a new EVENT_FD_AUTOCLOSE flag that prevents race conditions where code using fd events might close a fd before releasing the struct fd_event. That causes headaches for epoll. (This used to be commit f1ad216de13b154a1f8747a44b0970dcc47a784a) --- source4/lib/events/events_standard.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'source4/lib/events/events_standard.c') diff --git a/source4/lib/events/events_standard.c b/source4/lib/events/events_standard.c index dcf890ac12..799b19813a 100644 --- a/source4/lib/events/events_standard.c +++ b/source4/lib/events/events_standard.c @@ -30,7 +30,7 @@ #include "includes.h" #include "system/filesys.h" -#include "system/select.h" /* needed for WITH_EPOLL */ +#include "system/select.h" /* needed for HAVE_EVENTS_EPOLL */ #include "lib/util/dlinklist.h" #include "lib/events/events.h" #include "lib/events/events_internal.h" @@ -61,7 +61,7 @@ struct std_event_context { }; /* use epoll if it is available */ -#if WITH_EPOLL +#if HAVE_EVENTS_EPOLL /* called when a epoll call fails, and we should fallback to using select @@ -229,15 +229,15 @@ static int epoll_event_loop(struct std_event_context *std_ev, struct timeval *tv timeout = ((tvalp->tv_usec+999) / 1000) + (tvalp->tv_sec*1000); } - if (epoll_ev->ev->num_signal_handlers && - common_event_check_signal(epoll_ev->ev)) { + if (std_ev->ev->num_signal_handlers && + common_event_check_signal(std_ev->ev)) { return 0; } ret = epoll_wait(std_ev->epoll_fd, events, MAXEVENTS, timeout); - if (ret == -1 && errno == EINTR && epoll_ev->ev->num_signal_handlers) { - if (common_event_check_signal(epoll_ev->ev)) { + if (ret == -1 && errno == EINTR && std_ev->ev->num_signal_handlers) { + if (common_event_check_signal(std_ev->ev)) { return 0; } } @@ -353,6 +353,11 @@ static int std_event_fd_destructor(struct fd_event *fde) epoll_del_event(std_ev, fde); + if (fde->flags & EVENT_FD_AUTOCLOSE) { + close(fde->fd); + fde->fd = -1; + } + return 0; } -- cgit