Reputation: 6791
What does the following code do?
struct sigaction saStruct;
saStruct.sa_flags = SA_NOCLDWAIT|SA_NODEFER|SA_SIGINFO;
saStruct.sa_sigaction = NULL;
sigemptyset(&saStruct.sa_mask);
sigaction(SIGCHLD, &saStruct, NULL);
In particular, what does it mean that sa_sigaction
is set to NULL? Is this a complicated way to express something much more simple? I couldn't find any reference to this usage in the sigaction man page.
I'm primarily interested in answers for Linux (>= 2.6).
Upvotes: 3
Views: 1392
Reputation: 157484
NULL
happens to be equivalent to SIG_DFL
; don't depend on this.
#define SIG_ERR ((__sighandler_t) -1) /* Error return. */
#define SIG_DFL ((__sighandler_t) 0) /* Default action. */
#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */
SIG_DFL
etc. are intended to be assigned to the sa_handler
member, but (and again, don't depend on this) sa_handler
is on Linux in a union with sa_sigaction
so assigning NULL
to sa_sigaction
is equivalent to assigning SIG_DFL
to sa_handler
.
union
{
/* Used if SA_SIGINFO is not set. */
__sighandler_t sa_handler;
/* Used if SA_SIGINFO is set. */
void (*sa_sigaction) (int, siginfo_t *, void *);
}
__sigaction_handler;
# define sa_handler __sigaction_handler.sa_handler
# define sa_sigaction __sigaction_handler.sa_sigaction
Upvotes: 3