]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (test_sysinfo) add a helper to detect NS_GET_USERNS
authorMasatake YAMATO <yamato@redhat.com>
Fri, 20 Sep 2024 20:10:38 +0000 (05:10 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Tue, 1 Oct 2024 17:43:12 +0000 (02:43 +0900)
This can be used to detect qemu-user returning ENOSYS for invalid ioctl
numbers.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/helpers/test_sysinfo.c

index 6447e84134543ab60bda210c8d79352f62f35024..ad423068ba647d54471bb8db38aede6759fa749c 100644 (file)
 #ifdef HAVE_LINUX_NSFS_H
 # include <linux/nsfs.h>
 # if defined(NS_GET_NSTYPE) && defined(NS_GET_OWNER_UID)
-#  define USE_NS_GET_API       1
+#  define USE_NS_GET_NSTYPE    1
+# endif
+# if defined(NS_GET_USERNS)
+#  define USE_NS_GET_USERNS    1
 # endif
 #endif
 
@@ -143,7 +146,7 @@ static int hlp_sz_time(void)
 
 static int hlp_get_nstype_ok(void)
 {
-#ifdef USE_NS_GET_API
+#ifdef USE_NS_GET_NSTYPE
        errno = 0;
        ioctl(STDOUT_FILENO, NS_GET_NSTYPE);
 #else
@@ -153,6 +156,18 @@ static int hlp_get_nstype_ok(void)
        return 0;
 }
 
+static int hlp_get_userns_ok(void)
+{
+#ifdef USE_NS_GET_USERNS
+       errno = 0;
+       ioctl(STDOUT_FILENO, NS_GET_USERNS);
+#else
+       errno = ENOSYS;
+#endif
+       printf("%d\n", errno != ENOSYS);
+       return 0;
+}
+
 static const mntHlpfnc hlps[] =
 {
        { "WORDSIZE",   hlp_wordsize    },
@@ -169,6 +184,7 @@ static const mntHlpfnc hlps[] =
        { "fsopen-ok",  hlp_fsopen_ok   },
        { "sz(time_t)", hlp_sz_time     },
        { "ns-gettype-ok", hlp_get_nstype_ok },
+       { "ns-getuserns-ok", hlp_get_userns_ok },
        { NULL, NULL }
 };