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

[PATCH v2 2/5] run-command: allow stdin for run_processes_parallel

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Feb 3, 2023, 12:15 UTC
Message-ID
<patch-v2-2.5-9a178577dcc-20230203T104319Z-avarab@gmail.com>
In-Reply-To
<cover-v2-0.5-00000000000-20230203T104319Z-avarab@gmail.com>
From: Emily Shaffer <emilyshaffer@google.com>

While it makes sense not to inherit stdin from the parent process to avoid deadlocking, it's not necessary to completely ban stdin to children. An informed user should be able to configure stdin safely. By setting `some_child.process.no_stdin=1` before calling `get_next_task()` we provide a reasonable default behavior but enable users to set up stdin streaming for themselves during the callback.

`some_child.process.stdout_to_stderr`, however, remains unmodifiable by `get_next_task()` - the rest of the run_processes_parallel() API depends on child output in stderr.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 run-command.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/run-command.c b/run-command.c
index b439c7974ca..6bd16acb060 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1586,6 +1586,14 @@ static int pp_start_one(struct parallel_processes *pp,
 	if (i == opts->processes)
 		BUG("bookkeeping is hard");
 
+	/*
+	 * By default, do not inherit stdin from the parent process - otherwise,
+	 * all children would share stdin! Users may overwrite this to provide
+	 * something to the child's stdin by having their 'get_next_task'
+	 * callback assign 0 to .no_stdin and an appropriate integer to .in.
+	 */
+	pp->children[i].process.no_stdin = 1;
+
 	code = opts->get_next_task(&pp->children[i].process,
 				   opts->ungroup ? NULL : &pp->children[i].err,
 				   opts->data,
@@ -1601,7 +1609,6 @@ static int pp_start_one(struct parallel_processes *pp,
 		pp->children[i].process.err = -1;
 		pp->children[i].process.stdout_to_stderr = 1;
 	}
-	pp->children[i].process.no_stdin = 1;
 
 	if (start_command(&pp->children[i].process)) {
 		if (opts->start_failure)
-- 
2.39.1.1397.g8c8c074958d
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 3 of 6 in “hook API: support stdin, convert post-rewrite”
  1. 0/5 hook API: support stdin, convert post-rewriteÆvar Arnfjörð Bjarmason, Feb 3, 2023
  2. 1/5 run-command.c: remove dead assignment in while-loopÆvar Arnfjörð Bjarmason, Feb 3, 2023
  3. 2/5 run-command: allow stdin for run_processes_parallelÆvar Arnfjörð Bjarmason, Feb 3, 2023
  4. 4/5 sequencer: use the new hook API for the simpler "post-rewrite" callÆvar Arnfjörð Bjarmason, Feb 3, 2023
  5. 3/5 hook API: support passing stdin to hooks, convert am's 'post-rewrite'Ævar Arnfjörð Bjarmason, Feb 3, 2023
  6. 5/5 hook: support a --to-stdin=<path> optionÆvar Arnfjörð Bjarmason, Feb 3, 2023

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.