Reputation: 35
I would like to know which case is SIG_ERR among the return values of the signal function.
__sighandler_t oldHandler = signal( SIGSEGV, newSignalHandler );
if( oldHandler == SIG_ERR )
{
// In what case?
}
Upvotes: 1
Views: 584
Reputation: 57922
The man page for each system call is supposed to list all possible error conditions under the "ERRORS" heading, along with the corresponding values to which errno
is set in each case.
The man page for signal(2)
shows only:
EINVAL
signum is invalid.
This occurs if signum (the first argument) isn't the number of a valid signal, or is either SIGKILL
or SIGSTOP
which cannot be caught or ignored.
As such, if you have passed SIGSEGV
as the first argument, signal()
should never fail.
(I initially thought it could also fail if handler was an invalid pointer, but it seems in this case that it just installs the invalid pointer as the handler, and thus will segfault or otherwise misbehave should the signal actually be raised.)
Upvotes: 1