]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (lsns::filter) skip if /proc/self/uid_map is not writable
authorMasatake YAMATO <yamato@redhat.com>
Mon, 6 Jan 2025 08:34:19 +0000 (17:34 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Mon, 6 Jan 2025 18:18:53 +0000 (03:18 +0900)
On some platforms, lsns::filter test failed with the following
message:

   +test_mkfds: failed to write to /proc/self/uid_map: -1: Operation
   not permitted

This change is to skip the test case on such platforms.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/helpers/test_mkfds.c
tests/ts/lsfd/lsfd-functions.bash
tests/ts/lsns/filter

index dfb60ae8ecee9200966187ea0f4e5d5cecc9d172..702f8328a2c0654151c6eb520d5a122b67550488 100644 (file)
@@ -3091,7 +3091,7 @@ static void map_root_user(uid_t uid, uid_t gid)
                    "failed to open /proc/self/uid_map");
        r = write (mapfd, buf, n);
        if (r < 0)
-               err(EXIT_FAILURE,
+               err((errno == EPERM? EXIT_EPERM: EXIT_FAILURE),
                    "failed to write to /proc/self/uid_map");
        if (r != n)
                errx(EXIT_FAILURE,
index 1b2a0ac042ba5a20d2cc354f4ea6708c219d2d48..8bbe31ab1b3ba55abba3a97f923220fb463e269f 100644 (file)
@@ -149,3 +149,23 @@ function lsfd_check_vsock
                ts_failed "failed to use a AF_VSOCK socket: $msg [$err]";;
        esac
 }
+
+function lsfd_check_userns
+{
+       ts_check_test_command "$TS_HELPER_MKFDS"
+
+       local msg
+       local err
+
+       msg=$("$TS_HELPER_MKFDS" -c userns 3 2>&1)
+       err=$?
+
+       case $err in
+           0)
+               return;;
+           "$EPERM")
+               ts_skip "maybe /proc/self/uid_map it not writable";;
+           *)
+               ts_failed "failed to use a AF_VSOCK socket: $msg [$err]";;
+       esac
+}
index a6274b0319bafb10b29b77b1db67e2a73eda8e61..88029680c7dac497526f3596a6539f4f4101f803 100755 (executable)
@@ -31,6 +31,8 @@ ts_check_test_command "$TS_HELPER_MKFDS"
 # unshare(2) used in userns factory of test_mkfds reports "Invalid argument".
 ts_skip_qemu_user
 
+lsfd_check_userns
+
 ts_cd "$TS_OUTDIR"
 PID=
 FD=4