7 // https://stackoverflow.com/questions/6326290/about-the-ambiguous-description-of-sigwait
8 // except the deliberate errors
12 void on_sigusr1(int sig
)
19 // Set a signal handler for SIGUSR1
20 signal(SIGUSR1
, &on_sigusr1
);
22 // At program startup, SIGUSR1 is neither blocked nor pending, so raising it
23 // will call the signal handler
26 // Now let's block SIGUSR1
27 sigset_t
* psigset
= malloc(sizeof(sigset_t
));
29 sigaddset(psigset
, SIGUSR1
);
30 sigprocmask(SIG_BLOCK
, psigset
, NULL
);
32 // SIGUSR1 is now blocked, raising it will not call the signal handler
35 // SIGUSR1 is now blocked and pending -- this call to sigwait will return
38 int result
= sigwait(psigset
, &sig
);
40 printf("sigwait got signal: %d\n", sig
);
42 // SIGUSR1 is now no longer pending (but still blocked). Raise it again and
45 printf("About to unblock SIGUSR1\n");
46 sigprocmask(SIG_UNBLOCK
, psigset
, NULL
);
47 printf("Unblocked SIGUSR1\n");
49 assert(sig_count
== 2);
51 // now a couple of bad params
53 sigprocmask(SIG_BLOCK
, psigset
, NULL
);
56 int* psig
= malloc(sizeof(int));
58 result
= sigwait(psigset
, psig
);
64 result
= sigwait(psigset
, &sig
);