Signals
From PortaWiki
Signal delivery semantics differ between Unix-like systems, mainly based on SysV vs. BSD heritage
BSD-ish systems generally restart active syscalls when a signal is received
SysV-ish systems let the syscall return EINTR. This means that syscalls such as, eg read(2) or write(2) may be only partially complete.
There are also ambiguities over whether signal handlers are reinstated after they are run. Signal handlers would re-estabilish the handler immediately upon invocation, however there is a windows between invocation and re-establishing the handler where the default action would be taken.
OpenSSH uses a technique from W. Richard Stevens (section 10.14 in the 1st edition) to cope with this: it has a signal() replacement with consistent semantics.
Other gotchas:
- SIGCLD and SIGCHLD are similar but not the same. SIGCHLD is standardized, use that.
- signals on early Unix systems are unreliable; you could miss signals and never know it.
Recommendations for Unix systems: Use sigaction if you have it; it's in POSIX.1 and its behaviour is standardized.
(parts from Damien Miller's Secure Portability presentation, used with permission)
