summaryrefslogtreecommitdiff
path: root/test/unistd
diff options
context:
space:
mode:
authorLeonid Lisovskiy <lly.dev@gmail.com>2015-12-27 20:46:49 +0300
committerWaldemar Brodkorb <wbx@uclibc-ng.org>2016-01-01 19:48:17 +0100
commitd1b1ccb72f4dee5728f0878054709721b1163f62 (patch)
tree862e6231c4472e83b911d6794f11ee6b4e84efe7 /test/unistd
parenta65637cc30455841909b2676599589b702bd654e (diff)
Fix "pselect: Use linux pselect6 syscall when available"
Commit e3c3bf2b58 introduce use of pselect6, but has following disadvantages: * Use of userspace types in args67 structure - it breaks, for example, configs when 32-bit uClibc-ng compiled against 64-bit kernel. Syscall will always return EINVAL. We must use __kernel_* types and __SYSCALL_SIGSET_T_SIZE. * It have excess checks for NSEC_PER_SEC. Original code from select() implementation has struct timeval => struct timespec conversion, kernel select() syscall implementation do the same. But none of libc versions (glibc, eglibc, musl) I know, perform similar checks for pselect() - there is no structure fields conversions, just struct timespec through all the calls. To have such checks in uClibc-ng we need one example, at least. * It is possible to avoid extra userspace reads from kernel code if sigmask == NULL. I suggest to do it, for a few bytes cost. * Commit didn't add test case to testsuite. Signed-off-by: Leonid Lisovskiy <lly.dev@gmail.com>
Diffstat (limited to 'test/unistd')
-rw-r--r--test/unistd/tst-pselect.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/unistd/tst-pselect.c b/test/unistd/tst-pselect.c
new file mode 100644
index 000000000..cab945119
--- /dev/null
+++ b/test/unistd/tst-pselect.c
@@ -0,0 +1,51 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/select.h>
+
+// our SIGALRM handler
+void handler(int signum) {
+ (void)signum;
+ puts("got signal\n");
+}
+
+static int
+do_test (void)
+{
+ int rc;
+ sigset_t wait_mask, mask_sigchld;
+ struct sigaction act;
+
+ // block SIGALRM. We want to handle it only when we're ready
+ sigemptyset(&mask_sigchld);
+ sigaddset(&mask_sigchld, SIGALRM);
+ sigprocmask(SIG_BLOCK, &mask_sigchld, &wait_mask);
+ sigdelset(&wait_mask, SIGALRM);
+
+ // register a signal handler so we can see when the signal arrives
+ memset(&act, 0, sizeof(act));
+ sigemptyset(&act.sa_mask); // just in case an empty set isn't all 0's (total paranoia)
+ act.sa_handler = handler;
+ sigaction(SIGALRM, &act, NULL);
+
+ // send ourselves a SIGARLM. It will pend until we unblock that signal in pselect()
+ printf("sending ourselves a signal\n");
+ kill(getpid(), SIGALRM);
+
+ printf("signal is pending; calling pselect()\n");
+ rc = pselect(0, NULL, NULL, NULL, NULL, &wait_mask);
+ if (rc != -1 || errno != EINTR) {
+ int e = errno;
+ printf("pselect() returned %d, errno %d (%s)\n", rc, e, strerror(e));
+ exit(1);
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include <test-skeleton.c>