diff options
author | ache <ache@FreeBSD.org> | 2014-08-06 10:38:06 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2014-08-06 10:38:06 +0000 |
commit | da0a5df9dc8554eee90ceed7c5c9f42c593adc85 (patch) | |
tree | 25662667de2be50242b53785aaa7c78a73762768 /lib/libc | |
parent | 2d3901a5e0f5f2c82219f95729476541cf7a6c59 (diff) | |
download | FreeBSD-src-da0a5df9dc8554eee90ceed7c5c9f42c593adc85.zip FreeBSD-src-da0a5df9dc8554eee90ceed7c5c9f42c593adc85.tar.gz |
MFC: r269116
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@
Diffstat (limited to 'lib/libc')
-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 b3a07d9..bf3f030 100644 --- a/lib/libc/stdio/freopen.c +++ b/lib/libc/stdio/freopen.c @@ -150,6 +150,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: |