aboutsummaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJoachim Schmitz <jojo@schmitz-digital.de>2012-08-24 11:52:22 +0200
committerJunio C Hamano <gitster@pobox.com>2012-08-24 09:46:01 -0700
commita0788266d310dd3f6343c7ee754106784aa1e2af (patch)
tree39439e8905b977aff60f7be8b0f4c7092cb96f2a /sha1_file.c
parentfab4b04e4be5ccfdf93e21e7260040bd9e7faedd (diff)
downloadgit-a0788266d310dd3f6343c7ee754106784aa1e2af.tar.gz
git-a0788266d310dd3f6343c7ee754106784aa1e2af.tar.xz
sha1_file.c: introduce get_max_fd_limit() helper
Not all platforms have getrlimit(), but there are other ways to see the maximum number of files that a process can have open. If getrlimit() is unavailable, fall back to sysconf(_SC_OPEN_MAX) if available, and use OPEN_MAX from <limits.h>. Signed-off-by: Joachim Schmitz <jojo@schmitz-digital.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/sha1_file.c b/sha1_file.c
index af5cfbde6..915297464 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -731,6 +731,24 @@ void free_pack_by_name(const char *pack_name)
}
}
+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");
+
+ return lim.rlim_cur;
+#elif defined(_SC_OPEN_MAX)
+ return sysconf(_SC_OPEN_MAX);
+#elif defined(OPEN_MAX)
+ return OPEN_MAX;
+#else
+ return 1; /* see the caller ;-) */
+#endif
+}
+
/*
* Do not call this directly as this leaks p->pack_fd on error return;
* call open_packed_git() instead.
@@ -747,13 +765,7 @@ static int open_packed_git_1(struct packed_git *p)
return error("packfile %s index unavailable", p->pack_name);
if (!pack_max_fds) {
- struct rlimit lim;
- unsigned int max_fds;
-
- if (getrlimit(RLIMIT_NOFILE, &lim))
- die_errno("cannot get RLIMIT_NOFILE");
-
- max_fds = lim.rlim_cur;
+ unsigned int max_fds = get_max_fd_limit();
/* Save 3 for stdin/stdout/stderr, 22 for work */
if (25 < max_fds)