1/* $OpenBSD: readv.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/uio.h> 7#include <pthread.h> 8#include <signal.h> 9#include <unistd.h> 10#include "test.h" 11 12volatile sig_atomic_t hits = 0; 13 14void 15handler(int sig) 16{ 17 hits++; 18} 19 20void * 21thr_readv(void *arg) 22{ 23 struct iovec iov; 24 int fds[2]; 25 char buf; 26 27 CHECKe(pipe(fds)); 28 iov.iov_base = &buf; 29 iov.iov_len = 1; 30 ASSERT(readv(fds[0], &iov, 1) == -1); 31 return ((caddr_t)NULL + errno); 32} 33 34int 35main(int argc, char **argv) 36{ 37 struct sigaction sa; 38 pthread_t tid; 39 void *retval; 40 41 bzero(&sa, sizeof(sa)); 42 sa.sa_handler = handler; 43 sa.sa_flags = SA_RESTART; 44 CHECKe(sigaction(SIGUSR1, &sa, NULL)); 45 sa.sa_flags = 0; 46 CHECKe(sigaction(SIGUSR2, &sa, NULL)); 47 48 CHECKr(pthread_create(&tid, NULL, thr_readv, NULL)); 49 sleep(2); 50 51 /* Should restart it. */ 52 CHECKr(pthread_kill(tid, SIGUSR1)); 53 sleep(1); 54 55 /* Should interrupt it. */ 56 CHECKr(pthread_kill(tid, SIGUSR2)); 57 sleep(1); 58 59 CHECKr(pthread_join(tid, &retval)); 60 ASSERT(retval == (void *)EINTR); 61 ASSERT(hits == 2); 62 SUCCEED; 63} 64