#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include "test.h"
volatile sig_atomic_t sigactive;
volatile sig_atomic_t sigcount;
volatile sig_atomic_t was_active;
static void
act_handler(int signal, siginfo_t *siginfo, void *context)
{
char *str;
was_active += sigactive++;
sigcount += 1;
ASSERT(siginfo != NULL);
asprintf(&str,
"%sact_handler/%d, signal %d, siginfo %p, context %p\n",
was_active ? "[recurse] " : "",
sigcount, signal, siginfo, context);
CHECKe(write(STDOUT_FILENO, str, strlen(str)));
if (sigcount & 1)
CHECKe(kill(getpid(), SIGUSR1));
sigactive = 0;
}
int
main(int argc, char **argv)
{
struct sigaction act;
act.sa_sigaction = act_handler;
sigemptyset(&act.sa_mask);
act.sa_flags = SA_SIGINFO;
ASSERT(sigaction(SIGUSR1, &act, NULL) == 0);
CHECKe(kill(getpid(), SIGUSR1));
sleep(1);
ASSERT(was_active == 0);
act.sa_flags |= SA_NODEFER;
ASSERT(sigaction(SIGUSR1, &act, NULL) == 0);
CHECKe(kill(getpid(), SIGUSR1));
sleep(1);
ASSERT(was_active == 1);
SUCCEED;
}