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

[PATCH] Add output flushing before fork()

From
AMAnders Melchiorsen <mail@cup.kalibalik.dk>
Date
Aug 4, 2008, 10:18 UTC
Message-ID
<1217845120-28134-1-git-send-email-mail@cup.kalibalik.dk>
In-Reply-To
<alpine.LFD.1.10.0808032241260.3668@nehalem.linux-foundation.org>

This adds fflush(NULL) before fork() in start_command(), to keep the generic interface safe.

A remaining use of fork() with no flushing is in a comment in show_tree(). Rewrite that comment to use start_command().

Signed-off-by: Anders Melchiorsen <mail@cup.kalibalik.dk>
---
This fixes up the remaining two spots that Linus suggested.
 builtin-ls-tree.c |   13 ++++++-------
 run-command.c     |    1 +
 2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/builtin-ls-tree.c b/builtin-ls-tree.c
index d25767a..cb61717 100644
--- a/builtin-ls-tree.c
+++ b/builtin-ls-tree.c
@@ -66,17 +66,16 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
 		/*
 		 * Maybe we want to have some recursive version here?
 		 *
-		 * Something like:
+		 * Something similar to this incomplete example:
 		 *
 		if (show_subprojects(base, baselen, pathname)) {
-			if (fork()) {
-				chdir(base);
-				exec ls-tree;
-			}
-			waitpid();
+			struct child_process ls_tree;
+
+			ls_tree.dir = base;
+			ls_tree.argv = ls-tree;
+			start_command(&ls_tree);
 		}
 		 *
-		 * ..or similar..
 		 */
 		type = commit_type;
 	} else if (S_ISDIR(mode)) {
diff --git a/run-command.c b/run-command.c
index 6af83c5..bbb9c77 100644
--- a/run-command.c
+++ b/run-command.c
@@ -68,6 +68,7 @@ int start_command(struct child_process *cmd)
 	trace_argv_printf(cmd->argv, "trace: run_command:");
 
 #ifndef __MINGW32__
+	fflush(NULL);
 	cmd->pid = fork();
 	if (!cmd->pid) {
 		if (cmd->no_stdin)
-- 
1.5.6.4
Previous: Linus Torvalds
Message 8 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.