From owner-svn-src-stable-10@FreeBSD.ORG Wed Aug 6 10:38:07 2014 Return-Path: Delivered-To: svn-src-stable-10@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 02143F4D for ; Wed, 6 Aug 2014 10:38:07 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C6387248E for ; Wed, 6 Aug 2014 10:38:06 +0000 (UTC) Received: from ache (uid 542) (envelope-from ache@FreeBSD.org) id 5e19 by svn.freebsd.org (DragonFly Mail Agent v0.9+); Wed, 06 Aug 2014 10:38:06 +0000 From: Andrey A. Chernov Date: Wed, 6 Aug 2014 10:38:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r269624 - stable/10/lib/libc/stdio X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <53e2058e.5e19.1980309a@svn.freebsd.org> X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Aug 2014 10:38:07 -0000 Author: ache Date: Wed Aug 6 10:38:06 2014 New Revision: 269624 URL: http://svnweb.freebsd.org/changeset/base/269624 Log: 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@ Modified: stable/10/lib/libc/stdio/freopen.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/stdio/freopen.c ============================================================================== --- stable/10/lib/libc/stdio/freopen.c Wed Aug 6 10:33:43 2014 (r269623) +++ stable/10/lib/libc/stdio/freopen.c Wed Aug 6 10:38:06 2014 (r269624) @@ -150,6 +150,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: