#exec #fork #process #spawn #unix

bin+lib closefds

Functionality to set FD_CLOEXEC flag on file descriptors after fork and before exec

1 unstable release

0.1.0 Apr 11, 2019

#14 in #exec

MIT/Apache

12KB
146 lines

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.


lib.rs:

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.

Dependencies

~230KB