From: Junio C Hamano <gitster@pobox•com>
To: Jeff King <peff@peff•net>
Cc: Joey Hess <joey@kitenet•net>, git@vger•kernel.org
Subject: Re: RLIMIT_NOFILE fallback
Date: Wed, 18 Dec 2013 11:50:24 -0800 [thread overview]
Message-ID: <xmqq61qmhrb3.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <20131218191702.GA9083@sigill.intra.peff.net> (Jeff King's message of "Wed, 18 Dec 2013 14:17:02 -0500")
Jeff King <peff@peff•net> writes:
> 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.
> 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;
}
#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.
next prev parent reply other threads:[~2013-12-18 19:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-18 17:14 RLIMIT_NOFILE fallback Joey Hess
2013-12-18 18:00 ` Junio C Hamano
2013-12-18 18:41 ` Joey Hess
2013-12-18 19:17 ` Jeff King
2013-12-18 19:50 ` Junio C Hamano [this message]
2013-12-18 20:18 ` Junio C Hamano
2013-12-18 21:28 ` Jeff King
2013-12-18 21:37 ` Junio C Hamano
2013-12-18 21:40 ` Jeff King
2013-12-18 22:59 ` Junio C Hamano
2013-12-19 0:15 ` Jeff King
2013-12-19 17:30 ` Torsten Bögershausen
2013-12-19 17:39 ` Junio C Hamano
2013-12-20 9:12 ` Jeff King
2013-12-20 14:43 ` Torsten Bögershausen
2013-12-18 20:03 ` Joey Hess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq61qmhrb3.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=joey@kitenet$(echo .)net \
--cc=peff@peff$(echo .)net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox