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