common/config: implement set_prog_path() using 'type -P'
[xfstests-dev.git] / common / config
index fb60216ceb94be257c488825f6ace369b9dcabee..8211356c385fc284c5ac3246a63c92dc4b46bff0 100644 (file)
@@ -35,6 +35,7 @@
 # RMT_TAPE_DEV -    the remote tape device for the xfsdump tests
 # RMT_IRIXTAPE_DEV- the IRIX remote tape device for the xfsdump tests
 # RMT_TAPE_USER -   remote user for tape device
+# SELINUX_MOUNT_OPTIONS - Options to use when SELinux is enabled.
 #
 # - These can be added to $HOST_CONFIG_DIR (witch default to ./config)
 #   below or a separate local configuration file can be used (using
@@ -92,26 +93,10 @@ export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes}
 
 export RECREATE_TEST_DEV=false
 
-# $1 = prog to look for, $2* = default pathnames if not found in $PATH
+# $1 = prog to look for
 set_prog_path()
 {
-    p=`which $1 2> /dev/null`
-    if [ -n "$p" -a -x "$p" ]; then
-        echo $p
-        return 0
-    fi
-    p=$1
-
-    shift
-    for f; do
-        if [ -x $f ]; then
-            echo $f
-            return 0
-        fi
-    done
-
-    echo ""
-    return 1
+       type -P $1
 }
 
 # Handle mkfs.btrfs which does (or does not) require -f to overwrite
@@ -259,10 +244,16 @@ case "$HOSTOS" in
 esac
 
 # SELinux adds extra xattrs which can mess up our expected output.
-# So, mount with a context, and they won't be created
-# # nfs_t is a "liberal" context so we can use it.
+# So, mount with a context, and they won't be created.
+#
+# Since the context= option only accepts contexts defined in the SELinux
+# policy, and different systems may have different policies with
+# different context names, use the context of an existing directory.
+# Assume that any valid context is fine, since xfstests should really
+# only be run from an "unconfined" process, or with SELinux in permissive
+# mode.  But if not, just specify your own SELINUX_MOUNT_OPTIONS.
 if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
-       SELINUX_MOUNT_OPTIONS="-o context=system_u:object_r:nfs_t:s0"
+       : ${SELINUX_MOUNT_OPTIONS:="-o context=$(stat -c %C /)"}
        export SELINUX_MOUNT_OPTIONS
 fi
 
@@ -300,6 +291,9 @@ _mount_opts()
        ceph)
                export MOUNT_OPTIONS=$CEPHFS_MOUNT_OPTIONS
                ;;
+       glusterfs)
+               export MOUNT_OPTIONS=$GLUSTERFS_MOUNT_OPTIONS
+               ;;
        overlay)
                export MOUNT_OPTIONS=$OVERLAY_MOUNT_OPTIONS
                ;;
@@ -340,6 +334,12 @@ _test_mount_opts()
        ceph)
                export TEST_FS_MOUNT_OPTS=$CEPHFS_MOUNT_OPTIONS
                ;;
+       nfs)
+               export TEST_FS_MOUNT_OPTS=$NFS_MOUNT_OPTIONS
+               ;;
+       glusterfs)
+               export TEST_FS_MOUNT_OPTS=$GLUSTERFS_MOUNT_OPTIONS
+               ;;
        *)
                ;;
        esac