Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent FD leakage when calling fork(2)+exec(2) #558

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Prevent FD leakage when calling fork(2)+exec(2) #558

wants to merge 4 commits into from

Commits on Nov 6, 2017

  1. Configuration menu
    Copy the full SHA
    8ba8a6d View commit details
    Browse the repository at this point in the history
  2. Allow setting CLOEXEC on socket creation

    In order to prevent file descriptor leakage when calling fork(2)+exec(2), the FD_CLOEXEC flag needs to be set. Just setting the flag using fcntl(2) after socket creation is, however, not enough, since, in a multi-threaded application, another thread might fork after we created the socket but before we had the chance of setting the flag. To remedy this, Linux introduced the SOCK_CLOEXEC flag in 2.6.27, to be set on socket creation. At the time of this commit, it has been ported to other systems, such as FreeBSD. Should the flag not be available, as is the case in macOS or older versions of the Linux kernel, we do the next best thing, which is trying to call fcntl(2) right after socket creation.
    feliperuiz committed Nov 6, 2017
    Configuration menu
    Copy the full SHA
    38ff0fa View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    a4439da View commit details
    Browse the repository at this point in the history
  4. Refactor tests using lsof

    MacOS doesn't have procfs, which is what we were using for testing.
    feliperuiz committed Nov 6, 2017
    Configuration menu
    Copy the full SHA
    c512b7d View commit details
    Browse the repository at this point in the history