Re: [PATCH] selftests/proc: skip fd-003-kthread if run as non-root
From: Qingshuang Fu
Date: Wed Nov 25 2026 - 02:49:13 EST
在 2026/11/25 14:33, Andrew Morton 写道:
Fair enough.
--- a/tools/testing/selftests/proc/fd-003-kthread.c
+++ b/tools/testing/selftests/proc/fd-003-kthread.c
@@ -36,6 +36,7 @@
*
* Return /proc/$PID/fd descriptor if process is kernel thread.
* Return -1 if a process is userspace process.
+ * Return -EACCES if run as non-root.
*/
static int kernel_thread_fd(unsigned int pid)
{
@@ -88,6 +89,8 @@ static int kernel_thread_fd(unsigned int pid)
fd = -1;
if (flags & PF_KHTREAD) {
fd = openat(dir_fd, "fd", O_RDONLY|O_DIRECTORY);
+ if (fd == -1 && errno == EACCES)
+ fd = -EACCES;
}
close(dir_fd);
return fd;
@@ -168,6 +171,8 @@ int main(void)
pid++;
}
/* EACCES if run as non-root. */
+ if (fd == -EACCES)
+ return 4;
if (pid >= 1024)
return 1;
Why "4"?
4 is KSFT_SKIP. The convention in selftests/proc is a bare "return 4"
on skip paths -- 9 tests do it, e.g.:
proc-loadavg-001.c:32
proc-net-dev-lseek.c:35
proc-self-syscall.c:40
proc-self-wchan.c:30
setns-dcache.c:56
setns-sysvipc.c:55
Notably proc-pid-vm.c includes kselftest.h and still returns a bare
4 at the end of main(). So the bare 4 just follows the directory's
existing style.
(and why didn't they call it EACCESS. Also s/creat/create/)
Ha. Renaming it now would break 50 years of userspace, but I agree
the historical spelling is unfortunate.
--
Qingshuang Fu