Skip to content

Commit 8cfbccb

Browse files
committed
tests: integration: add helper to check if we're in a userns
Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 8bebdba commit 8cfbccb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tests/integration/helpers.bash

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@ function rootless_cgroup() {
368368
[[ "$ROOTLESS_FEATURES" == *"cgroup"* || -v RUNC_USE_SYSTEMD ]]
369369
}
370370

371+
function in_userns() {
372+
# The kernel guarantees the root userns inode number (and thus the value of
373+
# the magic-link) is always the same value (PROC_USER_INIT_INO).
374+
[[ "$(readlink /proc/self/ns/user)" != "user:[$((0xEFFFFFFD))]" ]]
375+
}
376+
371377
# Check if criu is available and working.
372378
function have_criu() {
373379
command -v criu &>/dev/null || return 1
@@ -396,7 +402,7 @@ function requires() {
396402
fi
397403
;;
398404
root)
399-
if [ $EUID -ne 0 ]; then
405+
if [ $EUID -ne 0 ] || in_userns; then
400406
skip_me=1
401407
fi
402408
;;

0 commit comments

Comments
 (0)