determine whether code is running in a signal handler context
Yubin Ruan
ablacktshirt@gmail.com
Thu Oct 19 03:51:00 GMT 2017
2017-10-19 11:12 GMT+08:00 Sean Conner <sean@conman.org>:
> It was thus said that the Great Yubin Ruan once stated:
>> 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.
>
> Wouldn't it be easier (and safer) just to document the library as
> not-async-signal-safe ("These functions, called from a signal handler, will
> invoke undefined behavior")? Use a large font if you have to, but I think
> protecting programmers from themselves over the long term is bad.
Yes I can document that and that is indeed an option. But I don't know
whether the user will read the docs. ;-)
It would be great if we can handle that smoothly such that users will
not notice.
Yubin
More information about the Libc-help
mailing list