# [PATCH] t0005: ksh93 portability workaround

6 messages from 2016-05-31 to 2016-05-31. Participants: Junio C Hamano, Eric Sunshine, Jeff King.
Thread: https://gitlist.dev/t/42499

## Junio C Hamano, 2016-05-31 22:47

Subject: [PATCH] t0005: ksh93 portability workaround
Message-ID: <xmqqinxt3kwq.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqinxt3kwq.fsf%40gitster.mtv.corp.google.com

```
The test has two things ksh93 does not happy about:

 * It thinks "(( command1; command2 ) | command3)" is a perfectly
   sane way to write a pipeline.  ksh93, unlike other POSIX shells,
   does not like the two open parentheses next to each other for
   whatever reason it has.

 * It adds 256, unlike 128 that are used by other POSIX shells, to
   the signal number that caused the process to die when coming up
   with the exit status.

What is interesting is that we knew about the latter issue and had a
workaround in the test-sigchain test when verifying that SIGTERM
works OK, but we didn't have corresponding workaround for SIGPIPE.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/t0005-signals.sh | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/t/t0005-signals.sh b/t/t0005-signals.sh
index e7f27eb..12b4efb 100755
--- a/t/t0005-signals.sh
+++ b/t/t0005-signals.sh
@@ -9,6 +9,16 @@ two
 one
 EOF
 
+died_with_sigpipe () {
+	case "$1" in
+	141 | 269)
+		# POSIX w/ SIGPIPE=13 gives 141
+		# ksh w/ SIGPIPE=13 gives 269
+		true ;;
+	*)	false ;;
+	esac
+}
+
 test_expect_success 'sigchain works' '
 	{ test-sigchain >actual; ret=$?; } &&
 	case "$ret" in
@@ -40,13 +50,13 @@ test_expect_success 'create blob' '
 '
 
 test_expect_success !MINGW 'a constipated git dies with SIGPIPE' '
-	OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) &&
-	test "$OUT" -eq 141
+	OUT=$( ( (large_git; echo $? 1>&3) | :) 3>&1 ) &&
+	died_with_sigpipe "$OUT"
 '
 
 test_expect_success !MINGW 'a constipated git dies with SIGPIPE even if parent ignores it' '
-	OUT=$( ((trap "" PIPE; large_git; echo $? 1>&3) | :) 3>&1 ) &&
-	test "$OUT" -eq 141
+	OUT=$( ( (trap "" PIPE; large_git; echo $? 1>&3) | :) 3>&1 ) &&
+	died_with_sigpipe "$OUT"
 '
 
 test_done

```

## Eric Sunshine, 2016-05-31 22:49

Subject: Re: [PATCH] t0005: ksh93 portability workaround
Message-ID: <CAPig+cRD8aTNJxvfkc-5Xjr6_pKRzAi3SpZ7JCZcRYMQFT_xMg@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcRD8aTNJxvfkc-5Xjr6_pKRzAi3SpZ7JCZcRYMQFT_xMg%40mail.gmail.com
In-Reply-To: <xmqqinxt3kwq.fsf@gitster.mtv.corp.google.com>

```
On Tue, May 31, 2016 at 6:47 PM, Junio C Hamano <gitster@pobox.com> wrote:
> The test has two things ksh93 does not happy about:

s/does/is/

>  * It thinks "(( command1; command2 ) | command3)" is a perfectly
>    sane way to write a pipeline.  ksh93, unlike other POSIX shells,
>    does not like the two open parentheses next to each other for
>    whatever reason it has.
>
>  * It adds 256, unlike 128 that are used by other POSIX shells, to
>    the signal number that caused the process to die when coming up
>    with the exit status.
>
> What is interesting is that we knew about the latter issue and had a
> workaround in the test-sigchain test when verifying that SIGTERM
> works OK, but we didn't have corresponding workaround for SIGPIPE.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>

```

## Jeff King, 2016-05-31 23:03

Subject: Re: [PATCH] t0005: ksh93 portability workaround
Message-ID: <20160531230301.GB4585@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20160531230301.GB4585%40sigill.intra.peff.net
In-Reply-To: <xmqqinxt3kwq.fsf@gitster.mtv.corp.google.com>

