closefds 0.1.0

Functionality to set FD_CLOEXEC flag on file descriptors after fork and before exec
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 26.2 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 912.36 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • DaGenix

closefds

closefds is a library that provides support for setting the FD_CLOEXEC flag on all open file descriptors after fork() and before exec() on UNIX-like systems.

Any file descriptors that aren't marked with this flag will stay open after exec() which can cause resources to leak and can lead to deadlocks. Ideally, whenever a file descriptor is created, it will be created with the FD_CLOEXEC flag already set. However, this may not be possible in some circumstances - such as when using an external library or a system call that does not support the FD_CLOEXEC flag, such as pipe().

The function close_fds_on_exec() will create a closure that can be passed as a pre_exec() function when spawning a child process via the Command interface and will set the FD_CLOEXEC flag as appropriate on open file descriptors.