Skip to content

Commit

Permalink
git: Try a bit harder not to lose errno in stdio
Browse files Browse the repository at this point in the history
This switches the checks around upon the exit codepath of the
git wrapper, so that we may recover at least non-transient errors.

It's still not perfect. As I've been harping on, stdio simply isn't very
good for error reporting. For example, if an IO error happened, you'd want
to see EIO, wouldn't you? And yes, that's what the kernel would return.
However, with buffered stdio (and flushing outside of our control), what
would likely happen is that some intermediate error return _does_ return
EIO, but then the kernel might decide to re-mount the filesystem read-only
due to the error, and the actual *report* for us might be

	"write failure on standard output: read-only filesystem"

which lost the EIO.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Jun 30, 2007
1 parent 39741ab commit 0227f98
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions git.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,12 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv)
return 0;

/* Check for ENOSPC and EIO errors.. */
if (ferror(stdout))
die("write failure on standard output");
if (fflush(stdout) || fclose(stdout))
if (fflush(stdout))
die("write failure on standard output: %s", strerror(errno));

if (ferror(stdout))
die("unknown write failure on standard output");
if (fclose(stdout))
die("close failed on standard output: %s", strerror(errno));
return 0;
}

Expand Down

0 comments on commit 0227f98

Please sign in to comment.