git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Trygve Aaberge <trygveaa@gmail.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Junio C Hamano <gitster@pobox.com>,
	Jeff Hostetler <jeffhost@microsoft.com>
Subject: Re: [PATCH 2/2] Wait for child on signal death for aliases to externals
Date: Tue, 7 Jul 2020 12:19:59 +0200	[thread overview]
Message-ID: <20200707101959.qsuumtuelepnxore@aaberge.net> (raw)
In-Reply-To: <20200706211403.GB85133@coredump.intra.peff.net>

On Mon, Jul 06, 2020 at 17:14:03 -0400, Jeff King wrote:
>     I guess to recreate that you'd need to trigger the pager inside the
>     alias itself, like:
> 
>       $ git -c alias.foo='!{ echo foo; sleep 10; echo bar; } | less' foo
>       ^C
> 
>     which does exhibit the annoying behavior (we exit, and pgrp loses
>     the tty session leader bit, and the pager gets EIO).

Yes, that's correct. So it's a rather niche use case. The main thing for me
was the first commit, but I figured I should fix this too while I was at it. I
don't think I have any current use cases where I would need this fix, but I
could imagine some existing. For instance, before stash list got the -p
option, I had this alias:

  stash-p = !git show $(git stash list | cut -d: -f1)

And this is one use case where the pager is invoked inside the alias, so the
first patch doesn't help, but the second one fixes it. While this alias isn't
necessary anymore, there could be similar use cases.

>   - the child for some reason decides not to respect the signal.
>     Obviously running a pager is one reason it would decide to do so,
>     and we'd be improving the behavior there. I have trouble imagining a
>     case where waiting for it would do the _wrong_ thing. I.e., if I do:
> 
>       $ git -c alias.foo='!trap "echo got signal" INT; sleep 5' foo
> 
>     it probably does make sense for us to continue to wait on that alias
>     to complete (I'm not sure what anyone would try to accomplish with
>     that, but waiting seems like the least-astonishing thing to me).

Yeah, I agree. Since it's an alias to an external command, I think it should
behave just as when running that external command by itself where there would
be no parent killing it on ^C.

> However, there is one weirdness worth thinking about. Because the
> wait_after_clean feature relies on actually trying to clean the child,
> Git will actually send a signal to the alias shell. For a signal, we'll
> try to pass along the same signal, so it just means the shell will get
> SIGINT twice in this case (or more likely, they'll race and we'll ignore
> the duplicate signal while the child is in its own handler).

Hm, okay, not sure if anything should be done about this.

> But a more interesting case is if somebody sends the parent git process
> a signal but _not_ the child (e.g., kill -TERM). Then we'd pass SIGTERM
> along to the child. I'd venture to say that's _probably_ the right thing
> to do, if only because it's exactly what we do for a dashed external as
> well.

Hm, not sure. If you run a process in bash and send TERM to bash it seems to
just ignore the signal. The child keeps running, and bash even keeps running
after the child exits. If you don't run a process in bash it respects TERM and
exits. I'm wondering if an alias executing an external command should behave
the same way as when a shell does it.

Though, I also see that this only happens when bash runs interactively. If you
run `bash -c 'echo; sleep 1000'` it exits, but sleep keeps running.

> Sorry that ended up so long-winded, but my conclusion is: this is doing
> the right thing. We should probably embed some of that discussion in the
> commit message, but I think the simplest argument is just: this is what
> we do for external commands we run, so treating shell aliases the same
> in terms of passing along signals makes things simple and consistent.

Thanks, yeah I'll send an updated patch with a better description.

-- 
Trygve Aaberge

  parent reply	other threads:[~2020-07-07 10:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-04 22:18 [PATCH 1/2] Wait for child on signal death for aliases to builtins trygveaa
2020-07-04 22:18 ` [PATCH 2/2] Wait for child on signal death for aliases to externals trygveaa
2020-07-06 21:14   ` Jeff King
2020-07-07  1:38     ` Junio C Hamano
2020-07-07 10:19     ` Trygve Aaberge [this message]
2020-07-07 22:06       ` Jeff King
2020-07-05  2:15 ` [PATCH 1/2] Wait for child on signal death for aliases to builtins Johannes Schindelin
2020-07-07  1:48   ` Junio C Hamano
2020-07-06 20:41 ` Jeff King
2020-07-07  1:50   ` Junio C Hamano
2020-07-07 10:23     ` Trygve Aaberge
2020-07-07 12:17 ` [PATCH v2 " trygveaa
2020-07-07 12:17   ` [PATCH v2 2/2] Wait for child on signal death for aliases to externals trygveaa

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=20200707101959.qsuumtuelepnxore@aaberge.net \
    --to=trygveaa@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jeffhost@microsoft.com \
    --cc=peff@peff.net \
    /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).