Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Jul 2010 00:40:17 +0300
From:      Kostik Belousov <kostikbel@gmail.com>
To:        Garrett Cooper <yanegomi@gmail.com>
Cc:        hackers@freebsd.org
Subject:   Re: *sigpause hanging on 8.x+
Message-ID:  <20100711214016.GR2408@deviant.kiev.zoral.com.ua>
In-Reply-To: <AANLkTimjk7oJKlB7YCrZimMsTQtvKIxipZtfBfpIdSz3@mail.gmail.com>
References:  <AANLkTikfxu3BjQE4nnNJ-VeNSDy9vhfXEhY1XQ4jWtY4@mail.gmail.com> <20100711210843.GQ2408@deviant.kiev.zoral.com.ua> <AANLkTimjk7oJKlB7YCrZimMsTQtvKIxipZtfBfpIdSz3@mail.gmail.com>

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

--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 <kostikbel@gmail.com> 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 <sys/param.h>
> >> =9A#include <signal.h>
> >> +#include <stdio.h>
> >> =9A#include <string.h>
> >> =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 <signal.h>
> >> #include <stdio.h>
> >>
> >> 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 <err.h>
> >> #include <signal.h>
> >>
> >> 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--



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