From owner-svn-src-head@FreeBSD.ORG Fri Aug 27 21:38:32 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F170F10656A9; Fri, 27 Aug 2010 21:38:32 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 4C4F18FC0A; Fri, 27 Aug 2010 21:38:31 +0000 (UTC) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id o7RLcR4t083035 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 28 Aug 2010 00:38:27 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4) with ESMTP id o7RLcRAw038234; Sat, 28 Aug 2010 00:38:27 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4/Submit) id o7RLcRsJ038233; Sat, 28 Aug 2010 00:38:27 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 28 Aug 2010 00:38:27 +0300 From: Kostik Belousov To: Pawel Jakub Dawidek Message-ID: <20100827213827.GD2396@deviant.kiev.zoral.com.ua> References: <201008272049.o7RKn63o007138@svn.freebsd.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="xdcVs9Jnmkyfpfbh" Content-Disposition: inline In-Reply-To: <201008272049.o7RKn63o007138@svn.freebsd.org> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-2.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_40, DNS_FROM_OPENWHOIS autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r211896 - head/sbin/hastd X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Aug 2010 21:38:33 -0000 --xdcVs9Jnmkyfpfbh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 >=20 > Log: > Check if no signals were delivered just before going to sleep. > =20 > MFC after: 2 weeks > Obtained from: Wheel Systems Sp. z o.o. http://www.wheelsystems.com >=20 > Modified: > head/sbin/hastd/primary.c >=20 > Modified: head/sbin/hastd/primary.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- 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. --xdcVs9Jnmkyfpfbh Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (FreeBSD) iEYEARECAAYFAkx4MFMACgkQC3+MBN1Mb4jynwCffUXFzlOu83zhUyVCrxI8POfT rIEAniRX+OPh21oUBgrZyes/YzqrMZcL =n2kn -----END PGP SIGNATURE----- --xdcVs9Jnmkyfpfbh--