Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: using trap function to cleanup and exit?



Is there an equivalent for exiting when using the trap builtin (list
traps)?  I don't completely understand the manual:

| a return from a list trap causes the surrounding context to return
| with the given status

I've tried both exit and return in a list trap, and am not seeing the
script exit.

Also, is exit intentionally disabled from within a trap function?
I didn't expect that, even with the special return handling.  So,
there is no way to exit 0 from a trap, since that is interpreted as
the signal having been handled, and wanting to continue executing?

With no traps of either type, should the child sleep remain after the
script is killed by a signal?

thank you,
Greg


>>>>> On April 10, 2022 Greg Klanderman <gak@xxxxxxxxxxxxxx> wrote:

> Hi Peter,
> I thought I'd changed that last night when I was reading that section
> of the manual, when I changed the exit value 1 to $(( 128 + $1 )), but
> apparently not.

> That does seem to be working better, in that the script itself does
> exit after running the cleanup, but the child sleep process still
> remains.

> I am playing with 'kill -9 -$$' in the trap function, but that seems
> like an awfully large hammer.

> thank you,
> Greg

>>>>> On April 10, 2022 Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:

>> On Sun, 2022-04-10 at 11:46 -0400, Greg Klanderman wrote:
>>> TRAPTERM () {
>>> echo "in TRAPTERM"
>>> cleanup TERM
>>> exit $(( 128 + $1 ))
>>> }

>> I haven't gone through this in great detail, so no guarantee this causes
>> everything to spring into life, but just to note that normal service
>> here would be obtained if you turn that "exit" into "return".  As
>> described in the Trap Functions in zshmisc, that's specially handled so
>> that the shell knows you want to continue to exit in a similar way to if
>> SIGTERM had been received without the trap function.

>> pws




Messages sorted by: Reverse Date, Date, Thread, Author