summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-01-10 18:32:28 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-01-10 18:32:28 (GMT)
commitc4bccea2d52dd59e0e6200cebba3df2dfcf593ea (patch)
tree4cce819b682f7b058380e13ff67f59867ffdbf09 /sha1_file.c
parent8a334727fc5b2ea0b173ca0af4cfb2209a88139a (diff)
parent491a8dec44e9b91149ef77c77c341e7d41df39be (diff)
downloadgit-c4bccea2d52dd59e0e6200cebba3df2dfcf593ea.zip
git-c4bccea2d52dd59e0e6200cebba3df2dfcf593ea.tar.gz
git-c4bccea2d52dd59e0e6200cebba3df2dfcf593ea.tar.bz2
Merge branch 'jh/rlimit-nofile-fallback'
When we figure out how many file descriptors to allocate for keeping packfiles open, a system with non-working getrlimit() could cause us to die(), but because we make this call only to get a rough estimate of how many is available and we do not even attempt to use up all file descriptors available ourselves, it is nicer to fall back to a reasonable low value rather than dying. * jh/rlimit-nofile-fallback: get_max_fd_limit(): fall back to OPEN_MAX upon getrlimit/sysconf failure
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/sha1_file.c b/sha1_file.c
index ee224e4..a2ff296 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -807,15 +807,38 @@ void free_pack_by_name(const char *pack_name)
static unsigned int get_max_fd_limit(void)
{
#ifdef RLIMIT_NOFILE
- struct rlimit lim;
+ {
+ struct rlimit lim;
- if (getrlimit(RLIMIT_NOFILE, &lim))
- die_errno("cannot get RLIMIT_NOFILE");
+ if (!getrlimit(RLIMIT_NOFILE, &lim))
+ return lim.rlim_cur;
+ }
+#endif
+
+#ifdef _SC_OPEN_MAX
+ {
+ long open_max = sysconf(_SC_OPEN_MAX);
+ if (0 < open_max)
+ return open_max;
+ /*
+ * Otherwise, we got -1 for one of the two
+ * reasons:
+ *
+ * (1) sysconf() did not understand _SC_OPEN_MAX
+ * and signaled an error with -1; or
+ * (2) sysconf() said there is no limit.
+ *
+ * We _could_ clear errno before calling sysconf() to
+ * tell these two cases apart and return a huge number
+ * in the latter case to let the caller cap it to a
+ * value that is not so selfish, but letting the
+ * fallback OPEN_MAX codepath take care of these cases
+ * is a lot simpler.
+ */
+ }
+#endif
- return lim.rlim_cur;
-#elif defined(_SC_OPEN_MAX)
- return sysconf(_SC_OPEN_MAX);
-#elif defined(OPEN_MAX)
+#ifdef OPEN_MAX
return OPEN_MAX;
#else
return 1; /* see the caller ;-) */