From owner-freebsd-hackers@FreeBSD.ORG Sun Jul 11 21:40:21 2010 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5FE70106566C for ; Sun, 11 Jul 2010 21:40:21 +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 BDA0C8FC08 for ; Sun, 11 Jul 2010 21:40:20 +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 o6BLeHuU033023 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 12 Jul 2010 00:40:17 +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 o6BLeHA5080977; Mon, 12 Jul 2010 00:40:17 +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 o6BLeH0M080976; Mon, 12 Jul 2010 00:40:17 +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: Mon, 12 Jul 2010 00:40:17 +0300 From: Kostik Belousov To: Garrett Cooper Message-ID: <20100711214016.GR2408@deviant.kiev.zoral.com.ua> References: <20100711210843.GQ2408@deviant.kiev.zoral.com.ua> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="9lPOKfY2vCV97ybw" Content-Disposition: inline In-Reply-To: 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_50, 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: hackers@freebsd.org Subject: Re: *sigpause hanging on 8.x+ X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Jul 2010 21:40:21 -0000 --9lPOKfY2vCV97ybw Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Jul 11, 2010 at 02:30:01PM -0700, Garrett Cooper wrote: > On Sun, Jul 11, 2010 at 2:08 PM, Kostik Belousov wr= ote: > > On Sun, Jul 11, 2010 at 12:39:39PM -0700, Garrett Cooper wrote: > >> So, long story short... I've basically ported the open posix testsuite > >> to FreeBSD, and one of the tests tests out sigpause. Unfortunately the > >> sucker hangs on my dev box at home. > >> > >> I've written a short testcase that demonstrates this. It prints out: > >> > >> $ ~/test_sigpause > >> 0 > >> > >> And proceeds to be unresponsive to signals (except SIGSTOP / SIGKILL, > >> as expected). > >> > >> When I monkey around with libc's compat4.3 stuff a bit, this is what c= omes up: > >> > >> $ env LD_LIBRARY_PATH=3D$PWD:/usr/src/lib/libc/../libthr ~/test_sigpau= se > >> 0 > >> before sigemptyset > >> before _sigsuspend > >> > >> So it's getting stuck after calling _sigsuspend. > >> > >> I tried the same thing on a i386 8-STABLE VM and it hangs as well. > >> > >> I tried applying similar printfs in libthr but it's not hitting that > >> code at all (it's now responding to SIGTERM though, which is > >> interesting, but not too interesting to me). > >> > >> I also wrote similar code that exercised the functionality in > >> sigsuspend, by calling sigprocmask beforehand, and it works. > >> > >> Thoughts? > >> > >> -Garrett > >> > >> Dev machine: > >> FreeBSD bayonetta.local 9.0-CURRENT FreeBSD 9.0-CURRENT #1 > >> r206173:209901M: Sun Jul 11 04:18:42 PDT 2010 > >> root@:/usr/obj/usr/src/sys/BAYONETTA =9Aamd64 > >> VM: > >> FreeBSD starr-bastion.localdomain 8.0-STABLE FreeBSD 8.0-STABLE #0 > >> r207913: Tue May 11 06:21:57 UTC 2010 > >> root@starr-bastion.localdomain:/usr/obj/usr/src/sys/GENERIC =9Ai386 > >> > >> Index: compat-43/sigcompat.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 > >> --- compat-43/sigcompat.c =9A =9A (revision 206173) > >> +++ compat-43/sigcompat.c =9A =9A (working copy) > >> @@ -36,6 +36,7 @@ > >> =9A#include "namespace.h" > >> =9A#include > >> =9A#include > >> +#include > >> =9A#include > >> =9A#include "un-namespace.h" > >> =9A#include "libc_private.h" > >> @@ -102,7 +103,9 @@ > >> =9A{ > >> =9A =9A =9A sigset_t set; > >> > >> + =9A =9A printf("before sigemptyset\n"); > >> =9A =9A =9A sigemptyset(&set); > >> + =9A =9A printf("before _sigsuspend\n"); > >> =9A =9A =9A set.__bits[0] =3D mask; > >> =9A =9A =9A return (_sigsuspend(&set)); > >> =9A} > >> @@ -111,10 +114,16 @@ > >> =9Axsi_sigpause(int sig) > >> =9A{ > >> =9A =9A =9A sigset_t set; > >> + =9A =9A int rc; > >> > >> + =9A =9A printf("before sigemptyset\n"); > >> =9A =9A =9A sigemptyset(&set); > >> + =9A =9A printf("before sigaddset\n"); > >> =9A =9A =9A sigaddset(&set, sig); > >> - =9A =9A return (_sigsuspend(&set)); > >> + =9A =9A printf("before _sigsuspend\n"); > >> + =9A =9A rc =3D (_sigsuspend(&set)); > >> + =9A =9A printf("after _sigsuspend\n"); > >> + =9A =9A return rc; > >> =9A} > >> > >> =9Aint > >> > >> $ cat ~/test_sigpause.c > >> #include > >> #include > >> > >> int > >> main (void) > >> { > >> =9A =9A =9A =9A printf("0\n"); > >> =9A =9A =9A =9A fflush(stdout); > >> =9A =9A =9A =9A (void) sigpause(1); > >> =9A =9A =9A =9A return 0; > >> } > >> $ cat ~/test_sigsuspend.c > >> #include > >> #include > >> > >> int > >> main (void) > >> { > >> =9A =9A =9A =9A sigset_t oset; > >> =9A =9A =9A =9A sigset_t nset; > >> =9A =9A =9A =9A if (sigprocmask(1, &nset, &oset) =3D=3D -1) > >> =9A =9A =9A =9A =9A =9A =9A =9A err(1, "sigprocmask(-1, &nset, &oset)"= ); > >> =9A =9A =9A =9A if (sigprocmask(-1, &nset, &oset) =3D=3D -1) > >> =9A =9A =9A =9A =9A =9A =9A =9A err(1, "sigprocmask(-1, &nset, &oset)"= ); > >> =9A =9A =9A =9A return (sigsuspend(&nset)); > >> } > > > > It seems I got a sigmask for sigpause inside the xsi_sigpause() backwar= d. > > On the other hand, I do not understand what is your issue with sigpause= (). >=20 > The negative testcase from the open posix testsuite was setup so that > setting sigpause(-1) would return -1 with EINVAL, according to the > sig* manpages (-1 is an invalid signal of course). That isn't being > triggered with either function today. >=20 > 0 seems a bit wonky too (it's an invalid signal number). >=20 > My bet is that values greater than SIGRTMAX aren't interpreted properly e= ither. I will add these checks, thanks. >=20 > > diff --git a/lib/libc/compat-43/sigcompat.c b/lib/libc/compat-43/sigcom= pat.c > > index c3ba30a..bab9d5c 100644 > > --- a/lib/libc/compat-43/sigcompat.c > > +++ b/lib/libc/compat-43/sigcompat.c > > @@ -111,9 +111,12 @@ int > > =9Axsi_sigpause(int sig) > > =9A{ > > =9A =9A =9A =9Asigset_t set; > > + =9A =9A =9A int error; > > > > - =9A =9A =9A sigemptyset(&set); > > - =9A =9A =9A sigaddset(&set, sig); > > + =9A =9A =9A error =3D _sigprocmask(SIG_BLOCK, NULL, &set); > > + =9A =9A =9A if (error !=3D 0) > > + =9A =9A =9A =9A =9A =9A =9A return (error); > > + =9A =9A =9A sigdelset(&set, sig); > > =9A =9A =9A =9Areturn (_sigsuspend(&set)); > > =9A} >=20 > Doesn't this violate the restore clause noted in the manpage? >=20 > The xsi_sigpause() function removes sig from the signal mask of the = call- > ing process and suspend the calling process until a signal is receiv= ed. > The xsi_sigpause() function restores the signal mask of the process = to > its original state before returning. >=20 > So if I had a sigset defined above with sig, then redefined it, I > would be whacking the previous handler by passing in NULL to > _sigprocmask, correct? If so, sigpause has issues too in its > implementation. No, not correct. Read the description of sigsuspend. Also note that the sigprocmask call does not change process mask. >=20 > There's also some interesting SIGDELSET action going on in libthr's > copy of _sigsuspend's with SIGCANCEL (apparently that's the unofficial > alias for SIGRTMIN as defined by libthr), but that's a sidenote for > the actual issue seen here. >=20 > Thanks! > -Garrett --9lPOKfY2vCV97ybw Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (FreeBSD) iEYEARECAAYFAkw6OkAACgkQC3+MBN1Mb4geJwCgyQz9p1k0/WB8UYWFQQvQwQfn Q9YAoN4NM4ArLLI1TW6TjVSXESBX1iTf =XVE0 -----END PGP SIGNATURE----- --9lPOKfY2vCV97ybw--