In below signal handlers as examples:
static void
sigalarm_handler (int sig)
{
evWaitFor(ctx, &sigalarm_event, sigalarm_event, NULL, NULL);
...
evDo(ctx, &sigalarm_event);
}
static void
sigterm_handler (int sig)
{
evDo(ctx, &sigterm_event);
}
Is it safe to use evDo
and evWaitFor
in a signal (e.g. SIGHUP
, SIGTERM
, SIGUSR2
, SIGALRM
, etc.) handler?
I read somewhere where the comment read "SIGALRM
cannot be serviced using evWaitFor
/evDo
because they are not signal (reentrant) safe". Hence, this question.
After some research and hands on, it is evident that evDo
and evWaitFor
are NOT safe in signal handler. evDO
and evWaitFor
are not async signal safe.
In fact, the evLib
functions are not signal safe.
If you want to replicate the crash, you could just send signals frequently to the PID. Assumption is that you have already established handlers for below signals.
kill -HUP <PID>; kill -HUP <PID>; kill -HUP <PID>; kill -HUP <PID>; kill -TERM <PID>
Solution:
It's better to just set a variable in the actual signal handler and then check for the variable in a synchronously called user level handler. The final signal handling could be done inside this handler.
evSetSyncHandler()
can register such a user defined synchronous handler.