Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 06 Sep 2021 10:50:30 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 258310] kevent() does not see signal with zero timeout
Message-ID:  <bug-258310-227@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D258310

            Bug ID: 258310
           Summary: kevent() does not see signal with zero timeout
           Product: Base System
           Version: 13.0-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: arichardson@FreeBSD.org

While adding patches to natively support FreeBSD in wayland, I noticed that
epoll-shim (used to emulate epoll with kqueue) didn't report signals sent to
self via kill() unless I added a non-zero timeout (even in a single-threaded
test program). In https://github.com/jiixyj/epoll-shim/pull/32=20
Jan Kokem=C3=BCller provided a reduced test case using only kqueue and keve=
nt:

```
#ifdef NDEBUG
#undef NDEBUG
#endif

#define _GNU_SOURCE

#include <sys/types.h>

#include <sys/event.h>

#include <assert.h>
#include <errno.h>
#include <signal.h>
#include <stdlib.h>

#include <poll.h>
#include <unistd.h>

int
main(void)
{
        int rv;

        sigset_t set;
        rv =3D sigemptyset(&set);
        assert(rv =3D=3D 0);
        rv =3D sigaddset(&set, SIGUSR1);
        assert(rv =3D=3D 0);

        rv =3D sigprocmask(SIG_BLOCK, &set, NULL);
        assert(rv =3D=3D 0);

        int skq =3D kqueue();
        assert(skq >=3D 0);

        struct kevent kev;
        EV_SET(&kev, SIGUSR1, EVFILT_SIGNAL, EV_ADD, 0, 0, 0);
        rv =3D kevent(skq, &kev, 1, NULL, 0, NULL);
        assert(rv =3D=3D 0);

        int kq =3D kqueue();
        assert(kq >=3D 0);

        EV_SET(&kev, skq, EVFILT_READ, EV_ADD | EV_CLEAR, 0, 0, 0);
        rv =3D kevent(kq, &kev, 1, NULL, 0, NULL);
        assert(rv =3D=3D 0);

        for (;;) {
                rv =3D kill(getpid(), SIGUSR1);
                assert(rv =3D=3D 0);

                /* Turn this into `#if 1` to avoid the race. */
#if 0
                rv =3D kevent(kq, NULL, 0, &kev, 1, NULL);
#else
                rv =3D kevent(kq, NULL, 0, &kev, 1, &(struct timespec) { 0,=
 0 });
#endif
                assert(rv =3D=3D 1);
                rv =3D kevent(kq, NULL, 0, &kev, 1, &(struct timespec) { 0,=
 0 });
                assert(rv =3D=3D 0);

                rv =3D kevent(skq, NULL, 0, &kev, 1, &(struct timespec) { 0=
, 0
});
                assert(rv =3D=3D 1);
                rv =3D kevent(skq, NULL, 0, &kev, 1, &(struct timespec) { 0=
, 0
});
                assert(rv =3D=3D 0);

                siginfo_t siginfo;

                rv =3D sigtimedwait(&set, &siginfo, &(struct timespec) { 0,=
 0 });
                assert(rv =3D=3D SIGUSR1);

                rv =3D sigtimedwait(&set, &siginfo, &(struct timespec) { 0,=
 0 });
                assert(rv < 0);
                assert(errno =3D=3D EAGAIN);
        }
}
```

Is this behaviour expected or a bug?

--=20
You are receiving this mail because:
You are the assignee for the bug.=



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