Remove the tmp file when exiting. Noticed by Arjan van de Ven. Catch mktemp failure and exit with message. Trap kill or other signals and exit cleanly.
Showing the changes to scripts/decodecode (1 of 1 file). Show all
Unified · Split
| @@ -6,7 +6,19 @@ · 5 unmodified lines | ||
| 6 | 6 | # e.g., to decode an i386 oops on an x86_64 system, use: |
| 7 | 7 | # AFLAGS=--32 decodecode < 386.oops |
| 8 | 8 | |
| 9 | −T=`mktemp` | |
| 9 | +cleanup() { | |
| 10 | + rm -f $T $T.s $T.o | |
| 11 | + exit 1 | |
| 12 | +} | |
| 13 | + | |
| 14 | +die() { | |
| 15 | + echo "$@" | |
| 16 | + exit 1 | |
| 17 | +} | |
| 18 | + | |
| 19 | +trap cleanup EXIT | |
| 20 | + | |
| 21 | +T=`mktemp` || die "cannot create temp file" | |
| 10 | 22 | code= |
| 11 | 23 | |
| 12 | 24 | while read i ; do |
| @@ -20,6 +32,7 @@ esac · 7 unmodified lines | ||
| 20 | 32 | done |
| 21 | 33 | |
| 22 | 34 | if [ -z "$code" ]; then |
| 35 | + rm $T | |
| 23 | 36 | exit |
| 24 | 37 | fi |
| 25 | 38 | |
| @@ -48,4 +61,4 @@ echo -n " .byte 0x" > $T.s · 22 unmodified lines | ||
| 48 | 61 | echo $code >> $T.s |
| 49 | 62 | as $AFLAGS -o $T.o $T.s |
| 50 | 63 | objdump -S $T.o |
| 51 | −rm $T.o $T.s | |
| 64 | +rm $T $T.s $T.o | |