From owner-freebsd-hackers@FreeBSD.ORG Wed Nov 19 21:57:03 2014 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9DD1AF23; Wed, 19 Nov 2014 21:57:03 +0000 (UTC) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client CN "mailhost.stack.nl", Issuer "CA Cert Signing Authority" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 60C2DBED; Wed, 19 Nov 2014 21:57:03 +0000 (UTC) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id 61BBA358C68; Wed, 19 Nov 2014 22:57:00 +0100 (CET) Received: by snail.stack.nl (Postfix, from userid 1677) id 5212728494; Wed, 19 Nov 2014 22:57:00 +0100 (CET) Date: Wed, 19 Nov 2014 22:57:00 +0100 From: Jilles Tjoelker To: Ian Lepore Subject: Re: Running 8 building 10 gives "Out of file descriptors" ? Message-ID: <20141119215700.GA42114@stack.nl> References: <1416428288.1147.140.camel@revolution.hippie.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1416428288.1147.140.camel@revolution.hippie.lan> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: freebsd-hackers@freebsd.org, Dieter BSD X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Nov 2014 21:57:03 -0000 On Wed, Nov 19, 2014 at 01:18:08PM -0700, Ian Lepore wrote: > On Wed, 2014-11-19 at 11:07 -0800, Dieter BSD wrote: > > if (fd < 10) { > > fd2 = fcntl(fd, F_DUPFD_CLOEXEC, 10); > > close(fd); > > if (fd2 < 0) > > { > > int limit; > > limit = getdtablesize(); > > fprintf(stderr, "sh: setinputfile(): fcntl() returned %d ge\ > > tdtablesize() returned %d\n", fd2, limit); > > perror("sh: fcntl(F_DUPFD_CLOEXEC) failed:"); > > error("sh: Out of file descriptors?"); > > } > > fd = fd2; > > } > > Result: > > sh: setinputfile(): fcntl() returned -1 getdtablesize() returned 11095 > > sh: fcntl(F_DUPFD_CLOEXEC) failed:: Invalid argument > > sh: Out of file descriptors? > > find /usr/include/ | xargs grep F_DUPFD_CLOEXEC > > gives no hits in 8.2, but > > /usr/include/sys/fcntl.h: > > /new/freebsd/usr/include/fcntl.h: > > #define F_DUPFD_CLOEXEC 17 /* Like F_DUPFD, but FD_CLOEXEC is set */ > > in 10.1 > > So, F_DUPFD_CLOEXEC was added after 8.2, and someone changed sh to > > use it, but couldn't be bothered to fix the error message. > > If someone would like to fix this, they don't need to build a toolchain, > > they can use a 2 line script: > > #!/bin/sh > > echo Hello, World! > > So Ian, how did you avoid running into this problem? > Ohhhh... hmm. That must have been MFC'd to 8-stable after I had updated > my 8.2 to 8.4 (which was quite a while ago, more than a year now I > guess). > I think this means it's no longer possible to bootstrap a system older > than 8.4 in a single step. You'd need to go 8.2 -> 8.4 then install > that and reboot to go forward from there. I'm not sure there's an easy > fix for that, but we could at least update the check in Makefile.inc1 to > stop the build and tell you that you can't bootstrap a system older than > 8.4 (right now the cutoff check is 8.0). > I'm not sure what the project policy is in terms of fixing this (no > matter how hard it may be) versus changing the cutoff warning. I'll > look into it. Updating the check in Makefile.inc1 makes sense. If building from 8.2 is supposed to work, it would make most sense to revert r250267. I don't think making the source a #ifdef mess is worth it, given that using O_CLOEXEC and F_DUPFD_CLOEXEC is only a minor optimization in sh and not a correctness issue like in threaded programs (including libc which may be used from threaded programs). Not being able to use kernel features in sh that were MFC'ed back three stable branches ago makes me sad, though. -- Jilles Tjoelker