On 01/13/2012 03:05 PM, Ryan Harper wrote:
> Create a cleanup function and call it from all exits so we don't leave
> temp files and directories around since we change the name on each invocation.
> 
> Also,  no need to delete the files in the tmpdir, so just remove the tmpdir
> if it exists.
> 
> Signed-off-by: Ryan Harper <ry...@us.ibm.com>
> ---
>  qemu-test |   11 +++++++++--
>  1 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/qemu-test b/qemu-test
> index cd102a7..71c1ba1 100755
> --- a/qemu-test
> +++ b/qemu-test
> @@ -1,7 +1,14 @@
>  #!/bin/sh
>  
> +cleanup() {
> +    if test -n "$tmpdir"; then
> +    rm -rf $tmpdir;
> +    fi
> +}
> +
>  if test -z "$1" -o -z "$2"; then
>      echo "Usage: $0 QEMU TEST1 [TEST2 ...]"
> +    cleanup
>      exit 1

Is it worth using 'trap cleanup 0' to install the cleanup handler up
front, instead of modifying all exit call sites?

-- 
Eric Blake   ebl...@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to