Linux: create sockets with close-on-exec flag in thread-safe manner
There is a window of opportunity to leak file descriptors between their creation and the fcntl(FD_CLOEXEC) call. If another thread forks during this window, the descriptors will not have a the close-on-exec flag, and get leaked after exec(). This is a limitation of POSIX. While we're using the Linux-specific SOCK_CLOEXEC, we might as well use SOCK_NONBLOCK, and spare ourselves the three fcntl() calls.
Showing
Please register or sign in to comment