# [PATCH] run-command.c: ensure signaled hook scripts are waited upon

3 messages from 2020-02-21 to 2020-02-22. Participants: Anthony Sottile, Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/52859

## Anthony Sottile, 2020-02-21 06:06

Subject: [PATCH] run-command.c: ensure signaled hook scripts are waited upon
Message-ID: <20200221060636.4507-1-asottile@umich.edu>
URL: https://gitlist.dev/e/20200221060636.4507-1-asottile%40umich.edu

```
In the event of a `^C` while hook scripts are running, ensure that the
hook processes are cleaned up and do not become zombies.  This also ensures
that upon `^C` execution is not handed back to the terminal until the
processes have been waited upon.

Signed-off-by: Anthony Sottile <asottile@umich.edu>
---
 run-command.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/run-command.c b/run-command.c
index f5e1149..75d3b73 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1358,6 +1358,8 @@ int run_hook_ve(const char *const *env, const char *name, va_list args)
 	hook.no_stdin = 1;
 	hook.stdout_to_stderr = 1;
 	hook.trace2_hook_name = name;
+	hook.clean_on_exit = 1;
+	hook.wait_after_clean = 1;
 
 	return run_command(&hook);
 }
-- 
2.25.GIT


```

## Jeff King, 2020-02-21 06:39

Subject: Re: [PATCH] run-command.c: ensure signaled hook scripts are waited upon
Message-ID: <20200221063954.GJ1280313@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20200221063954.GJ1280313%40coredump.intra.peff.net
In-Reply-To: <20200221060636.4507-1-asottile@umich.edu>

```
On Thu, Feb 20, 2020 at 10:06:36PM -0800, Anthony Sottile wrote:

> In the event of a `^C` while hook scripts are running, ensure that the
> hook processes are cleaned up and do not become zombies.  This also ensures
> that upon `^C` execution is not handed back to the terminal until the
> processes have been waited upon.

If we assume that most people would prefer this "wait until the hook has
died" behavior, I think this shouldn't have any unwanted secondary
effects. I'm on the fence on whether it's what most people would want or
not (I guess most people don't care either way, because their scripts
don't ignore SIGINT).

(Earlier in the thread, we discussed possibly swapping the order of the
cleanup code and dropping the signal handler, which could have more
unexpected effects, but that part isn't in this patch).

-Peff

```

## Junio C Hamano, 2020-02-22 17:12

Subject: Re: [PATCH] run-command.c: ensure signaled hook scripts are waited upon
Message-ID: <xmqqblpq7dho.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqblpq7dho.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <20200221063954.GJ1280313@coredump.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> If we assume that most people would prefer this "wait until the hook has
> died" behavior, I think this shouldn't have any unwanted secondary
> effects. I'm on the fence on whether it's what most people would want or
> not (I guess most people don't care either way, because their scripts
> don't ignore SIGINT).

Yeah, and imagining why they deliberately ignore INT (i.e. "because
I want this hook not be interrupted and run to its completion") does
not help guess if they want git to wait for hook's completion or
just go ahead and die of its own signal death.  We could timeout the
waiting and kill such a child forcibly, and that may avoid these
hook script that ignore INT to hang around, but I do not know if
that is desirable.



```
