mailing list of musl libc
 help / color / mirror / code / Atom feed
* bug with sysconf(_SC_CHILD_MAX) with user process ulimit set to unlimited
@ 2017-12-07 15:26 Natanael Copa
  2017-12-07 17:05 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Natanael Copa @ 2017-12-07 15:26 UTC (permalink / raw)
  To: musl

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 <stdio.h>
#include <unistd.h>

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: bug with sysconf(_SC_CHILD_MAX) with user process ulimit set to unlimited
  2017-12-07 15:26 bug with sysconf(_SC_CHILD_MAX) with user process ulimit set to unlimited Natanael Copa
@ 2017-12-07 17:05 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2017-12-07 17:05 UTC (permalink / raw)
  To: musl

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 <stdio.h>
> #include <unistd.h>
> 
> 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-12-07 17:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-07 15:26 bug with sysconf(_SC_CHILD_MAX) with user process ulimit set to unlimited Natanael Copa
2017-12-07 17:05 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).