1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-07 08:06:43 +02:00

run-command: allow stdin for run_processes_parallel

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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Emily Shaffer 2023-02-08 20:21:12 +01:00 committed by Junio C Hamano
parent 5123e6e7bd
commit 540267304d

View File

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