Re: [PATCH V2] selinux-testsuite: Allow nfs test script to close cleanly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Feb 21, 2020 at 8:18 AM Richard Haines
<richard_c_haines@xxxxxxxxxxxxxx> wrote:
>
> Whenever a failure, close NFS cleanly.
>
> Signed-off-by: Richard Haines <richard_c_haines@xxxxxxxxxxxxxx>

I'm not much of a shell programmer but this looks good to me.

Acked-by: Stephen Smalley <sds@xxxxxxxxxxxxx>

> ---
> V2 Changes:
> Revamp error handling to cover all cases
>
>  tools/nfs.sh | 27 +++++++++++++++++++++++----
>  1 file changed, 23 insertions(+), 4 deletions(-)
>
> diff --git a/tools/nfs.sh b/tools/nfs.sh
> index 314f898..7ba4cfc 100755
> --- a/tools/nfs.sh
> +++ b/tools/nfs.sh
> @@ -1,14 +1,33 @@
>  #!/bin/sh -e
>  MOUNT=`stat --print %m .`
>  TESTDIR=`pwd`
> -systemctl start nfs-server
> +MAKE_TEST=0
> +
> +function err_exit() {
> +    if [ $MAKE_TEST -eq 1 ]; then
> +        echo "Closing down NFS"
> +        popd
> +    else
> +        echo "Error on line: $1 - Closing down NFS"
> +    fi
> +    umount /mnt/selinux-testsuite
> +    exportfs -u localhost:$MOUNT
> +    rmdir /mnt/selinux-testsuite
> +    systemctl stop nfs-server
> +    exit 1
> +}
> +
> +trap 'err_exit $LINENO' ERR
>
> +systemctl start nfs-server
>  # Run the full testsuite on a labeled NFS mount.
>  exportfs -orw,no_root_squash,security_label localhost:$MOUNT
>  mkdir -p /mnt/selinux-testsuite
>  mount -t nfs -o vers=4.2 localhost:$TESTDIR /mnt/selinux-testsuite
>  pushd /mnt/selinux-testsuite
> +MAKE_TEST=1
>  make test
> +MAKE_TEST=0
>  popd
>  umount /mnt/selinux-testsuite
>
> @@ -18,7 +37,7 @@ echo "Testing context mount of a security_label export."
>  fctx=`secon -t -f /mnt/selinux-testsuite`
>  if [ "$fctx" != "etc_t" ]; then
>      echo "Context mount failed: got $fctx instead of etc_t."
> -    exit 1
> +    err_exit $LINENO
>  fi
>  umount /mnt/selinux-testsuite
>  exportfs -u localhost:$MOUNT
> @@ -30,7 +49,7 @@ echo "Testing context mount of a non-security_label export."
>  fctx=`secon -t -f /mnt/selinux-testsuite`
>  if [ "$fctx" != "etc_t" ]; then
>      echo "Context mount failed: got $fctx instead of etc_t."
> -    exit 1
> +    err_exit $LINENO
>  fi
>  umount /mnt/selinux-testsuite
>
> @@ -40,7 +59,7 @@ echo "Testing non-context mount of a non-security_label export."
>  fctx=`secon -t -f /mnt/selinux-testsuite`
>  if [ "$fctx" != "nfs_t" ]; then
>      echo "Context mount failed: got $fctx instead of nfs_t."
> -    exit 1
> +    err_exit $LINENO
>  fi
>  umount /mnt/selinux-testsuite
>
> --
> 2.24.1
>



[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux