Since printf
is not reentrant, it\'s not supposed to be safe to use it in a signal handler. But I\'ve seen lots of example codes that uses printf
t
For debugging purposes, I wrote a tool which verifies that you are in fact only calling functions on the async-signal-safe
list, and prints a warning message for each unsafe function called within a signal context. While it doesn't solve the problem of wanting to call non async-safe functions from a signal context, it at least helps you find cases where you have done so accidentally.
The source code is on GitHub. It works by overloading signal/sigaction
, then temporarily hijacking the PLT
entries of unsafe functions; this causes calls to unsafe functions to be redirected to a wrapper.