Your longjmp
will cause you to jump to the location, but you will not have returned from the signal handler. This means that the signal is still blocked (this is the default behavior for signals, they are masked until you have returned from the signal handler).
You can fix this by indicating that you want the signal to occur again by clearing the signal mask in your handler before longjmp
.
- Use the
SA_NODEFER
flag inact.sa_flags
to prevent it from being masked in the first place. - Use the
siglongjmp
/sigsetjmp
functions, which saves the mask for you
Or
- Call sigprocmask either before or after the longjmp to unmask it yourself.
A warning: This is a very dangerous thing to do (catch SIGSEGV, and then longjmp out of the signal handler) and it will be almost impossible to do anything useful with it.
If the memory access error occurs in any function that is not async signal safe and reentrant you will not be able to continue in any kind of sane way anyway.
But since there are multiple similar questions on the site I guess this is some kind of exercise.
Related question: Catching Segmentation Violations and Getting on with Life
Also useful
Longjmp out of signal handler? longjmp() from signal handler