How the answer depends on how you installed your signal handler. If you installed a signal handler using an obsolete signal() call, it will either be reset by the signal handler for the default handler, or it will block the signal being processed before calling your signal handler. If it blocks a signal, it unlocks it after the signal handler returns.
If you use sigaction() , you have control over which signals are blocked during the call of the signal handler. If you indicate so, you can invoke infinite recursion.
You can create a secure wrapper around sigaction() , which has an API like signal() :
sighandler_t safe_signal (int sig, sighandler_t h) { struct sigaction sa; struct sigaction osa; sa.sa_handler = h; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; if (sigaction(sig, &sa, &osa) < 0) { return SIG_ERR; } return osa.sa_handler; }
This blocks all signals for the duration of the signal handler call, which is restored after the signal handler returns.
source share