git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: RLIMIT_NOFILE fallback

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 19, 2013, 17:39 UTC
Message-ID
<xmqqmwjwg2ok.fsf@gitster.dls.corp.google.com>
In-Reply-To
<52B32D18.80400@web.de>
Torsten Bögershausen <tboegi@web.de> writes:
Show 9 quoted lines
> Thanks for an interesting reading,
> please allow a side question:
> Could it be, that "-1 == unlimited" is Linux specific?
> And therefore not 100% portable ?
>
> And doesn't "unlimited" number of files call for trouble,
> having the risk to starve the machine ?
>
> BTW: cygwin returns 256.

If you look at the caller, you will see that we do cap the value returned from this helper function down to a more reasonable and not so selfish maximum, exactly for the purpose of avoiding the risk of starving other processes.

Show 6 quoted lines
>
> ------------
> http://pubs.opengroup.org/onlinepubs/007908799/xsh/sysconf.html
> RETURN VALUE
>
>     If name is an invalid value, sysconf() returns -1 and sets errno to indicate the error. If the variable corresponding to name is associated with functionality that is not supported by the system, sysconf() returns -1 without changing the value of errno. 

That is a rather dated document. POSIX.1-2013 (look for the URL to the corresponding page in an earlier message from me) has a bit tighter wording than that to clarify the "there is no limit" case.

In addition, the final version Peff and I worked out does not even look at the value of errno, in order not to rely on possibly ambiguous interpretations of negative return values. So I think we are good.

Thanks.
Show 28 quoted lines
> ---------- Mac OS, based on BSD (?): ---------- 
> RETURN VALUES
>      If the call to sysconf() is not successful, -1 is returned and errno is
>      set appropriately.  Otherwise, if the variable is associated with func-
>      tionality that is not supported, -1 is returned and errno is not modi-
>      fied.  Otherwise, the current variable value is returned.
>
> ERRORS
>      The sysconf() function may fail and set errno for any of the errors spec-
>      ified for the library function sysctl(3).  In addition, the following
>      error may be reported:
>
>      [EINVAL]           The value of the name argument is invalid.
> [snip]
>      The sysconf() function first appeared in 4.4BSD.
>
> -----------
> Linux, Debian:
>       OPEN_MAX - _SC_OPEN_MAX
>               The  maximum number of files that a process can have open at any
>               time.  Must not be less than _POSIX_OPEN_MAX (20).
> [snip]
> RETURN VALUE
>        If name is invalid, -1 is returned, and errno is set to EINVAL.  Other‐
>        wise, the value returned is the value of the system resource and  errno
>        is  not  changed.  In the case of options, a positive value is returned
>        if a queried option is available, and -1 if it is not.  In the case  of
>        limits, -1 means that there is no definite limit.
Previous: Torsten BögershausenNext: Jeff King
Message 13 of 16 in “RLIMIT_NOFILE fallback”
  1. Joey HessDec 18, 2013
  2. Junio C HamanoDec 18, 2013
  3. Joey HessDec 18, 2013
  4. Jeff KingDec 18, 2013
  5. Junio C HamanoDec 18, 2013
  6. Junio C HamanoDec 18, 2013
  7. Jeff KingDec 18, 2013
  8. Junio C HamanoDec 18, 2013
  9. Jeff KingDec 18, 2013
  10. Junio C HamanoDec 18, 2013
  11. Jeff KingDec 19, 2013
  12. Torsten BögershausenDec 19, 2013
  13. Junio C HamanoDec 19, 2013
  14. Jeff KingDec 20, 2013
  15. Torsten BögershausenDec 20, 2013
  16. Joey HessDec 18, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.