Background:
As written in
|
close_fds :: Bool, -- ^ Close all file descriptors except stdin, stdout and stderr in the new process (on Windows, only works if std_in, std_out, and std_err are all Inherit). This implementation will call close an every fd from 3 to the maximum of open files, which can be slow for high maximum of open files. |
This implementation will call close() an every fd from 3 to the maximum of open files, which can be slow for high maximum of open files.
The new close_range() syscall solves this, closing them all in 1 go. According to the LWN link, it is very fast, and you can give it MAXINT.
The code that needs to be augmented (with CPP):
|
if (close_fds) { |
|
int i; |
|
if (max_fd == 0) { |
|
#if HAVE_SYSCONF |
|
max_fd = sysconf(_SC_OPEN_MAX); |
|
if (max_fd == -1) { |
|
max_fd = 256; |
|
} |
|
#else |
|
max_fd = 256; |
|
#endif |
|
} |
|
// XXX Not the pipe |
|
for (i = 3; i < max_fd; i++) { |
|
if (i != forkCommunicationFds[1]) { |
|
close(i); |
|
} |
|
} |
|
} |
Background:
As written in
process/System/Process/Common.hs
Line 91 in cb1d1a6
The new
close_range()syscall solves this, closing them all in 1 go. According to the LWN link, it is very fast, and you can give itMAXINT.The code that needs to be augmented (with CPP):
process/cbits/posix/runProcess.c
Lines 255 to 273 in cb1d1a6