openat: allow return of fd 0
authorEric Blake <ebb9@byu.net>
Sat, 19 Sep 2009 13:12:15 +0000 (07:12 -0600)
committerEric Blake <ebb9@byu.net>
Sat, 19 Sep 2009 14:18:06 +0000 (08:18 -0600)
commit996f76cd71a98365044457d94b0d87454bcd4deb
treee3be327949e601c9a9b153f58272d38c09c7496a
parent112523aea20cc9254b36e0644ca2029b634bfae6
openat: allow return of fd 0

Partially reverts patch fc33350 from 2009-09-02.

* modules/chdir-long (Depends-on): Relax openat-safer to openat.
* modules/save-cwd (Depends-on): Replace fcntl-safer with
unistd-safer.
* lib/chdir-long.c (includes): Replace "fcntl--.h" with
<fcntl.h>; this module does not leak fds.
* lib/openat.c (includes): Do not use "fcntl_safer"; plain openat
must be allowed to return 0, leaving openat_safer to add the
safety.
(openat_permissive): Avoid writing to just-opened fd 2 if
restoring the current directory fails.
* lib/openat-die.c (openat_restore_fail): Add comment.
* lib/save-cwd.c (includes): Make "fcntl--.h" conditional.
(save_cwd): Guarantee safe fd, but without use of open_safer.
* tests/test-openat.c: New test.
* modules/openat-tests (Files, Makefile.am): Distribute and build
new file.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
lib/chdir-long.c
lib/openat-die.c
lib/openat.c
lib/save-cwd.c
modules/chdir-long
modules/openat-tests
modules/save-cwd
tests/test-openat.c [new file with mode: 0644]