Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: pidfd: skip test if unshare fails with EPERM

Similar to how ENOSYS causes a skip if pidfd_send_signal is not present,
we can do the same for unshare if it fails with EPERM. This way, running
the test without privileges causes four tests to skip but no early bail out.

Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Paolo Bonzini and committed by
Shuah Khan
05790fd7 bb91c0ca

+16 -5
+16 -5
tools/testing/selftests/pidfd/pidfd_test.c
··· 162 162 } 163 163 164 164 ret = unshare(CLONE_NEWPID); 165 - if (ret < 0) 165 + if (ret < 0) { 166 + if (errno == EPERM) { 167 + ksft_test_result_skip("%s test: Unsharing pid namespace not permitted\n", 168 + test_name); 169 + return 0; 170 + } 166 171 ksft_exit_fail_msg("%s test: Failed to unshare pid namespace\n", 167 172 test_name); 173 + } 168 174 169 175 ret = unshare(CLONE_NEWNS); 170 - if (ret < 0) 171 - ksft_exit_fail_msg( 172 - "%s test: Failed to unshare mount namespace\n", 173 - test_name); 176 + if (ret < 0) { 177 + if (errno == EPERM) { 178 + ksft_test_result_skip("%s test: Unsharing mount namespace not permitted\n", 179 + test_name); 180 + return 0; 181 + } 182 + ksft_exit_fail_msg("%s test: Failed to unshare mount namespace\n", 183 + test_name); 184 + } 174 185 175 186 ret = mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0); 176 187 if (ret < 0)