Hi, we found quite some inconsistency and weirdness in the handling of SIGINT's during async function calls and were wondering, whether those are expected. All calls were executed from a script with jobcontrol turned off (set +m) while pressing Ctrl+C shortly afterwards. In summary: The main INT handler is never executed in foofunc (is that expected?) while the new (default) handler either aborts command execution in case of 'foofunc &' or continues execution in case of '{ foofunc; } &'. While on 'foofunc &' 'trap -p' at the beginning of foofunc (wrongly) prints the main handler, in case of '{ foofunc; } &' it suddenly prints the ignore handler "trap -- '' SIGINT" and remains indeed uninterruptible. Thus printing the trap apparently changes bash's behavior.
Tested bash versions: GNU bash, Version 5.1.4(1)-release (x86_64-pc-linux-gnu) GNU bash, Version 5.2.2(1)-release (x86_64-pc-linux-gnu) on Debian Bullseye. Thanks and kind regards Tycho ____________________________________ t='echo INT ${FUNCNAME[0]-main} >&2' trap "$t" INT foofunc(){ sleep 3; echo foo >&2; } foofunc & sleep 5 --> INT main # foofunc INT-handler is reset to default ('foo' is not printed). # Note that 'trap -p' within foofunc wrongly prints above INT handler. ____________________________________ t='echo INT ${FUNCNAME[0]-main} >&2' trap "$t" INT foofunc(){ trap "$t" INT; sleep 3; echo foo >&2; } foofunc & sleep 5 --> INT main INT foofunc foo # foofunc custom INT-handler works. ____________________________________ t='echo INT ${FUNCNAME[0]-main} >&2' trap "$t" INT foofunc(){ sleep 3; echo foo >&2; } { foofunc; } & sleep 5 --> INT main foo # Opposing to 'foofunc &' foo _is_ printed so apparently we have a # different default trap handler here. ____________________________________ t='echo INT ${FUNCNAME[0]-main} >&2' trap "$t" INT foofunc(){ trap -p; sleep 3; echo foo >&2; } { foofunc; } & sleep 5 --> trap -- '' SIGINT ^CINT main $ foo # Here, when the trap is printed, INT is reported as "ignored" and foofunc # becomes indeed uninterruptible. So, 'trap -p' changes bash's behavior. ____________________________________