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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 8, 2023, 21:09 UTC
Message-ID
<xmqq357frhix.fsf@gitster.g>
In-Reply-To
<patch-v2-2.5-9a178577dcc-20230208T191924Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 5 quoted lines
> 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.

I do not think deadlock avoidance is an issue. Unpredictable feeding of pieces of input into multiple children is. One possible semantics is to grab the input and dup/tee into all the children, so that each child gets its own copy to process. A hook like "pre-receive", when it has more than one scripts listening to the event, may want such a semantics. Another possible semantics is to give priority among the children running simultaneously and feed only one child, while starving others.

> 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.

I _think_ this alludes to the latter, e.g. "only one child is allowed, and the one that controls what children are spawned sets no_stdin for everybody but the chosen one". We may want to be a bit more explicit in the proposed log message and definitely in the documentation.

The implementation is "nice".
Show 19 quoted lines
> +	/*
> +	 * 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)
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 19 of 27 in “hook API: support stdin, convert post-rewrite”
  1. 0/5 hook API: support stdin, convert post-rewriteÆvar Arnfjörð Bjarmason, Jan 23, 2023
  2. 1/5 run-command.c: remove dead assignment in while-loopÆvar Arnfjörð Bjarmason, Jan 23, 2023
  3. Junio C HamanoJan 23, 2023
  4. 2/5 run-command: allow stdin for run_processes_parallelÆvar Arnfjörð Bjarmason, Jan 23, 2023
  5. Junio C HamanoJan 23, 2023
  6. 4/5 sequencer: use the new hook API for the simpler "post-rewrite" callÆvar Arnfjörð Bjarmason, Jan 23, 2023
  7. Phillip WoodJan 24, 2023
  8. Phillip WoodJan 27, 2023
  9. 3/5 hook API: support passing stdin to hooks, convert am's 'post-rewrite'Ævar Arnfjörð Bjarmason, Jan 23, 2023
  10. Junio C HamanoJan 23, 2023
  11. Junio C HamanoJan 23, 2023
  12. 5/5 hook: support a --to-stdin=<path> option for testingÆvar Arnfjörð Bjarmason, Jan 23, 2023
  13. Junio C HamanoJan 24, 2023
  14. Michael StrawbridgeJan 24, 2023
  15. 0/5 hook API: support stdin, convert post-rewriteÆvar Arnfjörð Bjarmason, Feb 8, 2023
  16. 1/5 run-command.c: remove dead assignment in while-loopÆvar Arnfjörð Bjarmason, Feb 8, 2023
  17. Junio C HamanoFeb 8, 2023
  18. 2/5 run-command: allow stdin for run_processes_parallelÆvar Arnfjörð Bjarmason, Feb 8, 2023
  19. Junio C HamanoFeb 8, 2023
  20. 3/5 hook API: support passing stdin to hooks, convert am's 'post-rewrite'Ævar Arnfjörð Bjarmason, Feb 8, 2023
  21. Junio C HamanoFeb 8, 2023
  22. 5/5 hook: support a --to-stdin=<path> optionÆvar Arnfjörð Bjarmason, Feb 8, 2023
  23. Junio C HamanoFeb 8, 2023
  24. Ævar Arnfjörð BjarmasonFeb 9, 2023
  25. 4/5 sequencer: use the new hook API for the simpler "post-rewrite" callÆvar Arnfjörð Bjarmason, Feb 8, 2023
  26. Junio C HamanoFeb 8, 2023
  27. Junio C HamanoFeb 8, 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.