c/program/signal

Sets the error handler for signal. The signal handler can be set so that default handling will occur, signal is ignored, or a user-defined function is called.

When signal handler is set to a function and a signal occurs, it is implementation defined whether will be executed immediately before the start of signal handler. Also, the implementation can prevent some implementation-defined set of signals from occurring while the signal handler runs.

Return value
Previous signal handler on success or sig_err on failure (setting a signal handler can be disabled on some implementations).

Signal handler
The following limitations are imposed on the user-defined function that is installed as a signal handler.

If the user defined function returns when handling sigfpe, sigill or sigsegv, the behavior is undefined.

If the signal handler is called as a result of abort or raise, the behavior is undefined if the signal handler calls raise.

If the signal handler is called NOT as a result of abort or raise (in other words, the signal handler is asynchronous), the behavior is undefined if
 * the signal handler calls any function within the standard library, except
 * abort
 * _exit
 * quick_exit
 * with the first argument being the number of the signal currently handled (async handler can re-register itself, but not other signals).
 * atomic functions from c/thread if the atomic arguments are lock-free
 * atomic_is_lock_free (with any kind of atomic arguments)


 * the signal handler refers to any object with static storage duration  other than by assigning to a static.

On entry to the signal handler, the state of the floating-point environment and the values of all objects is unspecified, except for
 * objects of type
 * objects of lock-free atomic types
 * side effects made visible through atomic_signal_fence

On return from a signal handler, the value of any object modified by the signal handler that is not or lock-free atomic is undefined.

The behavior is undefined if is used in a multithreaded program. It is not required to be thread-safe.