mirror of
https://github.com/NixOS/nix
synced 2025-06-27 00:11:17 +02:00
Set the close-on-exec flag on file descriptors
This commit is contained in:
parent
7b22bec252
commit
35355fc1fc
5 changed files with 20 additions and 3 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <cstring>
|
||||
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
|
||||
|
@ -683,6 +684,8 @@ void Pipe::create()
|
|||
if (pipe(fds) != 0) throw SysError("creating pipe");
|
||||
readSide = fds[0];
|
||||
writeSide = fds[1];
|
||||
closeOnExec(readSide);
|
||||
closeOnExec(writeSide);
|
||||
}
|
||||
|
||||
|
||||
|
@ -934,6 +937,15 @@ void closeMostFDs(const set<int> & exceptions)
|
|||
}
|
||||
|
||||
|
||||
void closeOnExec(int fd)
|
||||
{
|
||||
int prev;
|
||||
if ((prev = fcntl(fd, F_GETFD, 0)) == -1 ||
|
||||
fcntl(fd, F_SETFD, prev | FD_CLOEXEC) == -1)
|
||||
throw SysError("setting close-on-exec flag");
|
||||
}
|
||||
|
||||
|
||||
void quickExit(int status)
|
||||
{
|
||||
_exit(status);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue