From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12225 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: bug with sysconf(_SC_CHILD_MAX) with user process ulimit set to unlimited Date: Thu, 7 Dec 2017 12:05:40 -0500 Message-ID: <20171207170540.GY1627@brightrain.aerifal.cx> References: <20171207162609.45e02f83@ncopa-desktop.copa.dup.pw> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1512666352 14964 195.159.176.226 (7 Dec 2017 17:05:52 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 7 Dec 2017 17:05:52 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-12241-gllmg-musl=m.gmane.org@lists.openwall.com Thu Dec 07 18:05:48 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1eMzcK-0003mh-0G for gllmg-musl@m.gmane.org; Thu, 07 Dec 2017 18:05:48 +0100 Original-Received: (qmail 23734 invoked by uid 550); 7 Dec 2017 17:05:53 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 23716 invoked from network); 7 Dec 2017 17:05:52 -0000 Content-Disposition: inline In-Reply-To: <20171207162609.45e02f83@ncopa-desktop.copa.dup.pw> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:12225 Archived-At: On Thu, Dec 07, 2017 at 04:26:09PM +0100, Natanael Copa wrote: > Hi, > > While trying to debug why `bash -c 'sleep 1 & wait $!'` hangs with > alpine in docker[1] I made an interesting discovery. > > Set user process ulimit to "unlimited" and run the following program on > an x86_64 machine: > > #include > #include > > int main() { > long maxchild = sysconf(_SC_CHILD_MAX); > printf("maxchild: %ld\n", maxchild); > return 0; > } > > > With musl libc it prints: > > maxchild: 9223372036854775807 > > With glibc it prints: > > maxchild: -1 > > > Setting the process ulimit to something like 64k makes bash work again. > > Shouldn't sysconf(_SC_CHILD_MAX) return -1 if ulimit is set to > "unlimited"? > > Thanks! > > -nc > > > [1]: https://github.com/tianon/docker-bash/issues/4 Yes, I think you're completely right. But this is also a bug in bash; its loop to "round up to a power of two" is using the wrong type and results in an infinite loop whenever the process limit it sees is huge: http://git.savannah.gnu.org/cgit/bash.git/tree/jobs.c#n768 I'll make sure the patch works right and then commit your fix. Rich