]> granicus.if.org Git - strace/blobdiff - tests/epoll_ctl.c
strace: terminate itself if interrupted by a signal
[strace] / tests / epoll_ctl.c
index 7237f0f799e1f90bee1a94b3e429320e5abc0ff1..2251b35898e73e6f10df528fb64ef035d15794bd 100644 (file)
@@ -1,33 +1,38 @@
 #include "tests.h"
-#include <sys/syscall.h>
+#include <asm/unistd.h>
 
-#if defined __NR_epoll_ctl && defined HAVE_SYS_EPOLL_H
+#ifdef __NR_epoll_ctl
 
-# include <errno.h>
 # include <inttypes.h>
 # include <stdio.h>
 # include <sys/epoll.h>
 # include <unistd.h>
 
+static long
+invoke_syscall(unsigned long epfd, unsigned long op, unsigned long fd, void *ev)
+{
+       return syscall(__NR_epoll_ctl, epfd, F8ILL_KULONG_MASK | op,
+                      fd, (unsigned long) ev);
+}
+
 int
 main(void)
 {
-       struct epoll_event *const ev = tail_alloc(sizeof(*ev));
+       TAIL_ALLOC_OBJECT_CONST_PTR(struct epoll_event, ev);
        ev->events = EPOLLIN;
 
-       int rc = syscall(__NR_epoll_ctl, -1, EPOLL_CTL_ADD, -2, ev);
+       long rc = invoke_syscall(-1U, EPOLL_CTL_ADD, -2U, ev);
        printf("epoll_ctl(-1, EPOLL_CTL_ADD, -2, {EPOLLIN,"
-              " {u32=%u, u64=%" PRIu64 "}}) = %d %s (%m)\n",
-              ev->data.u32, ev->data.u64, rc,
-              errno == ENOSYS ? "ENOSYS" : "EBADF");
+              " {u32=%u, u64=%" PRIu64 "}}) = %ld %s (%m)\n",
+              ev->data.u32, ev->data.u64, rc, errno2name());
 
-       rc = syscall(__NR_epoll_ctl, -3, EPOLL_CTL_DEL, -4, ev);
-       printf("epoll_ctl(-3, EPOLL_CTL_DEL, -4, %p) = %d %s (%m)\n",
-              ev, rc, errno == ENOSYS ? "ENOSYS" : "EBADF");
+       rc = invoke_syscall(-3U, EPOLL_CTL_DEL, -4U, ev);
+       printf("epoll_ctl(-3, EPOLL_CTL_DEL, -4, %p) = %ld %s (%m)\n",
+              ev, rc, errno2name());
 
-       rc = syscall(__NR_epoll_ctl, -1L, EPOLL_CTL_MOD, -16L, 0);
-       printf("epoll_ctl(-1, EPOLL_CTL_MOD, -16, NULL) = %d %s (%m)\n",
-              rc, errno == ENOSYS ? "ENOSYS" : "EFAULT");
+       rc = invoke_syscall(-1UL, EPOLL_CTL_MOD, -16UL, 0);
+       printf("epoll_ctl(-1, EPOLL_CTL_MOD, -16, NULL) = %ld %s (%m)\n",
+              rc, errno2name());
 
        puts("+++ exited with 0 +++");
        return 0;
@@ -35,6 +40,6 @@ main(void)
 
 #else
 
-SKIP_MAIN_UNDEFINED("__NR_epoll_ctl && HAVE_SYS_EPOLL_H")
+SKIP_MAIN_UNDEFINED("__NR_epoll_ctl")
 
 #endif