Skip to content

Commit 5402673

Browse files
nasamuffingitster
authored andcommitted
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 <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5123e6e commit 5402673

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

run-command.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,14 @@ static int pp_start_one(struct parallel_processes *pp,
15861586
if (i == opts->processes)
15871587
BUG("bookkeeping is hard");
15881588

1589+
/*
1590+
* By default, do not inherit stdin from the parent process - otherwise,
1591+
* all children would share stdin! Users may overwrite this to provide
1592+
* something to the child's stdin by having their 'get_next_task'
1593+
* callback assign 0 to .no_stdin and an appropriate integer to .in.
1594+
*/
1595+
pp->children[i].process.no_stdin = 1;
1596+
15891597
code = opts->get_next_task(&pp->children[i].process,
15901598
opts->ungroup ? NULL : &pp->children[i].err,
15911599
opts->data,
@@ -1601,7 +1609,6 @@ static int pp_start_one(struct parallel_processes *pp,
16011609
pp->children[i].process.err = -1;
16021610
pp->children[i].process.stdout_to_stderr = 1;
16031611
}
1604-
pp->children[i].process.no_stdin = 1;
16051612

16061613
if (start_command(&pp->children[i].process)) {
16071614
if (opts->start_failure)

0 commit comments

Comments
 (0)