summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2007-06-24 17:29:33 (GMT)
committerJunio C Hamano <gitster@pobox.com>2007-06-25 05:56:40 (GMT)
commit0f157315a1020fce76fe2c5a703e40684b9b1699 (patch)
tree1ca26e03dee85ce03e56b35a18e66f2c87e511a3 /git.c
parent47d0b4ff57f391786ed050f38c0de51462eda97a (diff)
downloadgit-0f157315a1020fce76fe2c5a703e40684b9b1699.zip
git-0f157315a1020fce76fe2c5a703e40684b9b1699.tar.gz
git-0f157315a1020fce76fe2c5a703e40684b9b1699.tar.bz2
Check for IO errors after running a command
This is trying to implement the strict IO error checks that Jim Meyering suggested, but explicitly limits it to just regular files. If a pipe gets closed on us, we shouldn't complain about it. If the subcommand already returned an error, that takes precedence (and we assume that the subcommand already printed out any relevant messages relating to it) Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git.c')
-rw-r--r--git.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/git.c b/git.c
index 911fd3d..c65e52f 100644
--- a/git.c
+++ b/git.c
@@ -224,6 +224,8 @@ struct cmd_struct {
static int run_command(struct cmd_struct *p, int argc, const char **argv)
{
+ int status;
+ struct stat st;
const char *prefix;
prefix = NULL;
@@ -237,7 +239,24 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv)
}
trace_argv_printf(argv, argc, "trace: built-in: git");
- return p->fn(argc, argv, prefix);
+ status = p->fn(argc, argv, prefix);
+ if (status)
+ return status;
+
+ /* Somebody closed stdout? */
+ if (fstat(fileno(stdout), &st))
+ return 0;
+ /* Ignore write errors for pipes and sockets.. */
+ if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode))
+ return 0;
+
+ /* Check for ENOSPC and EIO errors.. */
+ if (ferror(stdout))
+ die("write failure on standard output");
+ if (fflush(stdout) || fclose(stdout))
+ die("write failure on standard output: %s", strerror(errno));
+
+ return 0;
}
static void handle_internal_command(int argc, const char **argv)