A signal handler should not re-assert its desire to handle its own signal. This is often done on non-persistent platforms, that is, when they receive a signal handler receives a signal that is bound to a handler, they unbind the signal to default behavior before calling the handler.
...
Non-Compliant Code Example
In this non-compliant code example, the signal handler handler()
is bound to signum
.
Code Block | ||
---|---|---|
| ||
void handler(int signum) { signal(signum, handler); /* handling code */ } /* ... */ signal(signum, handler); |
Inside the handler, the signal()
function permits Unfortunately this solution contains a race window. , starting when the OS first host environment resets the signal , and ending when the handler calls signal()
. During that time, a second signal sent to the program will still trigger the default signal behavior, thereby destroying defeating the persistence persistent behavior implied by the call to signal()
funtion inside from within the handler to reassert the binding.
If the OS environment is persistent (that is, it does not reset the handler when the signal is received), the handler's signal()
function is redundant.
...