From: Karel Zak Date: Wed, 5 Mar 2025 08:53:34 +0000 (+0100) Subject: tests: improve test_sysinfo to check for NS_GET_NSTYPE usability X-Git-Tag: v2.41-rc2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9f8ee6193360b9ffdb8a2cd7804c3e816506a78;p=thirdparty%2Futil-linux.git 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 (cherry picked from commit 4391638806a40b71383646a33ed022476f4c9dea) --- 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