From: Johannes Sixt <j6t@kdbg.org>
To: Jeff King <peff@peff.net>
Cc: "Trygve Aaberge" <trygveaa@gmail.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
git@vger.kernel.org
Subject: Re: Regression: Ctrl-c from the pager in an alias exits it
Date: Fri, 6 Jan 2017 23:42:25 +0100 [thread overview]
Message-ID: <2ed6f78b-7704-c724-c99b-e310c383c4e8@kdbg.org> (raw)
In-Reply-To: <20170106194115.k5u5esv7t63mryvk@sigill.intra.peff.net>
Am 06.01.2017 um 20:41 schrieb Jeff King:
> On Fri, Jan 06, 2017 at 03:39:59PM +0100, Johannes Sixt wrote:
>
>>> diff --git a/run-command.c b/run-command.c
>>> index ca905a9e80..db47c429b7 100644
>>> --- a/run-command.c
>>> +++ b/run-command.c
>>> @@ -29,6 +29,8 @@ static int installed_child_cleanup_handler;
>>>
>>> static void cleanup_children(int sig, int in_signal)
>>> {
>>> + struct child_to_clean *children_to_wait_for = NULL;
>>> +
>>> while (children_to_clean) {
>>> struct child_to_clean *p = children_to_clean;
>>> children_to_clean = p->next;
>>> @@ -45,6 +47,17 @@ static void cleanup_children(int sig, int in_signal)
>>> }
>>>
>>> kill(p->pid, sig);
>>> + p->next = children_to_wait_for;
>>> + children_to_wait_for = p;
>>> + }
>>> +
>>> + while (children_to_wait_for) {
>>> + struct child_to_clean *p = children_to_wait_for;
>>> + children_to_wait_for = p->next;
>>> +
>>> + while (waitpid(p->pid, NULL, 0) < 0 && errno == EINTR)
>>> + ; /* spin waiting for process exit or error */
>>> +
>>> if (!in_signal)
>>> free(p);
>>> }
>>>
>>
>> This looks like the minimal change necessary. I wonder, though, whether the
>> new local variable is really required. Wouldn't it be sufficient to walk the
>> children_to_clean chain twice?
>
> Yeah, I considered that. The fact that we disassemble the list in the
> first loop has two side effects:
>
> 1. It lets us free the list as we go (for the !in_signal case).
>
> 2. If we were to get another signal, it makes us sort-of reentrant. We
> will only kill and wait for each pid once.
>
> Obviously (1) moves down to the lower loop, but I was trying to preserve
> (2). I'm not sure if it is worth bothering, though.
Makes sense.
> The way we pull
> items off of the list is certainly not atomic (it does shorten the race
> to a few instructions, though, versus potentially waiting on waitpid()
> to return).
>
> My bigger concern with the whole thing is whether we could hit some sort
> of deadlock if the child doesn't die when we send it a signal. E.g.,
> imagine we have a pipe open to the child and somebody sends SIGTERM to
> us. We propagate SIGTERM to the child, and then waitpid() for it. The
> child decides to ignore our SIGTERM for some reason and keep reading
> until EOF on the pipe. It won't ever get it, and the two processes will
> hang forever.
>
> You can argue perhaps that the child is broken in that case. And I doubt
> this could trigger when running a git sub-command. But we may add more
> children in the future. Right now we use it for the new multi-file
> clean/smudge filters. They use the hook feature to close the
> descriptors, but note that that won't run in the in_signal case.
>
> So I dunno. Maybe this waiting should be restricted only to certain
> cases like executing git sub-commands.
If given it some thought.
In general, I think it is wrong to wait for child processes when a
signal was received. After all, it is the purpose of a (deadly) signal
to have the process go away. There may be programs that know it better,
like less, but git should not attempt to know better in general.
We do apply some special behavior for certain cases like we do for the
pager. And now the case with aliases is another special situation. The
parent git process only delegates to the child, and as such it is
reasonable that it binds its life time to the first child, which
executes the expanded alias.
-- Hannes
next prev parent reply other threads:[~2017-01-06 22:44 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-05 14:25 Regression: Ctrl-c from the pager in an alias exits it Trygve Aaberge
2017-01-06 6:40 ` Jeff King
2017-01-06 6:47 ` Jeff King
2017-01-06 7:26 ` Jeff King
2017-01-06 7:32 ` Jeff King
2017-01-06 13:19 ` Trygve Aaberge
2017-01-06 14:39 ` Johannes Sixt
2017-01-06 19:41 ` Jeff King
2017-01-06 22:42 ` Johannes Sixt [this message]
2017-01-06 23:20 ` Jeff King
2017-01-07 1:14 ` [PATCH 0/3] fix ^C killing pager when running alias Jeff King
2017-01-07 1:16 ` [PATCH 1/3] execv_dashed_external: use child_process struct Jeff King
2017-01-07 1:17 ` [PATCH 2/3] execv_dashed_external: stop exiting with negative code Jeff King
2017-01-07 1:22 ` [PATCH 3/3] execv_dashed_external: wait for child on signal death Jeff King
2017-01-07 7:28 ` Johannes Sixt
2017-01-07 7:34 ` Jeff King
2017-01-07 9:07 ` Duy Nguyen
2017-01-07 23:26 ` [PATCH 0/3] fix ^C killing pager when running alias Jacob Keller
2017-01-07 23:27 ` Jacob Keller
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2ed6f78b-7704-c724-c99b-e310c383c4e8@kdbg.org \
--to=j6t@kdbg.org \
--cc=git@vger.kernel.org \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
--cc=trygveaa@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).