On Wed, Apr 13, 2022 at 10:58 PM Greg Klanderman wrote: > > The script I posted is using /bin/zsh -f, so TRAPS_ASYNC should be > off, but I do see a trap run immediately, when the script is running > > | > > at the time the signal is received. > > Is the considered a foreground child? No, it's in the background; zsh "forks to the left" so that the is running in the current shell. This is the reverse of bash/ksh. (In recent zsh, when emulating sh, both sides of the pipe may be forked.) > When TRAPTERM uses 'exit' rather than 'return', the script does not > exit after receiving SIGTERM. OK, this is indeed a bug, previously discussed in workers/44007 and follow-ups. More on this below. > With 'return', the script does exit, > but the in > > | > > remains running. This is actually expected, I believe; as noted above, is a background job here, and it would normally be expected to exit on SIGPIPE when the exits and closes the connection. It never gets that signal because it never writes anything on the pipe. Regarding workers/44007: This seems ultimately to be a side-effect described by this comment: * We don't exit directly from functions to allow tidying * up, in particular EXIT traps. We still need to perform * the usual interactive tests to see if we can exit at * all, however. In bin_break(), which handles both "return" and "exit", the conditions applied upon "return" are not the same as those applied upon "exit". With the builtin.c hunk of the patch below "make check" reports: Test ./C03traps.ztst was expected to fail, but passed. Was testing: (workers/44007) function execution continues after 'exit' in trap I've therefore included cleaning up the BUGS file and reversing the sense of that test, but would prefer that another set of eyes review the code change.