git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Don't ignore write failure from git-diff, git-log, etc.
@ 2007-05-26 11:45 Jim Meyering
  2007-05-26 16:18 ` Linus Torvalds
  0 siblings, 1 reply; 29+ messages in thread
From: Jim Meyering @ 2007-05-26 11:45 UTC (permalink / raw)
  To: git

Currently, when git-diff writes to a full device or gets an I/O error,
it fails to detect the write error:

    $ git-diff |wc -c
    3984
    $ git-diff > /dev/full && echo ignored write failure
    ignored write failure

git-log does the same thing:

    $ git-log -n1 > /dev/full && echo ignored write failure
    ignored write failure

Each git command should report such a failure.
Some already do, but with the patch below, they all do, and we
won't have to rely on code in each command's implementation to
perform the right incantation.

    $ ./git-log -n1 > /dev/full
    fatal: write failure on standard output: No space left on device
    [Exit 128]
    $ ./git-diff > /dev/full
    fatal: write failure on standard output: No space left on device
    [Exit 128]

You can demonstrate this with git's own --version output, too:
(but git --help detects the failure without this patch)

    $ ./git --version > /dev/full
    fatal: write failure on standard output: No space left on device
    [Exit 128]

Note that the fcntl test (for whether the fileno may be closed) is
required in order to avoid EBADF upon closing an already-closed stdout,
as would happen for each git command that already closes stdout; I think
update-index was the one I noticed in the failure of t5400, before I
added that test.

Signed-off-by: Jim Meyering <jim@meyering.net>
---
 git.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/git.c b/git.c
index 29b55a1..a7d6515 100644
--- a/git.c
+++ b/git.c
@@ -308,6 +308,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
 	for (i = 0; i < ARRAY_SIZE(commands); i++) {
 		struct cmd_struct *p = commands+i;
 		const char *prefix;
+		int status;
 		if (strcmp(p->cmd, cmd))
 			continue;

@@ -321,7 +322,15 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
 			die("%s must be run in a work tree", cmd);
 		trace_argv_printf(argv, argc, "trace: built-in: git");

-		exit(p->fn(argc, argv, prefix));
+		status = p->fn(argc, argv, prefix);
+
+		/* Close stdout if necessary, and diagnose any failure.  */
+		if (0 <= fcntl(fileno (stdout), F_GETFD)
+		    && (ferror(stdout) || fclose(stdout)))
+			die("write failure on standard output: %s",
+			    strerror(errno));
+
+		exit(status);
 	}
 }

--
1.5.2.73.g18bece

^ permalink raw reply related	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2007-05-30 19:44 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-26 11:45 [PATCH] Don't ignore write failure from git-diff, git-log, etc Jim Meyering
2007-05-26 16:18 ` Linus Torvalds
2007-05-26 17:27   ` Junio C Hamano
2007-05-27  3:03     ` Nicolas Pitre
2007-05-27  9:16   ` Jim Meyering
2007-05-27 16:17     ` Linus Torvalds
2007-05-28 13:14       ` Jim Meyering
2007-05-28 15:46         ` Marco Roeland
2007-05-28 18:19           ` Jim Meyering
2007-05-28 19:05             ` Marco Roeland
2007-05-28 20:23               ` Jim Meyering
2007-05-28 23:41                 ` Petr Baudis
2007-05-28 20:44             ` Junio C Hamano
2007-05-29 20:11               ` Jim Meyering
2007-05-29 23:50                 ` Junio C Hamano
2007-05-30  7:12                   ` Jim Meyering
2007-05-28 16:32         ` Linus Torvalds
2007-05-28 20:04           ` Jim Meyering
2007-05-29  3:01             ` Linus Torvalds
2007-05-29 20:19               ` Jim Meyering
2007-05-29 21:19                 ` Linus Torvalds
2007-05-30 12:25                   ` Jim Meyering
2007-05-30 15:40                     ` Linus Torvalds
2007-05-30 16:12                       ` Jim Meyering
2007-05-28 21:27         ` Junio C Hamano
2007-05-29  3:47           ` Linus Torvalds
2007-05-30 11:39           ` Jim Meyering
2007-05-30 17:51             ` Junio C Hamano
2007-05-30 19:43               ` Jim Meyering

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 NNTP newsgroup(s).