1 /* $OpenBSD: kevent.c,v 1.1 2011/09/13 23:50:17 fgsch Exp $ */ 2 /* 3 * Federico G. Schwindt <fgsch@openbsd.org>, 2011. Public Domain. 4 */ 5 #include <sys/types.h> 6 #include <sys/event.h> 7 #include <sys/time.h> 8 #include <pthread.h> 9 #include <signal.h> 10 #include <unistd.h> 11 #include "test.h" 12 13 volatile sig_atomic_t hits = 0; 14 15 void 16 handler(int sig) 17 { 18 hits++; 19 } 20 21 void * 22 thr_kevent(void *arg) 23 { 24 struct kevent ev; 25 struct timespec ts = { 10, 0 }; 26 int kq; 27 28 CHECKe(kq = kqueue()); 29 ASSERT(kevent(kq, NULL, 0, &ev, 1, &ts) == -1); 30 return ((caddr_t)NULL + errno); 31 } 32 33 int 34 main(int argc, char **argv) 35 { 36 struct sigaction sa; 37 pthread_t tid; 38 void *retval; 39 40 bzero(&sa, sizeof(sa)); 41 sa.sa_handler = handler; 42 sa.sa_flags = SA_RESTART; 43 CHECKe(sigaction(SIGUSR1, &sa, NULL)); 44 45 CHECKr(pthread_create(&tid, NULL, thr_kevent, NULL)); 46 sleep(2); 47 48 /* Should interrupt it. */ 49 CHECKr(pthread_kill(tid, SIGUSR1)); 50 sleep(1); 51 52 CHECKr(pthread_join(tid, &retval)); 53 ASSERT(retval == (void *)EINTR); 54 ASSERT(hits == 1); 55 SUCCEED; 56 } 57