Chapter 7. Signals and signal file descriptors


Blocking signals
Signal file descriptors
Signal handlers
#include <x/sigset.H>

x::sigset signals;

signals += SIGHUP;

x::sigset is a wrapper for sigset_t, and implements the functionality of the sigsetops(2) man page. Its block(), unblock(), and set() methods invoke pthread_sigmask(3). current() returns the current thread's signal mask.

Blocking signals

    x::sigset::block_all sigblock;

    // ...

The x::sigset::block_all class is a convenient shortcut. It must be instantiated on the stack. Its constructor blocks all signals except for SIGABRT, and the destructor restores the original set of thread signals. The above example disables all signals in the scope where sigblock is declared.

#include <x/sigset.H>

x::ref<x::obj> mcguffin=x::sigset::block(SIGHUP);

This example blocks the SIGHUP signal, using pthread_sigmask(3). x::sigset::block() returns a mcguffin representing the blocked signal. The signal remains blocked until the mcguffin goes out of scope and gets destroyed, at which point pthread_sigmask(3) gets invoked to unblock it.

It's possible to create multiple mcguffins that block the same signal. Instantiating a mcguffin for signal that's already blocked does nothing. The signal remains blocked as long as any mcguffin remains in scope, and gets unblocked only after all blocking mcguffins go out of scope and no longer exist.

Mcguffins for different signals track their respective signals independently of each other.