[sane-devel] [PATCH] Do not accidentally close STDIN/STDOUT/STDERR

Nick Andrew nick at nick-andrew.net
Mon Aug 4 04:24:44 UTC 2008

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()
> > will cause that file descriptor to be closed, which is not
> > wanted.
> There is no reason why this would happen, so unless you've seen that
> actually happening...

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 because one of the file
descriptors will end up closed by accident. My patch merely ensures
that the code delivers what was intended by the author.

PGP Key ID = 0x418487E7                      http://www.nick-andrew.net/
PGP Key fingerprint = B3ED 6894 8E49 1770 C24A  67E3 6266 6EB9 4184 87E7

More information about the sane-devel mailing list