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

Re: [PATCH] Use line buffering for standard output

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Aug 4, 2008, 05:50 UTC
Message-ID
<alpine.LFD.1.10.0808032241260.3668@nehalem.linux-foundation.org>
In-Reply-To
<7vej557hlq.fsf@gitster.siamese.dyndns.org>
On Sun, 3 Aug 2008, Junio C Hamano wrote:
Show 11 quoted lines
> Anders Melchiorsen <mail@cup.kalibalik.dk> writes:
> >  
> >  #ifndef __MINGW32__
> > +	/* Flush output before fork() to avoid cloning the buffer */
> > +	fflush(stdout);
> > +
> >  	async->pid = fork();
> >  	if (async->pid < 0) {
> >  		error("fork (async) failed: %s", strerror(errno));
> 
> I think this with s/stdout/NULL/ would be a reasonable thing to do.
Agreed, I think that's the right thing to do. 

There's another fork there in start_command(), I suspect we should do it there too: it's a "generic" path, so it should try to be safe.

The other ones look ok from a quick scan. I don't know the imap-send.c code, but it's from outside people who hopefully know what they were doing. The other ones don't seem to be using stdio before the fork (except for things like "die()" ;)

There is a "fork()" in a _comment_ in builtin-ls-tree.c, and that one definitely should have a fflush(NULL) in front of it. But it _is_ just a comment, and rather than addign a fflush() there, it would probably be better to turn it into a "start_command()" or something like that.

			Linus.
Previous: Anders MelchiorsenNext: Anders Melchiorsen
Message 7 of 8 in “Use line buffering for standard output”
  1. Use line buffering for standard outputAnders Melchiorsen, Aug 3, 2008
  2. Junio C HamanoAug 3, 2008
  3. Linus TorvaldsAug 3, 2008
  4. Anders MelchiorsenAug 3, 2008
  5. Junio C HamanoAug 4, 2008
  6. Flush output in start_asyncAnders Melchiorsen, Aug 4, 2008
  7. Linus TorvaldsAug 4, 2008
  8. Add output flushing before fork()Anders Melchiorsen, Aug 4, 2008

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.