From: Johannes Sixt <j6t@kdbg.org>
To: Stefan Beller <sbeller@google.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>,
"Jeff King" <peff@peff.net>, "Junio C Hamano" <gitster@pobox.com>,
"Johannes Schindelin" <johannes.schindelin@gmail.com>,
"Jens Lehmann" <Jens.Lehmann@web.de>,
"Eric Sunshine" <ericsunshine@gmail.com>,
"Torsten Bögershausen" <tboegi@web.de>
Subject: Re: [PATCH 1/2] run-command: Remove set_nonblocking
Date: Fri, 6 Nov 2015 06:51:27 +0100 [thread overview]
Message-ID: <563C3FDF.9050304@kdbg.org> (raw)
In-Reply-To: <CAGZ79kZs8HQegNy=L5nGMUGJ98s-xgce1Ncrxpxe_ReaJXMjKw@mail.gmail.com>
Am 05.11.2015 um 23:20 schrieb Stefan Beller:
> On Thu, Nov 5, 2015 at 12:27 PM, Johannes Sixt <j6t@kdbg.org> wrote:
>
>> 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...
>
>> -
>> 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.
Correct.
>> + 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.
No. In the next round, we need -1 to request a pipe. get_next_task
callback sets it to -1 as well (and I think it is wrong that the
callback does it; pp_start_one should do that).
> 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.
But, as I said, .err is not the right place to mark dying processes (it
was just the simplest way to demonstrate the concept in this patch).
Better extend .in_use to a tri-state indicator.
-- Hannes
next prev parent reply other threads:[~2015-11-06 5:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-05 18:17 [PATCH 0/2] Remove non-blocking fds from run-command Stefan Beller
2015-11-05 18:17 ` [PATCH 1/2] run-command: Remove set_nonblocking Stefan Beller
2015-11-05 18:45 ` Junio C Hamano
2015-11-05 19:22 ` Stefan Beller
2015-11-05 19:37 ` Junio C Hamano
2015-11-05 20:27 ` Johannes Sixt
2015-11-05 20:50 ` Junio C Hamano
2015-11-05 22:20 ` Stefan Beller
2015-11-06 5:51 ` Johannes Sixt [this message]
2015-11-06 19:00 ` Stefan Beller
2015-11-06 21:41 ` Johannes Sixt
2015-11-05 18:17 ` [PATCH 2/2] strbuf: Correct documentation for strbuf_read_once Stefan Beller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=563C3FDF.9050304@kdbg.org \
--to=j6t@kdbg.org \
--cc=Jens.Lehmann@web.de \
--cc=ericsunshine@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johannes.schindelin@gmail.com \
--cc=peff@peff.net \
--cc=sbeller@google.com \
--cc=tboegi@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).