fdopendir: fix bug on MacOS X when low on file descriptors
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 8 Nov 2010 05:58:54 +0000 (21:58 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 9 Nov 2010 04:55:11 +0000 (20:55 -0800)
commitbc2e836273a27da04e43c5ffada54f567aa35980
tree6cbe9d1e0c9a8adbe03eb61059000643dabe3a38
parentf03d479e8f5f234789cde2fd841d16fd4eeda247
fdopendir: fix bug on MacOS X when low on file descriptors

* lib/fdopendir.c (REPLACE_FCHDIR): #define to 0 if not defined.
(fdopendir_with_dup, fd_clone_opendir): Now have extra CWD arg.
All callers changed.
(fdopendir): Invoke save_cwd at the top level, not after using
multiple dup() calls to use up file descriptors.  Then retry
fdopendir_with_dup.  This avoids failure with EMFILE if FD is 1
less than the maximum number of open file descriptors, because
save_cwd fails with errno == EMFILE.  Problem reported by tsteven4
on Mac OS X 10.6.4 for tar 1.24
<http://lists.gnu.org/archive/html/bug-tar/2010-10/msg00084.html>
<http://lists.gnu.org/archive/html/bug-tar/2010-11/msg00000.html>
and for tar 1.25
<http://lists.gnu.org/archive/html/bug-tar/2010-11/msg00038.html>.
ChangeLog
lib/fdopendir.c