Date: Sat, 26 Jul 2014 08:41:03 +0000 (UTC) From: "Andrey A. Chernov" <ache@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r269116 - head/lib/libc/stdio Message-ID: <201407260841.s6Q8f3Od091465@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ache Date: Sat Jul 26 08:41:03 2014 New Revision: 269116 URL: http://svnweb.freebsd.org/changeset/base/269116 Log: 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 Modified: head/lib/libc/stdio/freopen.c Modified: head/lib/libc/stdio/freopen.c ============================================================================== --- head/lib/libc/stdio/freopen.c Sat Jul 26 07:40:31 2014 (r269115) +++ head/lib/libc/stdio/freopen.c Sat Jul 26 08:41:03 2014 (r269116) @@ -151,6 +151,14 @@ freopen(const char * __restrict file, co /* 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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201407260841.s6Q8f3Od091465>