Thread (1 message) 1 message, 1 author, 2016-06-15

Re: RLIMIT_NOFILE fallback

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:59:29

Junio C Hamano [off-list ref] writes:
Jeff King [off-list ref] writes:
quoted
That is, does sysconf actually work on such a system (or does it need a
similar run-time fallback)? And either way, we should try falling back
to OPEN_MAX rather than 1 if we have it.
Interesting.
quoted
As far as the warning, I am not sure I see a point. The user does not
have any useful recourse, and git should continue to operate as normal.
Having every single git invocation print "by the way, RLIMIT_NOFILE does
not work on your system" seems like it would get annoying.
Very true.  That makes the resulting function look like this:


-------------------------------- 8< ------------------------------

static unsigned int get_max_fd_limit(void)
{
#ifdef RLIMIT_NOFILE
	struct rlimit lim;

	if (!getrlimit(RLIMIT_NOFILE, &lim))
		return lim.rlim_cur;
#endif

#if defined(_SC_OPEN_MAX)
	{
		long sc_open_max = sysconf(_SC_OPEN_MAX);
		if (0 < sc_open_max)
			return sc_open_max;
	}
err, here we need

#endif /* defined(_SC_OPEN_MAX) */

to truly implement the structure "try all the available functions,
and then fall back to OPEN_MAX".


#if defined(OPEN_MAX)
	return OPEN_MAX;
#else
	return 1; /* see the caller ;-) */
#endif
}

-------------------------------- >8 ------------------------------


But the sysconf part makes me wonder; here is what we see in
http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html

    If name is an invalid value, sysconf() shall return -1 and set errno
    to indicate the error. If the variable corresponding to name is
    described in <limits.h> as a maximum or minimum value and the
    variable has no limit, sysconf() shall return -1 without changing
    the value of errno. Note that indefinite limits do not imply
    infinite limits; see <limits.h>.

For a broken system (like RLIMIT_NOFILE defined for the compiler,
but the actual call returns a bogus error), the compiler may see the
_SC_OPEN_MAX defined, while sysconf() may say "I've never heard of
such a name" and return -1, or the system, whether broken or not,
may want to say "Unlimited" and return -1.  The caller takes
anything unreasonable as a positive value capped to 25 or something,
so there isn't a real harm if we returned a bogus value from here,
but I am not sure what the safe default behaviour of this function
should be to help such a broken system while not harming systems
that are functioning correctly.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help