]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (test_mkfds) add ppoll multiplexer
authorMasatake YAMATO <yamato@redhat.com>
Sun, 30 Jul 2023 09:03:03 +0000 (18:03 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Mon, 11 Sep 2023 11:19:42 +0000 (20:19 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
meson.build
tests/helpers/Makemodule.am
tests/helpers/test_mkfds.c
tests/helpers/test_mkfds.h
tests/helpers/test_mkfds_ppoll.c [new file with mode: 0644]

index d077fef06e1817de7a9ed14ca5a68f03d84bc8cd..fcab1732d78c8d13900358ee59e63931da21d3f0 100644 (file)
@@ -3385,6 +3385,7 @@ if LINUX
     'test_mkfds',
     'tests/helpers/test_mkfds.c',
     'tests/helpers/test_mkfds.h',
+    'tests/helpers/test_mkfds_ppoll.c',
     include_directories : includes,
     dependencies : mq_libs,
     build_by_default: program_tests)
index 00a32c8159127a656576bd6b93ffd12c30d9b332..860d72f0f674c0c3258e17e164d72a5f5a100010 100644 (file)
@@ -33,7 +33,8 @@ test_uuid_namespace_SOURCES = tests/helpers/test_uuid_namespace.c \
 
 if LINUX
 check_PROGRAMS += test_mkfds
-test_mkfds_SOURCES = tests/helpers/test_mkfds.c tests/helpers/test_mkfds.h
+test_mkfds_SOURCES = tests/helpers/test_mkfds.c tests/helpers/test_mkfds.h \
+       tests/helpers/test_mkfds_ppoll.c
 test_mkfds_LDADD = $(LDADD) $(MQ_LIBS)
 
 check_PROGRAMS += test_enosys
index 930768e29537a707ce26326cd753e95705efb610..b0bb8b71a4276ce59ea2001509244550c27d8453 100644 (file)
@@ -3908,6 +3908,12 @@ static struct multiplexer multiplexers [] = {
                .fn = wait_event_poll,
        },
 #endif
+#ifdef __NR_ppoll
+       {
+               .name = "ppoll",
+               .fn = wait_event_ppoll,
+       },
+#endif
 };
 
 static struct multiplexer *lookup_multiplexer(const char *name)
index 068dd72e1b66c0578cd8c350866612e7fba13fef..7d679b44fe9f18e3d09ff21e2b1f823f91e65bce 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef TEST_MKFDS_H
 #define TEST_MKFDS_H
 
+#include <asm/unistd.h>
 #include <stdbool.h>
 #include <stddef.h>
 
@@ -77,4 +78,8 @@ struct fdesc {
                free(pfds);                                             \
        }
 
+#ifdef __NR_ppoll
+void wait_event_ppoll(bool add_stdin, struct fdesc *fdescs, size_t n_fdescs);
+#endif
+
 #endif /* TEST_MKFDS_H */
diff --git a/tests/helpers/test_mkfds_ppoll.c b/tests/helpers/test_mkfds_ppoll.c
new file mode 100644 (file)
index 0000000..33d5aa8
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * test_mkfds_ppoll.c - call ppoll(2) DIRECTLY
+ *
+ * Written by Masatake YAMATO <yamato@redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+/* Why this ppoll multiplexer must be defined here?
+ *
+ * Glibc defines sigset_t its own way. However, it is not what kernel
+ * expects.
+ *
+ * If an applicaiton uses the glibc's sigset_t via ppoll(2) wrapper,
+ * there is no problem; the wrapper function may translate the glibc's
+ * sigset_t to what kernel expects.
+ *
+ * Here, we want to ppoll(2) directly. In this case, the glibc's sigset_t
+ * becomes an issue. To use ppoll(2) directly, we have to include <asm/poll.h>.
+ * Including both <poll.h> provided by glibc and <asm/poll.h> provided by kernel
+ * causes "redefined ***" errors.
+ *
+ * This file is for defining the poll multiplexer only with <asm/poll.h>.
+ *
+ */
+#include "test_mkfds.h"
+
+#include <string.h>            /* memset */
+#include <err.h>               /* err */
+#include <errno.h>             /* EINTR */
+#include <linux/poll.h>                /* struct pollfd */
+#include <asm/signal.h>                /* sigset_t */
+
+extern long syscall(long number, ...);
+extern void *calloc(size_t nmemb, size_t size);
+extern void free(void *ptr);
+
+#ifndef EXIT_FAILURE
+# define EXIT_FAILURE 1
+#endif
+#ifndef XALLOC_EXIT_CODE
+# define XALLOC_EXIT_CODE EXIT_FAILURE
+#endif
+
+/* Copied from include/xalloc.h */
+static void *xcalloc(const size_t nelems, const size_t size)
+{
+       void *ret = calloc(nelems, size);
+
+       if (!ret && size && nelems)
+               err(XALLOC_EXIT_CODE, "cannot allocate %zu bytes", size);
+       return ret;
+}
+
+/* sigemptyset may not be defiend and/or declared in asm/signal.h */
+static void clear_sigset(sigset_t *sigset)
+{
+       memset(sigset, 0, sizeof(*sigset));
+}
+
+#ifdef __NR_ppoll
+DEFUN_WAIT_EVENT_POLL(ppoll,
+                     "ppoll",
+                     sigset_t sigset;,
+                     clear_sigset(&sigset);,
+                     syscall(__NR_ppoll, pfds, n, NULL, &sigset, sizeof(sigset)))
+#endif