From 59086e459c2650b7dc42bd2fc4a9a98b23aaf6e7 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Sat, 13 Jan 2018 15:18:35 +0200 Subject: 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 --- tests/common.sh.in | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/common.sh.in') 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 -- cgit 1.4.1