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

Re: [PATCH 1/2] run-command: Remove set_nonblocking

From
Stefan Beller <sbeller@google.com>
Date
Nov 5, 2015, 22:20 UTC
Message-ID
<CAGZ79kZs8HQegNy=L5nGMUGJ98s-xgce1Ncrxpxe_ReaJXMjKw@mail.gmail.com>
In-Reply-To
<563BBBBC.7070807@kdbg.org>
On Thu, Nov 5, 2015 at 12:27 PM, Johannes Sixt <j6t@kdbg.org> wrote:
Show 26 quoted lines
> diff --git a/run-command.c b/run-command.c
> index 51d078c..3e42299 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -977,7 +977,7 @@ static struct parallel_processes *pp_init(int n,
>         for (i = 0; i < n; i++) {
>                 strbuf_init(&pp->children[i].err, 0);
>                 child_process_init(&pp->children[i].process);
> -               pp->pfd[i].events = POLLIN;
> +               pp->pfd[i].events = POLLIN|POLLHUP;
>                 pp->pfd[i].fd = -1;
>         }
>         sigchain_push_common(handle_children_on_signal);
> @@ -1061,11 +1061,17 @@ static void pp_buffer_stderr(struct parallel_processes *pp, int output_timeout)
>         /* Buffer output from all pipes. */
>         for (i = 0; i < pp->max_processes; i++) {
>                 if (pp->children[i].in_use &&
> -                   pp->pfd[i].revents & POLLIN)
> -                       if (strbuf_read_once(&pp->children[i].err,
> -                                            pp->children[i].process.err, 0) < 0)
> +                   pp->pfd[i].revents & (POLLIN|POLLHUP)) {
> +                       int n = strbuf_read_once(&pp->children[i].err,
> +                                            pp->children[i].process.err, 0);
> +                       if (n == 0) {
> +                               close(pp->children[i].process.err);
> +                               pp->children[i].process.err = -1;
So you set .err to -1 to signal the process has ended here...
Show 6 quoted lines
> -
>                 for (i = 0; i < pp->max_processes; i++)
>                         if (pp->children[i].in_use &&
> -                           pid == pp->children[i].process.pid)
> +                           pp->children[i].process.err == -1)
>                                 break;
to make a decision here if we want to finish_command on it.
> +               code = finish_command(&pp->children[i].process);
> -               child_process_clear(&pp->children[i].process);

but .err stays stays -1 here for the next iteration? We would need to reset it to 0 again.

So .err is
  0 when the slot is not in use
 -1 when the child has finished awaiting termination
 >0 when the child is living a happy life.
Previous: Junio C HamanoNext: Johannes Sixt
Message 8 of 12 in “Remove non-blocking fds from run-command.”
  1. 0/2 Remove non-blocking fds from run-command.Stefan Beller, Nov 5, 2015
  2. 1/2 run-command: Remove set_nonblockingStefan Beller, Nov 5, 2015
  3. Junio C HamanoNov 5, 2015
  4. Stefan BellerNov 5, 2015
  5. Junio C HamanoNov 5, 2015
  6. Johannes SixtNov 5, 2015
  7. Junio C HamanoNov 5, 2015
  8. Stefan BellerNov 5, 2015
  9. Johannes SixtNov 6, 2015
  10. Stefan BellerNov 6, 2015
  11. Johannes SixtNov 6, 2015
  12. 2/2 strbuf: Correct documentation for strbuf_read_onceStefan Beller, Nov 5, 2015

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.