0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-31 01:43:02 +08:00

sockets created by accept are leaked to child processes (ticket #956)

This commit is contained in:
Jan Kryl 2014-04-02 12:25:40 -04:00
parent 55bde2a7b5
commit 48b37f217f
2 changed files with 14 additions and 0 deletions

View File

@ -280,6 +280,13 @@ zmq::fd_t zmq::ipc_listener_t::accept ()
return retired_fd; return retired_fd;
} }
// Race condition can cause socket not to be closed (if fork happens
// between accept and this point).
#ifdef FD_CLOEXEC
int rc = fcntl (sock, F_SETFD, FD_CLOEXEC);
errno_assert (rc != -1);
#endif
// IPC accept() filters // IPC accept() filters
#if defined ZMQ_HAVE_SO_PEERCRED || defined ZMQ_HAVE_LOCAL_PEERCRED #if defined ZMQ_HAVE_SO_PEERCRED || defined ZMQ_HAVE_LOCAL_PEERCRED
if (!filter (sock)) { if (!filter (sock)) {

View File

@ -288,6 +288,13 @@ zmq::fd_t zmq::tcp_listener_t::accept ()
} }
#endif #endif
// Race condition can cause socket not to be closed (if fork happens
// between accept and this point).
#ifdef FD_CLOEXEC
int rc = fcntl (sock, F_SETFD, FD_CLOEXEC);
errno_assert (rc != -1);
#endif
if (!options.tcp_accept_filters.empty ()) { if (!options.tcp_accept_filters.empty ()) {
bool matched = false; bool matched = false;
for (options_t::tcp_accept_filters_t::size_type i = 0; i != options.tcp_accept_filters.size (); ++i) { for (options_t::tcp_accept_filters_t::size_type i = 0; i != options.tcp_accept_filters.size (); ++i) {