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

Re: [PATCH 2/2] A loose object is not corrupt if it cannot be read due to EMFILE

From
CDCasey Dahlin <cdahlin@redhat.com>
Date
Nov 18, 2010, 18:23 UTC
Message-ID
<20101118182358.GQ355@fearengine.rdu.redhat.com>
In-Reply-To
<AANLkTi=rrcc5tia03K-Rtqs3vyjOv9P1NArnmbYhCQ27@mail.gmail.com>
On Thu, Nov 18, 2010 at 07:18:37PM +0100, Erik Faye-Lund wrote:
Show 28 quoted lines
> On Thu, Nov 18, 2010 at 6:29 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> > Erik Faye-Lund wrote:
> >
> >> I was wondering about the same thing, I don't think this approach is
> >> very easy to follow. But either way I think we should make sure
> >> opendir/closedir/readdir doesn't mess with errno.
> >
> > Other platforms and are allowed to (and do) clobber errno in many
> > non-error situations, so the main effect would be to work around/hide
> > some git bugs.
> 
> I don't think that's the case; K&R (section B1.7) says "In addition,
> the integer expression errno (declared in <errno.h>) may contain an
> error number that contains information about the most recent error.".
> A non-error condition would not be information about the most recent
> error. I interpret the use of the word "may" to mean "some functions
> does not update errno, so errno could also have information about
> older errors" not as "some functions can clear errno", but other might
> disagree with me.
> 
> POSIX (which defines opendir) says "No function in this volume of IEEE
> Std 1003.1-2001 shall set errno to 0", so I think it's clear cut in
> this case. (see
> http://www.opengroup.org/onlinepubs/009695399/functions/errno.html for
> the full text)
> 
> We also seem to depend quite heavily on errno being preserved on
> non-errors some places around in the code.

Errno can be clobbered if some subset of the operation in question failed but the operation itself succeeded. For example suppose opendir did a memory allocation that failed, but was able to recover from it and return successfully. Errno might contain ENOMEM at the exit.

tl;dr - errno can be clobbered when functions that succeed call functions that fail while progressing.

--CJD
Previous: Erik Faye-LundNext: Jonathan Nieder
Message 8 of 10 in “read_sha1_file(): report correct name of packfile with a corrupt object”
  1. 1/2 read_sha1_file(): report correct name of packfile with a corrupt objectJunio C Hamano, Oct 28, 2010
  2. 2/2 A loose object is not corrupt if it cannot be read due to EMFILEJunio C Hamano, Oct 28, 2010
  3. Erik Faye-LundNov 18, 2010
  4. Johannes SixtNov 18, 2010
  5. Erik Faye-LundNov 18, 2010
  6. Jonathan NiederNov 18, 2010
  7. Erik Faye-LundNov 18, 2010
  8. Casey DahlinNov 18, 2010
  9. Jonathan NiederNov 18, 2010
  10. Johannes SixtOct 29, 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.