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 18, 2013, 18:00 UTC
Message-ID
<xmqqy53ihwe4.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20131218171446.GA19657@kitenet.net>
Joey Hess <joey@kitenet.net> writes:
Show 10 quoted lines
> In sha1_file.c, when git is built on linux, it will use 
> getrlimit(RLIMIT_NOFILE). I've been deploying git binaries to some
> unusual systems, like embedded NAS devices, and it seems some with older
> kernels like 2.6.33 fail with "fatal: cannot get RLIMIT_NOFILE: Bad address".
>
> I could work around this by building git without RLIMIT_NOFILE defined,
> but perhaps it would make sense to improve the code to fall back
> to one of the other methods for getting the limit, and/or return the
> hardcoded 1 as a fallback. This would make git binaries more robust
> against old/broken/misconfigured kernels.
Hmph, perhaps you are right.  Like this?
 sha1_file.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index daacc0c..a3a0014 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -809,8 +809,12 @@ static unsigned int get_max_fd_limit(void)
 #ifdef RLIMIT_NOFILE
 	struct rlimit lim;
 
-	if (getrlimit(RLIMIT_NOFILE, &lim))
-		die_errno("cannot get RLIMIT_NOFILE");
+	if (getrlimit(RLIMIT_NOFILE, &lim)) {
+		static int warn_only_once;
+		if (!warn_only_once++)
+			warning("cannot get RLIMIT_NOFILE: %s", strerror(errno));
+		return 1; /* see the caller ;-) */
+	}
 
 	return lim.rlim_cur;
 #elif defined(_SC_OPEN_MAX)
Previous: Joey HessNext: Joey Hess
Message 2 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.