On Sat, Aug 28, 2010 at 11:43:55AM +0300, Kostik Belousov wrote: > On Fri, Aug 27, 2010 at 11:54:02PM +0200, Pawel Jakub Dawidek wrote: > > On Sat, Aug 28, 2010 at 12:38:27AM +0300, Kostik Belousov wrote: > > > > --- head/sbin/hastd/primary.c Fri Aug 27 20:48:12 2010 > > > > (r211895) > > > > +++ head/sbin/hastd/primary.c Fri Aug 27 20:49:06 2010 > > > > (r211896) > > > > @@ -1988,7 +1988,9 @@ guard_thread(void *arg) > > > > rw_unlock(&hio_remote_lock[ii]); > > > > } > > > > } > > > > - (void)cv_timedwait(&hio_guard_cond, &hio_guard_lock, > > > > timeout); > > > > + /* Sleep only if a signal wasn't delivered in the > > > > meantime. */ > > > > + if (!sigexit_received && !sighup_received && > > > > !sigchld_received) > > > > + cv_timedwait(&hio_guard_cond, &hio_guard_lock, > > > > timeout); > > > > mtx_unlock(&hio_guard_lock); > > > > } > > > > /* NOTREACHED */ > > > I wanted to say that this is racy, because if a signal is delivered after > > > the check is done but before the sleep, you loose. > > > > Yes, I know it is racy, but the race isn't critical anymore, as we will > > eventually wait at most 10 seconds to handle signals. > > > > > After looking at the signal handler, I noted that you call not async-safe > > > functions in the handler. This is easy way to get undefined behaviour, > > > i.e. probably crash. And wakeup from the handler would have the same > > > race as sigXXX_received check. > > > > Which aren't async-safe? pthread stuff? > > Yes. All pthread_* namespace is not async-signal safe.
Ehh, I'm lame. All I need to do is to use cv_timedwait_sig() instead of cv_timedwait() and I can remove all pthread stuff from the sighandler. Thanks! -- Pawel Jakub Dawidek http://www.wheelsystems.com p...@freebsd.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am!
pgpKo3zrpQTMW.pgp
Description: PGP signature