[LTP] [PATCH V3] syscalls/timer_settime01: Make sure the timer fires

Cyril Hrubis chrubis@suse.cz
Wed Jul 15 10:53:14 CEST 2020


Hi!
> > Pushed with minor changes, thanks.
> > 
> > Among other fixes I've moved the signal check from the signal handler to
> > the clear_signal() function, since the tst_res() function is not
> > signal-async-safe...
> 
> What does that mean ? I remember that I added it there in
> clear_signal() first, but then I tried to print the stuff (forcefully)
> from sighandler() and it worked without any issues and so I did that.

Calling printf() from signal handler is not safe, which tst_res() does.

It will work fine 99% of the cases and this is the reason most people do
it anyways. One of the failure modes is the malloc arena lock. Printf
may allocate temporary buffer so if the signal comes when the process is
in the malloc code the process will hang forewer because it will try to
acquire a lock that has been locked before we jumped into the signal
handler, but there is probably more. It usually gets triggered on
stranger architectures, x86 is quite forgiving in this regard.

Signal handlers are generally tricky and there is a list of functions
that carefuly avoid messing with any global state and can be safely used
from withing a signal handler (man 7 signal-safety) anything else is,
unlikely to fail, but still potential hazard.

Generally the safest approach to signal handlers is to set a variable
and exit, which is what I usually do in tests...

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list