git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] Work around EMFILE when there are too many pack files

From
Johannes Sixt <j.sixt@viscovery.net>
Date
Nov 2, 2010, 08:44 UTC
Message-ID
<4CCFCF8A.20608@viscovery.net>
In-Reply-To
<1288652061-19614-3-git-send-email-spearce@spearce.org>
Am 11/1/2010 23:54, schrieb Shawn O. Pearce:
Show 32 quoted lines
> -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
Previous: Shawn O. PearceNext: Junio C Hamano
Message 10 of 11 in “Work around too many file descriptors”
  1. 0/2 Work around too many file descriptorsShawn O. Pearce, Nov 1, 2010
  2. 1/2 Use git_open_noatime when accessing pack dataShawn O. Pearce, Nov 1, 2010
  3. Junio C HamanoNov 3, 2010
  4. Jonathan NiederNov 3, 2010
  5. Junio C HamanoNov 3, 2010
  6. Jonathan NiederNov 4, 2010
  7. Kevin BallardNov 4, 2010
  8. Junio C HamanoNov 5, 2010
  9. 2/2 Work around EMFILE when there are too many pack filesShawn O. Pearce, Nov 1, 2010
  10. Johannes SixtNov 2, 2010
  11. Junio C HamanoNov 3, 2010

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.