git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "brian m. carlson" <sandals@crustytoothpaste.net>
Cc: Anthony Sottile <asottile@umich.edu>,
	Git Mailing List <git@vger.kernel.org>
Subject: Re: git does not wait on hook exes (^C)
Date: Fri, 21 Feb 2020 00:32:21 -0500	[thread overview]
Message-ID: <20200221053221.GC1280313@coredump.intra.peff.net> (raw)
In-Reply-To: <20200221022558.GD6462@camp.crustytoothpaste.net>

On Fri, Feb 21, 2020 at 02:25:58AM +0000, brian m. carlson wrote:

> On 2020-02-21 at 01:20:51, Anthony Sottile wrote:
> > My hook in question is a python process: https://pre-commit.com
> > 
> > It doesn't really do all that much on SIGINT but prints "(^C)
> > Interrupted" and offers a crash log when receiving ^C -- this races
> > with the git process terminating and causes terminal spew (sometimes
> > with pretty bad consequences with input breaking until `reset`
> > depending on which thing wins the tty reset race).
> 
> Thanks, this is helpful context.  I don't know that Git waiting for the
> process is going to fix the broken terminal state, although it will
> likely fix the jumbled output.
> 
> I'm not planning on writing a patch, but I think an interesting patch to
> see might be if we called wait(2) in a loop in a SIGINT handler but
> didn't reinstall the signal handler, which means that a second Ctrl-C
> would kill Git.  I believe that's what certain other programs do, and
> that might address many of the problems in both scenarios.

The run-command struct has a clean_on_exit flag, as well as a
wait_after_clean flag, that would do what you want: when we're killed by
SIGINT, we'd pass the signal on to the child and then wait for to
finish.  That first step should generally be unnecessary for SIGINT
(since as you noted, it will usually be delivered to the whole process
group), but it shouldn't hurt.

To get the double-^C behavior, I think cleanup_children_on_signal()
would have to be reordered to pop the signal handler first before
calling cleanup_children().

I'm not quite convinced that's all worth doing, or wouldn't have other
unforeseen consequences. But if anybody is interested in experimenting,
I think the patch would only be a few lines (set those flags when
running hooks, and then that reordering).

-Peff

  reply	other threads:[~2020-02-21  5:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-20 21:14 git does not wait on hook exes (^C) Anthony Sottile
2020-02-21  0:01 ` brian m. carlson
2020-02-21  0:12   ` Anthony Sottile
2020-02-21  1:11     ` brian m. carlson
2020-02-21  1:20       ` Anthony Sottile
2020-02-21  2:25         ` brian m. carlson
2020-02-21  5:32           ` Jeff King [this message]
2020-02-21  6:08             ` Anthony Sottile

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=20200221053221.GC1280313@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=asottile@umich.edu \
    --cc=git@vger.kernel.org \
    --cc=sandals@crustytoothpaste.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.
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).