POSIX.1-2017 specifies under XSH 2.4.3 SIG_IGN that
The behavior of a process is undefined after it ignores a SIGFPE, SIGILL, SIGSEGV, or SIGBUS signal that was not generated by kill(), sigqueue(), or raise().
and I'm wondering what the significance of the emphasized part is?
Can you ignore those signals generated only by the above functions yet avoid invoking undefined behavior?
You shouldn't SIG_IGN
-ore those signals if you're expecting the kernel to generate them.
You can catch them with sigaction
and SA_SIGINFO
in .sa_flags
and use SA_SIGINFO
so you can then use info->si_code
in the handler to distinguish between kernel-sent and user-sent variants.
If you then do nothing in the handler if the signal wasn't kernel-sent and exit/abort if it was, then with a SA_RESTART
handler you've basically got yourself a userspace emulation of SIG_IGN
that also works with kernel-sent SISGEV
, SIGILL
, etc.
If you use real SIG_IGN
, you must take care not to provoke the kernel into generating these signals (no invalid memory references, no invalid instructions, etc.).
I think POSIX allows you to safely ignore SIGFPE
, SIGILL
, SIGSEGV
, or SIGBUS
simply because there's no strong reason to flatly disallowing ignoring these signals in all circumstances, but I don't think there's much significance behind the feature otherwise.