about summary refs log tree commit diff
path: root/tests/common.sh.in
diff options
context:
space:
mode:
authorTuomas Tynkkynen <tuomas@tuxera.com>2018-01-13T13·18+0200
committerTuomas Tynkkynen <tuomas@tuxera.com>2018-01-13T17·08+0200
commit59086e459c2650b7dc42bd2fc4a9a98b23aaf6e7 (patch)
tree7f0d043cc86e0c25c4b923a1471d500d9b313cb9 /tests/common.sh.in
parent74f75c855837bce7f48491e9ce8ac03794e5b40d (diff)
Fix tests using user namespaces on kernels that don't have it
Disable various tests if the kernel doesn't support unprivileged user
namespaces (e.g. Arch Linux disables them) or disable them via a sysctl
(Debian, Ubuntu).

Fixes #1521
Fixes #1625
Diffstat (limited to 'tests/common.sh.in')
-rw-r--r--tests/common.sh.in18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/common.sh.in b/tests/common.sh.in
index 83643d8b06bb..186f9d6b9553 100644
--- a/tests/common.sh.in
+++ b/tests/common.sh.in
@@ -87,6 +87,24 @@ killDaemon() {
     trap "" EXIT
 }
 
+canUseSandbox() {
+    if [[ $(uname) != Linux ]]; then return 1; fi
+
+    if [ ! -L /proc/self/ns/user ]; then
+        echo "Kernel doesn't support user namespaces, skipping this test..."
+        return 1
+    fi
+
+    if [ -e /proc/sys/kernel/unprivileged_userns_clone ]; then
+        if [ "$(cat /proc/sys/kernel/unprivileged_userns_clone)" != 1 ]; then
+            echo "Unprivileged user namespaces disabled by sysctl, skipping this test..."
+            return 1
+        fi
+    fi
+
+    return 0
+}
+
 fail() {
     echo "$1"
     exit 1