Problem: eventfd leaks socket on fork+exec

Solution: if available, use eventfd with EFD_CLOEXEC flag to make
the process close the socket on fork+exec
This commit is contained in:
Luca Boccassi
2016-12-26 18:18:00 +01:00
parent 211898d243
commit f287c7a2aa
6 changed files with 58 additions and 3 deletions

View File

@@ -381,7 +381,14 @@ void zmq::signaler_t::forked ()
int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_)
{
#if defined ZMQ_HAVE_EVENTFD
fd_t fd = eventfd (0, 0);
int flags = 0;
#if defined ZMQ_HAVE_EVENTFD_CLOEXEC
// Setting this option result in sane behaviour when exec() functions
// are used. Old sockets are closed and don't block TCP ports, avoid
// leaks, etc.
flags |= EFD_CLOEXEC;
#endif
fd_t fd = eventfd (0, flags);
if (fd == -1) {
errno_assert (errno == ENFILE || errno == EMFILE);
*w_ = *r_ = -1;