Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Aug 2010 00:38:27 +0300
From:      Kostik Belousov <kostikbel@gmail.com>
To:        Pawel Jakub Dawidek <pjd@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r211896 - head/sbin/hastd
Message-ID:  <20100827213827.GD2396@deviant.kiev.zoral.com.ua>
In-Reply-To: <201008272049.o7RKn63o007138@svn.freebsd.org>
References:  <201008272049.o7RKn63o007138@svn.freebsd.org>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
On Fri, Aug 27, 2010 at 08:49:06PM +0000, Pawel Jakub Dawidek wrote:
> Author: pjd
> Date: Fri Aug 27 20:49:06 2010
> New Revision: 211896
> URL: http://svn.freebsd.org/changeset/base/211896
> 
> Log:
>   Check if no signals were delivered just before going to sleep.
>   
>   MFC after:	2 weeks
>   Obtained from:	Wheel Systems Sp. z o.o. http://www.wheelsystems.com
> 
> Modified:
>   head/sbin/hastd/primary.c
> 
> Modified: head/sbin/hastd/primary.c
> ==============================================================================
> --- 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.

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.

[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (FreeBSD)

iEYEARECAAYFAkx4MFMACgkQC3+MBN1Mb4jynwCffUXFzlOu83zhUyVCrxI8POfT
rIEAniRX+OPh21oUBgrZyes/YzqrMZcL
=n2kn
-----END PGP SIGNATURE-----
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100827213827.GD2396>