Re: Possible strategy for safe signal handling
Lassi Kortela 19 Jul 2019 20:13 UTC
> I ran into this strategy in a C program and I'm posting it here to get
> it on record.
>
> The idea is to create a pipe when a process starts up and give the write
> end to a global signal-handling function. When a signal that is not
> ignored or defaulted is received, a packet describing the signal is
> written into the pipe with write(2), a known signal-safe operation, to
> the pipe. The handler then returns.
I don't understand all the details, but the idea sounds brilliant. It
sounds like a further developed version of the self-pipe trick from Dan
Bernstein, early 1990s: <https://cr.yp.to/docs/selfpipe.html>
> The read end of this pipe is examined by the Great Big Select or similar
> multiplexer
I'm under the impression that poll() provides a clean and portable
interface nowadays (and it plenty fast unless you need to multiplex
hundreds of file descriptors). Please correct if wrong.