On 9/13/18 11:09 AM, Richard W.M. Jones wrote:
I'm glad the idea worked!
+# cleanup_fn f [args]
+#
+# A generic trap handling function. This runs the function f + args
Not just functions, but any command name...
+# when the script exits for any reason.
+declare -a _cleanup_hook
+cleanup_fn ()
+{
+ _cleanup_hook[${#_cleanup_hook[@]}]="$@"
+}
+++ b/tests/test-zero.sh
@@ -31,6 +31,7 @@
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
+source ./functions.sh
set -x
set -e
@@ -42,18 +43,7 @@ fi
files="test-zero.out"
rm -f $files
-
-cleanup ()
-{
- status=$?
- trap '' INT QUIT TERM EXIT ERR
- echo $0: cleanup: exit code $status
-
- rm $files
-
- exit $status
-}
-trap cleanup INT QUIT TERM EXIT ERR
+cleanup_fn rm $files
...as evidenced by this conversion. Pre-existing, but you could fix it
while here: why is this not using 'rm -f' like all the other cleanups?
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization:
qemu.org |
libvirt.org