From owner-svn-src-all@FreeBSD.ORG Sat Aug 28 08:50:56 2010 Return-Path: Delivered-To: svn-src-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8B3B410656A3; Sat, 28 Aug 2010 08:50:56 +0000 (UTC) (envelope-from pjd@garage.freebsd.pl) Received: from mail.garage.freebsd.pl (60.wheelsystems.com [83.12.187.60]) by mx1.freebsd.org (Postfix) with ESMTP id 30E018FC14; Sat, 28 Aug 2010 08:50:55 +0000 (UTC) Received: by mail.garage.freebsd.pl (Postfix, from userid 65534) id 91AFE45E86; Sat, 28 Aug 2010 10:50:54 +0200 (CEST) Received: from localhost (chello089077043238.chello.pl [89.77.43.238]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.garage.freebsd.pl (Postfix) with ESMTP id 4092245CD8; Sat, 28 Aug 2010 10:50:49 +0200 (CEST) Date: Sat, 28 Aug 2010 10:50:42 +0200 From: Pawel Jakub Dawidek To: Kostik Belousov Message-ID: <20100828085042.GE2077@garage.freebsd.pl> References: <201008272049.o7RKn63o007138@svn.freebsd.org> <20100827213827.GD2396@deviant.kiev.zoral.com.ua> <20100827215402.GB2077@garage.freebsd.pl> <20100828084355.GH2396@deviant.kiev.zoral.com.ua> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="5oH/S/bF6lOfqCQb" Content-Disposition: inline In-Reply-To: <20100828084355.GH2396@deviant.kiev.zoral.com.ua> User-Agent: Mutt/1.4.2.3i X-PGP-Key-URL: http://people.freebsd.org/~pjd/pjd.asc X-OS: FreeBSD 9.0-CURRENT amd64 X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on mail.garage.freebsd.pl X-Spam-Level: X-Spam-Status: No, score=-0.6 required=4.5 tests=BAYES_00,RCVD_IN_SORBS_DUL autolearn=no version=3.0.4 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-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Aug 2010 08:50:56 -0000 --5oH/S/bF6lOfqCQb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 a= fter > > > the check is done but before the sleep, you loose. > >=20 > > 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. > >=20 > > > 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. > >=20 > > Which aren't async-safe? pthread stuff? >=20 > 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! --=20 Pawel Jakub Dawidek http://www.wheelsystems.com pjd@FreeBSD.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am! --5oH/S/bF6lOfqCQb Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (FreeBSD) iEYEARECAAYFAkx4zeEACgkQForvXbEpPzQzVwCg6vf4JuovOKYGcXPIkBI+M8fK 6egAoJbBt5qDJAxFcTbQozb+dQUVfFK/ =EJHx -----END PGP SIGNATURE----- --5oH/S/bF6lOfqCQb--