git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Use line buffering for standard output
@ 2008-08-03 21:26 Anders Melchiorsen
  2008-08-03 21:38 ` Junio C Hamano
  2008-08-03 21:46 ` Linus Torvalds
  0 siblings, 2 replies; 8+ messages in thread
From: Anders Melchiorsen @ 2008-08-03 21:26 UTC (permalink / raw)
  To: git; +Cc: gitster, Anders Melchiorsen

Normally, stdout is fully buffered, unless it refers to a terminal
device. This gives problems when fork() is in play: the buffer is
cloned and output appears twice.

By always setting stdout to line buffering, we make the output work
identically for all output devices.

Signed-off-by: Anders Melchiorsen <mail@cup.kalibalik.dk>
---

On #git, blix mentioned that running git clone through a pipe made it
output the "Initialized empty" line twice. This seems to be due to
bad interactions between fork() and buffered stdio.

Rather than putting in flushing at all the right places, this
sledgehammer fix simply reverts to line buffering for all output devices.


Anders.


 git.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/git.c b/git.c
index 37b1d76..040b900 100644
--- a/git.c
+++ b/git.c
@@ -421,6 +421,12 @@ int main(int argc, const char **argv)
 	int done_alias = 0;
 
 	/*
+	 * Use line buffering, even if we do not have interactive
+	 * output. Full buffering mixes badly with fork().
+	 */
+	setvbuf(stdout, NULL, _IOLBF, 0);
+
+	/*
 	 * Take the basename of argv[0] as the command
 	 * name, and the dirname as the default exec_path
 	 * if we don't have anything better.
-- 
1.5.6.4

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

end of thread, other threads:[~2008-08-04 10:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-03 21:26 [PATCH] Use line buffering for standard output Anders Melchiorsen
2008-08-03 21:38 ` Junio C Hamano
2008-08-03 21:46 ` Linus Torvalds
2008-08-03 22:48   ` Anders Melchiorsen
2008-08-04  0:24     ` Junio C Hamano
2008-08-04  0:30       ` [PATCH] Flush output in start_async Anders Melchiorsen
2008-08-04  5:50       ` [PATCH] Use line buffering for standard output Linus Torvalds
2008-08-04 10:18         ` [PATCH] Add output flushing before fork() Anders Melchiorsen

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).