From 4391638806a40b71383646a33ed022476f4c9dea Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 5 Mar 2025 09:53:34 +0100 Subject: [PATCH] tests: improve test_sysinfo to check for NS_GET_NSTYPE usability Now the test checks if the kernel supports the NS_GET_NSTYPE ioctl, but it seems that on some platforms it's implemented but does not work as expected and returns ENOTTY. Signed-off-by: Karel Zak --- tests/helpers/test_sysinfo.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/helpers/test_sysinfo.c b/tests/helpers/test_sysinfo.c index 7cda1178f..9f9f0fd0f 100644 --- a/tests/helpers/test_sysinfo.c +++ b/tests/helpers/test_sysinfo.c @@ -46,6 +46,7 @@ #endif #include "xalloc.h" +#include "namespace.h" typedef struct { const char *name; @@ -176,8 +177,21 @@ static int hlp_sz_time(void) static int hlp_get_nstype_ok(void) { #ifdef USE_NS_GET_NSTYPE + int fd = open("/proc/self/ns/mnt", O_RDONLY); + errno = 0; - ioctl(STDOUT_FILENO, NS_GET_NSTYPE); + if (fd >= 0) { + int errsv = 0; + + /* Check for actual usability */ + if (ioctl(fd, NS_GET_NSTYPE) != CLONE_NEWNS) + errsv = ENOSYS; + close(fd); + errno = errsv; + } else { + /* Generic check for ENOSYS only */ + ioctl(STDOUT_FILENO, NS_GET_NSTYPE); + } #else errno = ENOSYS; #endif -- 2.47.3