diff options
Diffstat (limited to 'tests/traps.rc')
-rw-r--r-- | tests/traps.rc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/traps.rc b/tests/traps.rc new file mode 100644 index 00000000000..f011960c97e --- /dev/null +++ b/tests/traps.rc @@ -0,0 +1,22 @@ +#!/bin/bash + +# Make sure this only gets included/executed once. Unfortunately, bash doesn't +# usually distinguish between values that are unset and values that are null. +# To work around that, we declare TRAPFUNCS to be a one-element array right at +# the start, but that one element is : which is defined to do nothing. + +if [ ${#TRAPFUNCS[@]} = 0 ]; then + TRAPFUNCS=(:) + + push_trapfunc () { + TRAPFUNCS[${#TRAPFUNCS[@]}]="$@" + } + + execute_trapfuncs () { + for i in "${TRAPFUNCS[@]}"; do + $i + done + } + + trap execute_trapfuncs EXIT +fi |