1 /* $FreeBSD$ */ 2 #include <signal.h> 3 #include <stdio.h> 4 #include <err.h> 5 #include <errno.h> 6 7 int received; 8 9 void handler(int sig, siginfo_t *si, void *ctx) 10 { 11 if (si->si_code != SI_QUEUE) 12 errx(1, "si_code != SI_QUEUE"); 13 if (si->si_value.sival_int != received) 14 errx(1, "signal is out of order"); 15 received++; 16 } 17 18 int main() 19 { 20 struct sigaction sa; 21 union sigval val; 22 int ret; 23 int i; 24 sigset_t set; 25 26 sa.sa_flags = SA_SIGINFO; 27 sigemptyset(&sa.sa_mask); 28 sa.sa_sigaction = handler; 29 sigaction(SIGRTMIN, &sa, NULL); 30 sigemptyset(&set); 31 sigaddset(&set, SIGRTMIN); 32 sigprocmask(SIG_BLOCK, &set, NULL); 33 i = 0; 34 for (;;) { 35 val.sival_int = i; 36 ret = sigqueue(getpid(), SIGRTMIN, val); 37 if (ret == -1) { 38 if (errno != EAGAIN) { 39 errx(1, "errno != EAGAIN"); 40 } 41 break; 42 } 43 i++; 44 } 45 sigprocmask(SIG_UNBLOCK, &set, NULL); 46 if (received != i) 47 errx(1, "error, signal lost"); 48 printf("OK\n"); 49 } 50