On Fri, Aug 01, 2008 at 11:08:34AM +0200, Julien BLACHE wrote:
Nick Andrew nick at nick-andrew.net wrote:
When /dev/null is opened it gets the lowest numbered unopened
file descriptor. If any of the file descriptors 0, 1 or 2 are
closed when the program starts running, the later close()
Nick Andrew nick at nick-andrew.net wrote:
Hi,
It's just basic defensive programming. The intent of saned is
obviously to sanitise file descriptors 0, 1 and 2 by opening them
all to /dev/null; if any of those file descriptors weren't open at
program start then the sanitising will fail
Do not accidentally close STDIN/STDOUT/STDERR
When /dev/null is opened it gets the lowest numbered unopened
file descriptor. If any of the file descriptors 0, 1 or 2 are
closed when the program starts running, the later close()
will cause that file descriptor to be closed, which is not
wanted.