Skip to content
/ git Public
forked from git/git

Commit

Permalink
Merge branch 'js/use-sc-open-max' into maint
Browse files Browse the repository at this point in the history
* js/use-sc-open-max:
  sha1_file.c: introduce get_max_fd_limit() helper
  • Loading branch information
gitster committed Sep 11, 2012
2 parents 2332834 + a078826 commit 3119084
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down

0 comments on commit 3119084

Please sign in to comment.