diff options
author | Sumit Bose <sbose@redhat.com> | 2011-08-11 12:30:48 +0200 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2011-08-11 14:38:53 -0400 |
commit | 158b208dfd75c04698f9f9196161322b16a020a2 (patch) | |
tree | a81837ad3fe0d4c707e16c080f782b0ca441b576 /lib/tevent/tevent_epoll.c | |
parent | d52343a9673a55e0e11d35f904808c0007405fa4 (diff) | |
download | samba-158b208dfd75c04698f9f9196161322b16a020a2.tar.gz samba-158b208dfd75c04698f9f9196161322b16a020a2.tar.bz2 samba-158b208dfd75c04698f9f9196161322b16a020a2.zip |
tevent: Set FD_CLOEXEC on epoll handle
If an application using libtevent starts a new process the epoll file descriptor
is leaked to the new process if the event context is not freed explicitly. By
setting FD_CLOEXEC this is not needed anymore.
Signed-off-by: Simo Sorce <idra@samba.org>
Diffstat (limited to 'lib/tevent/tevent_epoll.c')
-rw-r--r-- | lib/tevent/tevent_epoll.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/tevent/tevent_epoll.c b/lib/tevent/tevent_epoll.c index 3ab8283955..33e1d3f20f 100644 --- a/lib/tevent/tevent_epoll.c +++ b/lib/tevent/tevent_epoll.c @@ -78,11 +78,20 @@ static int epoll_ctx_destructor(struct epoll_event_context *epoll_ev) static int epoll_init_ctx(struct epoll_event_context *epoll_ev) { epoll_ev->epoll_fd = epoll_create(64); - epoll_ev->pid = getpid(); - talloc_set_destructor(epoll_ev, epoll_ctx_destructor); if (epoll_ev->epoll_fd == -1) { + tevent_debug(epoll_ev->ev, TEVENT_DEBUG_FATAL, + "Failed to create epoll handle.\n"); return -1; } + + if (!ev_set_close_on_exec(epoll_ev->epoll_fd)) { + tevent_debug(epoll_ev->ev, TEVENT_DEBUG_WARNING, + "Failed to set close-on-exec, file descriptor may be leaked to children.\n"); + } + + epoll_ev->pid = getpid(); + talloc_set_destructor(epoll_ev, epoll_ctx_destructor); + return 0; } @@ -108,6 +117,12 @@ static void epoll_check_reopen(struct epoll_event_context *epoll_ev) "Failed to recreate epoll handle after fork\n"); return; } + + if (!ev_set_close_on_exec(epoll_ev->epoll_fd)) { + tevent_debug(epoll_ev->ev, TEVENT_DEBUG_WARNING, + "Failed to set close-on-exec, file descriptor may be leaked to children.\n"); + } + epoll_ev->pid = getpid(); for (fde=epoll_ev->ev->fd_events;fde;fde=fde->next) { epoll_add_event(epoll_ev, fde); |