I need a function that allows to either specify a user defined signal action, to reset it to default, or to ignore the signal. The code so far is
int setsig(int signum, void (*action)(int, siginfo_t *, void *)) {
struct sigaction sig;
sigemptyset (&sig.sa_mask);
sig.sa_sigaction = action;
sig.sa_flags = SA_NODEFER|SA_SIGINFO;
return sigaction (code, &sig, NULL);
}
This shall later be used in a code like
static void my_action (int, siginfo_t *, void *);
void (*mysignal)(int, siginfo_t *, void *);
if (some_condition) {
mysignal = my_action;
} else if (some_other_contion) {
mysignal = SIG_IGN;
} else {
mysignal = SIG_DFL;
}
[…]
setsig(signum, mysignal);
However, this wrongly treats SIG_IGN
and SIG_DFL
as sigactions and not as sighandlers.
Are there (portable) equivalents as actions? Or is there another way to have them handled in a similar way?