determine whether code is running in a signal handler context

Yubin Ruan ablacktshirt@gmail.com
Wed Oct 18 14:18:00 GMT 2017


Hi,

I am writing to see if this is any util functions in libc that can
help to determine it is currently running in a signal.

I wrote some library and provide a function which will be used in many
client code. However this function is not async-signal safe (it calls
malloc(3)) so when it is called, I want to detect whether it is
currently running in a signal handler. If it is, I can avoid calling
those not-async-signal-safe functions which might cause deadlock.

that is, I want a `in_signal_handler_context()' utility that can be
used as this:

int mylibfunc( void ) {
    if( in_signal_handler_context() ) { return(-1) }
    // rest of function goes here
    return( 0 );
}


Yubin



More information about the Libc-help mailing list