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_util.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_util.c')
-rw-r--r-- | lib/tevent/tevent_util.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/tevent/tevent_util.c b/lib/tevent/tevent_util.c index f78cd8f707..16af8f3b90 100644 --- a/lib/tevent/tevent_util.c +++ b/lib/tevent/tevent_util.c @@ -88,3 +88,20 @@ int ev_set_blocking(int fd, bool set) return fcntl( fd, F_SETFL, val); #undef FLAG_TO_SET } + +bool ev_set_close_on_exec(int fd) +{ +#ifdef FD_CLOEXEC + int val; + + val = fcntl(fd, F_GETFD, 0); + if (val >= 0) { + val |= FD_CLOEXEC; + val = fcntl(fd, F_SETFD, val); + if (val != -1) { + return true; + } + } +#endif + return false; +} |