I was playing with the signal handling code anyway (seemed too complicated for me), so I've got a patch that fixes this problem and provides a new regress test. It just makes changes immediately in evsignal_add() and evsignal_del() and does not block/unblock signals.

This patch does not get rid of ncalls, which I'm also thinking of doing, as I mentioned in an earlier message to the list.

devpoll.c      |   15 +++--------
epoll.c        |   15 +++--------
evport.c       |   17 +++----------
evsignal.h     |    8 ++----
poll.c         |   15 +++--------
select.c       |   14 +++-------
signal.c | 74 +++++++++++++++ +-----------------------------------------
test/regress.c |   32 ++++++++++++++++++++++++
8 files changed, 76 insertions(+), 114 deletions(-)

There's one subtlety to it. With my change, evsignal_process() runs with signals unblocked, so timing is critical. The original code is then racy:

        TAILQ_FOREACH(ev, &signalqueue, ev_signal_next) {
                ncalls = evsigcaught[EVENT_SIGNAL(ev)];         <-- point A
                if (ncalls) {
                        if (!(ev->ev_events & EV_PERSIST))
                                event_del(ev);
                        event_active(ev, EV_SIGNAL, ncalls);
                }
        }

        memset(evsigcaught, 0, sizeof(evsigcaught));            <-- point B
        evsignal_caught = 0;                                    <-- point C

For any signal that is not already pending (ncalls == 0 when reaching its point A), if it arrives between then and its ncalls being cleared in point B, it will be lost. If it arrives after then but before evsignal_caught in point C, it will be arbitrarily delayed (until another signal comes along to set evsignal_caught).

I solved this by

* moving the evsignal_caught to before checking the individual signals for delivery (but after evsignal_caught is checked itself, in a different function). * setting "evsigcaught[x] = 0" only when we are setting that signal active.

--
Scott Lamb <http://www.slamb.org/>

Attachment: event-signal.patch
Description: Binary data

_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkey.org/mailman/listinfo/libevent-users

Reply via email to