[Vm-dev] [commit][2966] Add exit traps to the linux build scripts

Eliot Miranda eliot.miranda at gmail.com
Tue Jun 10 23:14:34 UTC 2014


On Mon, Jun 9, 2014 at 6:12 PM, gettimothy <gettimothy at zoho.com> wrote:

>
> What is an "exit trap" ? Cleanup on fail?
>

It can do, yes.  But what it does is cause the script to exit.  If you're
looping over other scripts, as in

        #!/bin/bash
        for d in newspeak.cog.* newspeak.stack.* squeak.*; do
                if test -d "$d"; then
                        (cd $d;./makeallclean)
                else
                        echo no $d directory found
                fi
        done

and you hit control-C halfway through then the control-C will simply kill
the inner script, and the outer script will continue runnign, invoking the
next script in the list.  So one ends up hitting control-C in some demented
fashion until every script has been killed.

Add an exit trap though:

        #!/bin/bash
        trap 'exit 2' HUP INT PIPE TERM 0
        for d in newspeak.cog.* newspeak.stack.* squeak.*; do
                if test -d "$d"; then
                        (cd $d;./makeallclean)
                else
                        echo no $d directory found
                fi
        done

and the script will catch the ctrl-C and exit immediately.  And you can
indeed add cleanup actions, e.g. from a script for diffing cr-line-ending
files:

        Ftmp=/tmp/`basename "$2"`.$$
        trap 'rm -f "$Ftmp" 2>/dev/null; exit 2' HUP INT PIPE TERM 0
        if [ ! -f "$2" ]; then
            echo $0: $2: No such file.
            exit 1
        fi
        tr \\015 \\012 <"$2" >"$Ftmp"
        ...

That is the first time I have seen that term.
>

It might not be the right term, but hopefully you get what I mean :-)


> thx.
>
> tty
>

-- 
best,
Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20140610/b136a5bb/attachment.htm


More information about the Vm-dev mailing list