]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: improve test_sysinfo to check for NS_GET_NSTYPE usability
authorKarel Zak <kzak@redhat.com>
Wed, 5 Mar 2025 08:53:34 +0000 (09:53 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 5 Mar 2025 08:53:34 +0000 (09:53 +0100)
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 <kzak@redhat.com>
tests/helpers/test_sysinfo.c

index 7cda1178f9351a7e83617b71a0db41c9876c90c2..9f9f0fd0f9f15f728e8688ed4b108a1cd1274886 100644 (file)
@@ -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