```
On Tue, May 31, 2016 at 03:47:01PM -0700, Junio C Hamano wrote:

> The test has two things ksh93 does not happy about:
> 
>  * It thinks "(( command1; command2 ) | command3)" is a perfectly
>    sane way to write a pipeline.  ksh93, unlike other POSIX shells,
>    does not like the two open parentheses next to each other for
>    whatever reason it has.
> 
>  * It adds 256, unlike 128 that are used by other POSIX shells, to
>    the signal number that caused the process to die when coming up
>    with the exit status.
> 
> What is interesting is that we knew about the latter issue and had a
> workaround in the test-sigchain test when verifying that SIGTERM
> works OK, but we didn't have corresponding workaround for SIGPIPE.

Hmm. We discussed these back in:

  http://thread.gmane.org/gmane.comp.version-control.git/268657

but I thought we decided not to do anything about them (according to
that thread, I found a bunch of other ksh93 oddities, but maybe we've
since fixed them?).

> +died_with_sigpipe () {
> +	case "$1" in
> +	141 | 269)
> +		# POSIX w/ SIGPIPE=13 gives 141
> +		# ksh w/ SIGPIPE=13 gives 269
> +		true ;;
> +	*)	false ;;
> +	esac
> +}

This is OK, but I like the patch I posted in

  http://article.gmane.org/gmane.comp.version-control.git/268666

better, as it contains the shell logic in a single place (though I am
not sure how these tests fare on Windows, where I think every signal
just looks like "3").

-Peff

```

## Junio C Hamano, 2016-05-31 23:04

Subject: [PATCH] t/lib-git-daemon: ksh portability workaround
Message-ID: <xmqq60tt3k4f.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq60tt3k4f.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <xmqqinxt3kwq.fsf@gitster.mtv.corp.google.com>

```
The "git daemon" test checks with what status the daemon exits when
we terminate it, and we expect that we can observe death by SIGTERM.

We forgot that ksh adds 256, unlike 128 that are used by other POSIX
shells, to the signal number that caused the process to die when
coming up with the exit status.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
diff --git a/t/lib-git-daemon.sh b/t/lib-git-daemon.sh
index 340534c..623b3ae 100644
--- a/t/lib-git-daemon.sh
+++ b/t/lib-git-daemon.sh
@@ -83,7 +83,8 @@ stop_git_daemon() {
 	wait "$GIT_DAEMON_PID" >&3 2>&4
 	ret=$?
 	# expect exit with status 143 = 128+15 for signal TERM=15
-	if test $ret -ne 143
+	# or 271 = 256+15 on ksh
+	if test $ret -ne 143 && test $ret -ne 271
 	then
 		error "git daemon exited with status: $ret"
 	fi

```

## Jeff King, 2016-05-31 23:05

Subject: Re: [PATCH] t/lib-git-daemon: ksh portability workaround
Message-ID: <20160531230547.GC4585@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20160531230547.GC4585%40sigill.intra.peff.net
In-Reply-To: <xmqq60tt3k4f.fsf@gitster.mtv.corp.google.com>

```
On Tue, May 31, 2016 at 04:04:00PM -0700, Junio C Hamano wrote:

> The "git daemon" test checks with what status the daemon exits when
> we terminate it, and we expect that we can observe death by SIGTERM.
> 
> We forgot that ksh adds 256, unlike 128 that are used by other POSIX
> shells, to the signal number that caused the process to die when
> coming up with the exit status.
> 
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
> diff --git a/t/lib-git-daemon.sh b/t/lib-git-daemon.sh
> index 340534c..623b3ae 100644
> --- a/t/lib-git-daemon.sh
> +++ b/t/lib-git-daemon.sh
> @@ -83,7 +83,8 @@ stop_git_daemon() {
>  	wait "$GIT_DAEMON_PID" >&3 2>&4
>  	ret=$?
>  	# expect exit with status 143 = 128+15 for signal TERM=15
> -	if test $ret -ne 143
> +	# or 271 = 256+15 on ksh
> +	if test $ret -ne 143 && test $ret -ne 271

The presence of this patch (on top of the other one) makes me think we
should go with something like:

  test_exit_code_is

or something, and make it available via test-lib-functions.sh.

-Peff

```

## Junio C Hamano, 2016-05-31 23:17

Subject: Re: [PATCH] t0005: ksh93 portability workaround
Message-ID: <xmqqwpm924ya.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqwpm924ya.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <20160531230301.GB4585@sigill.intra.peff.net>

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

> Hmm. We discussed these back in:
>
>   http://thread.gmane.org/gmane.comp.version-control.git/268657
>
> but I thought we decided not to do anything about them (according to
> that thread, I found a bunch of other ksh93 oddities, but maybe we've
> since fixed them?).

OK, I completely forgot about that topic.

Sorry for the noise.  Let's drop it.

Thanks for reminding me of that thread; I would have been stumped
with the "cd ../.git/objects" thing and wasted a lot of time.

```
