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

[-- Attachment #1 --]
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> wrote:
> > 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 comes up:
> >>
> >> $ env LD_LIBRARY_PATH=$PWD:/usr/src/lib/libc/../libthr ~/test_sigpause
> >> 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 šamd64
> >> 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 ši386
> >>
> >> Index: compat-43/sigcompat.c
> >> ===================================================================
> >> --- compat-43/sigcompat.c š š (revision 206173)
> >> +++ compat-43/sigcompat.c š š (working copy)
> >> @@ -36,6 +36,7 @@
> >> š#include "namespace.h"
> >> š#include <sys/param.h>
> >> š#include <signal.h>
> >> +#include <stdio.h>
> >> š#include <string.h>
> >> š#include "un-namespace.h"
> >> š#include "libc_private.h"
> >> @@ -102,7 +103,9 @@
> >> š{
> >> š š š sigset_t set;
> >>
> >> + š š printf("before sigemptyset\n");
> >> š š š sigemptyset(&set);
> >> + š š printf("before _sigsuspend\n");
> >> š š š set.__bits[0] = mask;
> >> š š š return (_sigsuspend(&set));
> >> š}
> >> @@ -111,10 +114,16 @@
> >> šxsi_sigpause(int sig)
> >> š{
> >> š š š sigset_t set;
> >> + š š int rc;
> >>
> >> + š š printf("before sigemptyset\n");
> >> š š š sigemptyset(&set);
> >> + š š printf("before sigaddset\n");
> >> š š š sigaddset(&set, sig);
> >> - š š return (_sigsuspend(&set));
> >> + š š printf("before _sigsuspend\n");
> >> + š š rc = (_sigsuspend(&set));
> >> + š š printf("after _sigsuspend\n");
> >> + š š return rc;
> >> š}
> >>
> >> šint
> >>
> >> $ cat ~/test_sigpause.c
> >> #include <signal.h>
> >> #include <stdio.h>
> >>
> >> int
> >> main (void)
> >> {
> >> š š š š printf("0\n");
> >> š š š š fflush(stdout);
> >> š š š š (void) sigpause(1);
> >> š š š š return 0;
> >> }
> >> $ cat ~/test_sigsuspend.c
> >> #include <err.h>
> >> #include <signal.h>
> >>
> >> int
> >> main (void)
> >> {
> >> š š š š sigset_t oset;
> >> š š š š sigset_t nset;
> >> š š š š if (sigprocmask(1, &nset, &oset) == -1)
> >> š š š š š š š š err(1, "sigprocmask(-1, &nset, &oset)");
> >> š š š š if (sigprocmask(-1, &nset, &oset) == -1)
> >> š š š š š š š š err(1, "sigprocmask(-1, &nset, &oset)");
> >> š š š š return (sigsuspend(&nset));
> >> }
> >
> > It seems I got a sigmask for sigpause inside the xsi_sigpause() backward.
> > On the other hand, I do not understand what is your issue with sigpause().
> 
> 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.
> 
> 0 seems a bit wonky too (it's an invalid signal number).
> 
> My bet is that values greater than SIGRTMAX aren't interpreted properly either.
I will add these checks, thanks.

> 
> > diff --git a/lib/libc/compat-43/sigcompat.c b/lib/libc/compat-43/sigcompat.c
> > index c3ba30a..bab9d5c 100644
> > --- a/lib/libc/compat-43/sigcompat.c
> > +++ b/lib/libc/compat-43/sigcompat.c
> > @@ -111,9 +111,12 @@ int
> > šxsi_sigpause(int sig)
> > š{
> > š š š šsigset_t set;
> > + š š š int error;
> >
> > - š š š sigemptyset(&set);
> > - š š š sigaddset(&set, sig);
> > + š š š error = _sigprocmask(SIG_BLOCK, NULL, &set);
> > + š š š if (error != 0)
> > + š š š š š š š return (error);
> > + š š š sigdelset(&set, sig);
> > š š š šreturn (_sigsuspend(&set));
> > š}
> 
> Doesn't this violate the restore clause noted in the manpage?
> 
>      The xsi_sigpause() function removes sig from the signal mask of the call-
>      ing process and suspend the calling process until a signal is received.
>      The xsi_sigpause() function restores the signal mask of the process to
>      its original state before returning.
> 
> 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.

> 
> 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.
> 
> Thanks!
> -Garrett

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

iEYEARECAAYFAkw6OkAACgkQC3+MBN1Mb4geJwCgyQz9p1k0/WB8UYWFQQvQwQfn
Q9YAoN4NM4ArLLI1TW6TjVSXESBX1iTf
=XVE0
-----END PGP SIGNATURE-----

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