diff options
author | ache <ache@FreeBSD.org> | 2014-07-26 08:41:03 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2014-07-26 08:41:03 +0000 |
commit | 0a368aceb8a3059aa6d18a982b39d43cd6d3a165 (patch) | |
tree | c43056fe81e5fbc7c4bee9d3d6334089e7ee26c9 /lib | |
parent | a2e36007e36f5ae5cb58959c11b985275d126637 (diff) | |
download | FreeBSD-src-0a368aceb8a3059aa6d18a982b39d43cd6d3a165.zip FreeBSD-src-0a368aceb8a3059aa6d18a982b39d43cd6d3a165.tar.gz |
In the "Too many open files" edge cases don't try to preserve old
number for non-std* descriptors, but close old file and retry.
Obtained from: inspired by Apple's change from pfg@
MFC after: 2 weeks
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/stdio/freopen.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c index 28b54f8..4dcd50f 100644 --- a/lib/libc/stdio/freopen.c +++ b/lib/libc/stdio/freopen.c @@ -151,6 +151,14 @@ freopen(const char * __restrict file, const char * __restrict mode, /* Get a new descriptor to refer to the new file. */ f = _open(file, oflags, DEFFILEMODE); + /* If out of fd's close the old one and try again. */ + if (f < 0 && isopen && wantfd > STDERR_FILENO && + (errno == ENFILE || errno == EMFILE)) { + (void) (*fp->_close)(fp->_cookie); + isopen = 0; + wantfd = -1; + f = _open(file, oflags, DEFFILEMODE); + } sverrno = errno; finish: |