[PATCH] selftests/proc: stop depending on glibc for the mount API
From: Qingshuang Fu
Date: Thu Nov 19 2026 - 22:30:22 EST
proc-pidns.c calls fsopen(), fsconfig() and fsmount() directly and uses
the FSOPEN_CLOEXEC, FSCONFIG_* and FSMOUNT_CLOEXEC definitions. glibc
only grew declarations for these functions in 2.36 and does not provide
the related constants at all, so older toolchains fail to build the
test:
proc-pidns.c:118:28: error: 'FSOPEN_CLOEXEC' undeclared
(first use in this function)
Switch to the sys_fsopen(), sys_fsconfig() and sys_fsmount() wrappers
from filesystems/wrappers.h, the same approach already used by the
mount_setattr test. The wrappers issue the same syscalls directly and
pull in <linux/mount.h>, which the proc Makefile already provides via
$(TOOLS_INCLUDES).
Fixes: 5554d820f71c ("selftests/proc: add tests for new pidns APIs")
Signed-off-by: Qingshuang Fu <fuqingshuang@xxxxxxxxxx>
---
tools/testing/selftests/proc/proc-pidns.c | 39 ++++++++++++-----------
1 file changed, 21 insertions(+), 18 deletions(-)
diff --git a/tools/testing/selftests/proc/proc-pidns.c b/tools/testing/selftests/proc/proc-pidns.c
index 6f7c10fe97b3..00ca9ccb5a83 100644
--- a/tools/testing/selftests/proc/proc-pidns.c
+++ b/tools/testing/selftests/proc/proc-pidns.c
@@ -17,6 +17,7 @@
#include <sys/stat.h>
#include <sys/prctl.h>
+#include "../filesystems/wrappers.h"
#include "kselftest_harness.h"
#define ASSERT_ERRNO(expected, _t, seen) \
@@ -115,13 +116,13 @@ TEST_F(ns, pidns_mount_string_path)
TEST_F(ns, pidns_fsconfig_string_path)
{
- int fsfd = fsopen("proc", FSOPEN_CLOEXEC);
+ int fsfd = sys_fsopen("proc", FSOPEN_CLOEXEC);
ASSERT_SUCCESS(fsfd);
- ASSERT_SUCCESS(fsconfig(fsfd, FSCONFIG_SET_STRING, "pidns", "/tmp/dummy/pidns", 0));
- ASSERT_SUCCESS(fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
+ ASSERT_SUCCESS(sys_fsconfig(fsfd, FSCONFIG_SET_STRING, "pidns", "/tmp/dummy/pidns", 0));
+ ASSERT_SUCCESS(sys_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
- int mountfd = fsmount(fsfd, FSMOUNT_CLOEXEC, 0);
+ int mountfd = sys_fsmount(fsfd, FSMOUNT_CLOEXEC, 0);
ASSERT_SUCCESS(mountfd);
ASSERT_ERRNO_EQ(-ENOENT, faccessat(mountfd, "1/", X_OK, 0));
@@ -133,13 +134,13 @@ TEST_F(ns, pidns_fsconfig_string_path)
TEST_F(ns, pidns_fsconfig_fd)
{
- int fsfd = fsopen("proc", FSOPEN_CLOEXEC);
+ int fsfd = sys_fsopen("proc", FSOPEN_CLOEXEC);
ASSERT_SUCCESS(fsfd);
- ASSERT_SUCCESS(fsconfig(fsfd, FSCONFIG_SET_FD, "pidns", NULL, self->dummy_pidns));
- ASSERT_SUCCESS(fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
+ ASSERT_SUCCESS(sys_fsconfig(fsfd, FSCONFIG_SET_FD, "pidns", NULL, self->dummy_pidns));
+ ASSERT_SUCCESS(sys_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
- int mountfd = fsmount(fsfd, FSMOUNT_CLOEXEC, 0);
+ int mountfd = sys_fsmount(fsfd, FSMOUNT_CLOEXEC, 0);
ASSERT_SUCCESS(mountfd);
ASSERT_ERRNO_EQ(-ENOENT, faccessat(mountfd, "1/", X_OK, 0));
@@ -165,19 +166,20 @@ TEST_F(ns, pidns_reconfigure_remount)
TEST_F(ns, pidns_reconfigure_fsconfig_string_path)
{
- int fsfd = fsopen("proc", FSOPEN_CLOEXEC);
+ int fsfd = sys_fsopen("proc", FSOPEN_CLOEXEC);
ASSERT_SUCCESS(fsfd);
- ASSERT_SUCCESS(fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
+ ASSERT_SUCCESS(sys_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
- int mountfd = fsmount(fsfd, FSMOUNT_CLOEXEC, 0);
+ int mountfd = sys_fsmount(fsfd, FSMOUNT_CLOEXEC, 0);
ASSERT_SUCCESS(mountfd);
ASSERT_SUCCESS(faccessat(mountfd, "1/", X_OK, 0));
ASSERT_SUCCESS(faccessat(mountfd, "self/", X_OK, 0));
- ASSERT_ERRNO_EQ(-EBUSY, fsconfig(fsfd, FSCONFIG_SET_STRING, "pidns", "/tmp/dummy/pidns", 0));
- ASSERT_SUCCESS(fsconfig(fsfd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0)); /* noop */
+ ASSERT_ERRNO_EQ(-EBUSY, sys_fsconfig(fsfd, FSCONFIG_SET_STRING,
+ "pidns", "/tmp/dummy/pidns", 0));
+ ASSERT_SUCCESS(sys_fsconfig(fsfd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0)); /* noop */
ASSERT_SUCCESS(faccessat(mountfd, "1/", X_OK, 0));
ASSERT_SUCCESS(faccessat(mountfd, "self/", X_OK, 0));
@@ -188,19 +190,20 @@ TEST_F(ns, pidns_reconfigure_fsconfig_string_path)
TEST_F(ns, pidns_reconfigure_fsconfig_fd)
{
- int fsfd = fsopen("proc", FSOPEN_CLOEXEC);
+ int fsfd = sys_fsopen("proc", FSOPEN_CLOEXEC);
ASSERT_SUCCESS(fsfd);
- ASSERT_SUCCESS(fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
+ ASSERT_SUCCESS(sys_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
- int mountfd = fsmount(fsfd, FSMOUNT_CLOEXEC, 0);
+ int mountfd = sys_fsmount(fsfd, FSMOUNT_CLOEXEC, 0);
ASSERT_SUCCESS(mountfd);
ASSERT_SUCCESS(faccessat(mountfd, "1/", X_OK, 0));
ASSERT_SUCCESS(faccessat(mountfd, "self/", X_OK, 0));
- ASSERT_ERRNO_EQ(-EBUSY, fsconfig(fsfd, FSCONFIG_SET_FD, "pidns", NULL, self->dummy_pidns));
- ASSERT_SUCCESS(fsconfig(fsfd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0)); /* noop */
+ ASSERT_ERRNO_EQ(-EBUSY, sys_fsconfig(fsfd, FSCONFIG_SET_FD, "pidns",
+ NULL, self->dummy_pidns));
+ ASSERT_SUCCESS(sys_fsconfig(fsfd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0)); /* noop */
ASSERT_SUCCESS(faccessat(mountfd, "1/", X_OK, 0));
ASSERT_SUCCESS(faccessat(mountfd, "self/", X_OK, 0));
--
2.25.1