From: Johannes Sixt <j.sixt@viscovery.net>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH 2/2] Work around EMFILE when there are too many pack files
Date: Tue, 02 Nov 2010 09:44:58 +0100 [thread overview]
Message-ID: <4CCFCF8A.20608@viscovery.net> (raw)
In-Reply-To: <1288652061-19614-3-git-send-email-spearce@spearce.org>
Am 11/1/2010 23:54, schrieb Shawn O. Pearce:
> -static int git_open_noatime(const char *name)
> +static int git_open_noatime(const char *name, struct packed_git *p)
> {
> static int sha1_file_open_flag = O_NOATIME;
> - int fd = open(name, O_RDONLY | sha1_file_open_flag);
>
> - /* Might the failure be due to O_NOATIME? */
> - if (fd < 0 && errno != ENOENT && sha1_file_open_flag) {
> - fd = open(name, O_RDONLY);
> + for (;;) {
> + int fd = open(name, O_RDONLY | sha1_file_open_flag);
> if (fd >= 0)
> + return fd;
> +
> + /* Might the failure be insufficient file descriptors? */
> + if (errno == EMFILE) {
> + if (unuse_one_window(p, -1))
> + continue;
> + else
> + return -1;
> + }
> +
> + /* Might the failure be due to O_NOATIME? */
> + if (errno != ENOENT && sha1_file_open_flag) {
> sha1_file_open_flag = 0;
> + continue;
> + }
> +
> + return -1;
> }
> - return fd;
> }
Oh, boy! A function that returns a value, but does not have a return
statement at the end? Even a goto would be easier to read:
retry:
fd = open(name, O_RDONLY | sha1_file_open_flag);
if (fd >= 0)
return fd;
if (errno == EMFILE) {
if (unuse_one_window(p, -1))
goto retry;
return -1;
}
if (errno != ENOENT && sha1_file_open_flag) {
sha1_file_open_flag = 0;
goto retry;
}
return -1;
IMHO, of course.
-- Hannes
next prev parent reply other threads:[~2010-11-02 8:45 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-01 22:54 [PATCH 0/2] Work around too many file descriptors Shawn O. Pearce
2010-11-01 22:54 ` [PATCH 1/2] Use git_open_noatime when accessing pack data Shawn O. Pearce
2010-11-03 17:07 ` Junio C Hamano
2010-11-03 17:41 ` Jonathan Nieder
2010-11-03 19:35 ` Junio C Hamano
2010-11-04 5:04 ` Jonathan Nieder
2010-11-04 5:23 ` Kevin Ballard
2010-11-05 17:26 ` Junio C Hamano
2010-11-01 22:54 ` [PATCH 2/2] Work around EMFILE when there are too many pack files Shawn O. Pearce
2010-11-02 8:44 ` Johannes Sixt [this message]
2010-11-03 17:06 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4CCFCF8A.20608@viscovery.net \
--to=j.sixt@viscovery.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).