1#! /shell/bug/test/for/moderni/sh
2# See the file LICENSE in the main modernish directory for the licence.
3
4# BUG_TRAPUNSRE: When a trap UNSets itself and then REsends its own signal,
5# the execution of the trap action (including functions called by it) is
6# not interrupted by the now-untrapped signal; instead, the process
7# terminates after completing the entire trap routine.
8#
9# Bug found on: bash <= 4.2; zsh
10# Ref.: http://www.zsh.org/mla/workers/2019/msg00958.html
11
12{ _Msh_test=$(
13	# Store this subshell's PID in $REPLY.
14	insubshell -p
15	# In case some signal is ignored, try several.
16	for _Msh_sig in ALRM HUP INT PIPE POLL PROF TERM USR1 USR2 VTALRM; do
17		command trap "\
18			putln trap
19			command trap - ${_Msh_sig}
20			command kill -s ${_Msh_sig} $REPLY
21			putln stillhere
22		" "${_Msh_sig}"
23		str begin "${ZSH_VERSION:-}" 5.0. && set -x # TODO: remove when unsupporting zsh 5.0.8
24		command kill -s "${_Msh_sig}" "$REPLY"
25	done
26); } 2>/dev/null
27
28case ${_Msh_test} in
29( trap${CCn}stillhere ) ;;
30( * ) return 1 ;;
31esac
32