[Libguestfs] [PATCH v2 nbdkit 4/5] tests: Use a generic cleanup mechanism instead of explicit trap.
Richard W.M. Jones
rjones at redhat.com
Thu Sep 13 18:50:26 UTC 2018
On Thu, Sep 13, 2018 at 01:00:40PM -0500, Eric Blake wrote:
> On 9/13/18 11:09 AM, Richard W.M. Jones wrote:
> >Thanks: Eric Blake for the suggestion here:
> >https://www.redhat.com/archives/libguestfs/2018-September/msg00069.html
> >---
>
> 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...
I've changed the test to say "function or command".
> >+# 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?
Oops, yes it's a bug (in the existing code actually). Will fix.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html
More information about the Libguestfs
mailing list