From: Masatake YAMATO Date: Fri, 20 Sep 2024 20:10:38 +0000 (+0900) Subject: tests: (test_sysinfo) add a helper to detect NS_GET_USERNS X-Git-Tag: v2.42-start~184^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=45b5ad380df387fa303c7ca08b73f6e42b2393cd;p=thirdparty%2Futil-linux.git tests: (test_sysinfo) add a helper to detect NS_GET_USERNS This can be used to detect qemu-user returning ENOSYS for invalid ioctl numbers. Signed-off-by: Masatake YAMATO --- diff --git a/tests/helpers/test_sysinfo.c b/tests/helpers/test_sysinfo.c index 6447e8413..ad423068b 100644 --- a/tests/helpers/test_sysinfo.c +++ b/tests/helpers/test_sysinfo.c @@ -36,7 +36,10 @@ #ifdef HAVE_LINUX_NSFS_H # include # 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 } };