tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: snprintf(3) and friends async-signal safety?

On Wed, 22 Dec 2010 18:07:50 +0200
Jean-Yves Migeon <> wrote:

>  Hi list,
>  While working on my msgfmt thingy for dd(1) [1], I found that 
>  snprintf(3) gets used in summary(), which is a function that can be 
>  called via the SIGINFO handler.
>  Unfortunately, I am not quite certain of what I read; a quick look at 
>  snprintf(3) code in libc/stdio makes me believe that the function is 
>  _not_ async signal safe (it is not listed in signal(7) either), but is 
>  still used in as-is in dd(1).
>  Question is: is it really safe to use it in a signal handler inside 
>  NetBSD?
>  [1] 
> -- 
>  Jean-Yves Migeon

Well you could hangle Unix signals synchronously by using a thread which waits 
for signals with sigwait(). Usually you block certain signals in main thread, 
then one (signal catching) thread calls sigwait() waiting for a signal. When 
the signal arrives, signal catching thread stops/restarts other threads, 
depending on what the signal was meant to do.

Home | Main Index | Thread Index | Old Index