On 20 Nov 2007 15:43:02 -0800 Icarus Sparry wrote:
> You might find this web page interesting; it discusses what various
> shells do when given sigint.
> http://www.cons.org/cracauer/sigint.html
thanks
the fix we have in place works like the WCE case in that url
but the regression test for the fix shows that WCE has sub-cases
that further differentiate shell implementations
one of the differences is an inconsistency that ksh93 will not replicate:
if a parent traps SIGINT and the child process catches SIGINT and exits
normally then the parent SIGINT trap is not called
(some shell implementations call the parent SIGINT trap in this case)
why is that inconsistent?
if the parent does not have a SIGINT trap then those same shell
implementation do not take the default SIGINT action and instead ignore SIGINT
here is the standalone part of the regression tests that runs the
test on a list of shell implementations
run this snippet in a separate dir
it creates 4 scripts { tst tst-1 tst-2 tst-3 }
---cut---
cat > tst <<'!'
# shell trap tests
#
# tst control script that calls tst-1
# tst-1 calls tst-2
# tst-2 calls tst-3
# tst-3 defaults or handles and discards/propagates SIGINT
#
# initial -v option lists script entry and SIGINT delivery
#
# three test options
#
# d call next script directly, otherwise via $SHELL -c
# t trap, echo, and kill self on SIGINT, otherwise x or SIGINT default if
no x
# x trap, echo on SIGINT, and exit 0, otherwise SIGINT default
#
# Usage: tst [-v] [-options] shell-to-test ...
set -o monitor || exit 1
function gen
{
typeset o t x d
for x in - x
do case $x in
[$1]) for t in - t
do case $t in
[$1]) for d in - d
do case $d in
[$1]) o="$o $x$t$d"
esac
done
esac
done
esac
done
echo '' $o
}
case $1 in
-v) v=v; shift ;;
-*v*) v=v ;;
*) v= ;;
esac
case $1 in
*' '*) o=$1; shift ;;
-*) o=$(gen $1); shift ;;
*) o=$(gen -txd) ;;
esac
case $# in
0) set ksh bash ksh88 pdksh ash zsh ;;
esac
for f in $o
do case $# in
1) ;;
*) echo ;;
esac
for sh
do if $sh -c 'exit 0' > /dev/null 2>&1
then case $# in
1) printf '%3s ' "$f" ;;
*) printf '%16s %3s ' "$sh" "$f" ;;
esac
$sh tst-1 $v$f $sh > tst.out &
wait
echo $(cat tst.out)
fi
done
done
case $# in
1) ;;
*) echo ;;
esac
!
cat > tst-1 <<'!'
exec 2>/dev/null
case $1 in
*v*) echo 1-main ;;
esac
{
sleep 2
case $1 in
*v*) echo "SIGINT" ;;
esac
kill -s INT 0
} &
case $1 in
*t*) trap '
echo 1-intr
trap - INT
# omitting the self kill exposes shells that deliver
# the SIGINT trap but exit 0 for -xt
# kill -s INT $$
' INT
;;
esac
case $1 in
*d*) tst-2 $1 $2; status=$? ;;
*) $2 -c "tst-2 $1 $2"; status=$? ;;
esac
printf '1-%04d\n' $status
sleep 2
!
cat > tst-2 <<'!'
case $1 in
*x*) trap '
echo 2-intr
exit
' INT
;;
*t*) trap '
echo 2-intr
trap - INT
kill -s INT $$
' INT
;;
esac
case $1 in
*v*) echo 2-main ;;
esac
case $1 in
*d*) tst-3 $1 $2; status=$? ;;
*) $2 -c "tst-3 $1 $2"; status=$? ;;
esac
printf '2-%04d\n' $status
!
cat > tst-3 <<'!'
case $1 in
*x*) trap '
sleep 2
echo 3-intr
exit 0
' INT
;;
*) trap '
sleep 2
echo 3-intr
trap - INT
kill -s INT $$
' INT
;;
esac
case $1 in
*v*) echo 3-main ;;
esac
sleep 5
printf '3-%04d\n' $?
!
chmod +x tst tst-?
---cut---
here is the output on linux.i386-64 for
tst -tx ksh ksh-2007-11-05 bash ksh88 pdksh ash zsh
where ksh has the (to be posted tomorrow) fix and
ksh-2007-11-05 does not have the fix
note that some shells use 256+signal to denote exit due to signal
this cannot clash with user exit values which are limited to 0 - 255
ksh --- 3-intr
ksh-2007-11-05 ---
bash --- 3-intr
ksh88 --- 3-intr
pdksh ---
ash --- 3-intr
zsh ---
ksh -t- 3-intr 2-intr 1-intr 1-0258
ksh-2007-11-05 -t- 3-intr 2-intr 1-intr 1-0258
bash -t- 3-intr 2-intr 1-intr 1-0130
ksh88 -t- 3-intr 2-intr 1-intr 1-0130
pdksh -t- 3-intr 2-intr 1-intr 1-0258
ash -t- 3-intr 2-intr 1-intr 1- 130
zsh -t- 1-intr 3-intr 2-intr 1-0001
ksh x-- 3-intr 2-0000 1-0000
ksh-2007-11-05 x--
bash x-- 3-intr 2-intr 1-0000
ksh88 x-- 3-intr 2-intr
pdksh x--
ash x-- 3-intr 2-intr
zsh x--
ksh xt- 3-intr 2-0000 1-0000
ksh-2007-11-05 xt- 3-intr 2-intr 1-intr 1-0000
bash xt- 3-intr 2-intr 1-intr 1-0000
ksh88 xt- 3-intr 2-intr 1-intr 1-0000
pdksh xt- 3-intr 2-intr 1-intr 1-0000
ash xt- 3-intr 2-intr 1-intr 1- 130
zsh xt- 1-intr 3-intr 2-0000 1-0001
-- Glenn Fowler -- AT&T Research, Florham Park NJ --
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users