NAME
sigblockall
,
sigunblockall
—
quickly block and unblock all maskable
signals
LIBRARY
library “libc”
SYNOPSIS
#include
<signal.h>
int
sigblockall
(void);
int
sigunblockall
(void);
DESCRIPTION
These functions operate on a per-thread basis and temporarily prevent signal posts to the calling thread, protecting the function from potential reentrancy issues due to signal interruption. The signal mask is not modified in any way and synchronous signals caused by traps (such asSIGSEGV
) will still be immediately posted.
These functions operate via the /dev/lpmap per-thread shared page facility and, once primed, will operate without having to issue any system calls. They are designed to be very fast, typically sub-10nS.
The
sigblockall
()
procedure temporarily blocks the posting of any maskable signal.
SIGSTOP
and SIGKILL
are not
maskable and will still be delivered, as will any signals caused by
synchronous traps. This facility does not prevent signals from being
delivered to the thread, it simply prevents the signals from being posted to
(interrupting) the thread.
Callers must pair all calls to
sigblockall
()
with calls to sigunblockall
(). These functions may
be used recursively.
The
sigunblockall
()
procedure unwinds the operation. On the last transition, any blocked signals
not otherwise masked through the normal signal mask will be immediately
posted prior to the function returning.
RETURN VALUES
Both procedures return the recursive blocking count's value after
the operation. Thus the first call to sigblockall
()
will generally return the value 1 and the last call to
sigunblockall
() will generally return the value
0.
The returned value may have bit 31 set, resulting in a negative
number. Bit 31 set indicates that one or more signals may have been blocked
from being posted and represents cumulative state until the last call to
sigunblockall
().
If bit 31 is set in the value returned by the last call to
sigunblockall
(), it is an indication that signals
were previously blocked and have now been posted. Bit 31 will be cleared in
libc's internal state for the calling thread on the last call.
WARNINGS
Any blocking count for the current thread present as-of any fork(2) or vfork(2) will be inherited by the child and must be unwound in both parent and child. This also allows programs to conveniently prevent signal delivery in a new child process until they are ready to deal with it, if desired.
Care must be taken if coupling the use of these functions with the longjmp and ucontext facilities. The blocking count is associated with the thread, NOT the context.
ERRORS
These functions return -1 on error, which can only occur if the /dev/lpmap facility is not available. However, generally speaking, because these procedures are meant to be used in critical code paths, callers are not expected to check for this failure condition in critical code paths. Detecting support can be done at the start of the program, if desired, simply by issuing the function pair and retaining the result.
SEE ALSO
HISTORY
The sigblockall
() familiy of functions
first appeared in DragonFly 5.7.