Re: [PATCH 03/12] t: prepare `stop_git_daemon ()` for `set -e`
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 13, 2026, 16:53 UTC
- Message-ID
- <xmqq8qaqkdjc.fsf@gitster.g>
- In-Reply-To
- <20260413-b4-pks-tests-with-set-e-v1-3-5b83763a0e84@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 27 quoted lines
> We have a couple of calls to `stop_git_daemon ()` outside of specific > test cases that will kill a backgrounded git-daemon(1) process and > expect the process with a specific error code. While these function > calls do end up killing git-daemon(1), the error handling we have in > those contexts is basically ineffective. So while we expect the process > to exit with a specific error code, we will just continue with any error > in case it doesn't. > > This will change once we enable `set -e` in a subsequent commit. There's > two issues though that will make this _always_ fail: > > - Our call to `wait` is expected to fail, but because it's not part of > a condition it will cause us to bail out immediately with `set -e`. > > - We try to kill git-daemon(1) a second time via the pidfile. We can > generally expect that this is the same PID though as we had in the > "GIT_DAEMON_PID" environment variable, and thus it's more likely > than not that we have already killed it, and the call to kill will > fail. > > Prepare for this change by making the call to `wait` part of a condition > and by silencing failures of the second call to `kill`. > > Signed-off-by: Patrick Steinhardt <ps@pks.im> > --- > t/lib-git-daemon.sh | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-)
The same comment as [02/12] applies to the early part.
Ignoring the exit status from "kill" in case that the daemon has already exited with " || :" totally makes sense.
Show 29 quoted lines
> diff --git a/t/lib-git-daemon.sh b/t/lib-git-daemon.sh
> index e62569222b..91bcdd0bf7 100644
> --- a/t/lib-git-daemon.sh
> +++ b/t/lib-git-daemon.sh
> @@ -85,14 +85,21 @@ stop_git_daemon() {
>
> # kill git-daemon child of git
> say >&3 "Stopping git daemon ..."
> +
> kill "$GIT_DAEMON_PID"
> - wait "$GIT_DAEMON_PID" >&3 2>&4
> - ret=$?
> + if wait "$GIT_DAEMON_PID" >&3 2>&4
> + then
> + ret=0
> + else
> + ret=$?
> + fi
> +
> if ! test_match_signal 15 $ret
> then
> error "git daemon exited with status: $ret"
> fi
> - kill "$(cat "$GIT_DAEMON_PIDFILE")" 2>/dev/null
> +
> + kill "$(cat "$GIT_DAEMON_PIDFILE")" 2>/dev/null || :
> GIT_DAEMON_PID=
> rm -f git_daemon_output "$GIT_DAEMON_PIDFILE"
> }