]> granicus.if.org Git - libevent/commitdiff
signal handler satefy improvements from Theo DeRaadt
authorNiels Provos <provos@gmail.com>
Sat, 3 Dec 2005 17:52:47 +0000 (17:52 +0000)
committerNiels Provos <provos@gmail.com>
Sat, 3 Dec 2005 17:52:47 +0000 (17:52 +0000)
svn:r186

signal.c

index 19a85f1477141a7e8f2ed1cd24096bd7289d99d3..978b7ba2f3ac9eb66e7afa4d1c538933986045fc 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -52,7 +52,7 @@
 
 extern struct event_list signalqueue;
 
-static short evsigcaught[NSIG];
+static sig_atomic_t evsigcaught[NSIG];
 static int needrecalc;
 volatile sig_atomic_t evsignal_caught = 0;
 
@@ -61,11 +61,12 @@ static int ev_signal_pair[2];
 static int ev_signal_added;
 
 /* Callback for when the signal handler write a byte to our signaling socket */
-static void evsignal_cb(int fd, short what, void *arg)
+static void
+evsignal_cb(int fd, short what, void *arg)
 {
        static char signals[100];
        struct event *ev = arg;
-       int n;
+       ssize_t n;
 
        n = read(fd, signals, sizeof(signals));
        if (n == -1)
@@ -98,6 +99,8 @@ evsignal_init(sigset_t *evsigmask)
        FD_CLOSEONEXEC(ev_signal_pair[0]);
        FD_CLOSEONEXEC(ev_signal_pair[1]);
 
+       fcntl(ev_signal_pair[0], F_SETFL, O_NONBLOCK);
+
        event_set(&ev_signal, ev_signal_pair[1], EV_READ,
            evsignal_cb, &ev_signal);
        ev_signal.ev_flags |= EVLIST_INTERNAL;
@@ -135,11 +138,14 @@ evsignal_del(sigset_t *evsigmask, struct event *ev)
 static void
 evsignal_handler(int sig)
 {
+       int save_errno = errno;
+
        evsigcaught[sig]++;
        evsignal_caught = 1;
 
        /* Wake up our notification mechanism */
        write(ev_signal_pair[0], "a", 1);
+       errno = save_errno;
 }
 
 int
@@ -187,7 +193,7 @@ void
 evsignal_process(void)
 {
        struct event *ev;
-       short ncalls;
+       sig_atomic_t ncalls;
 
        TAILQ_FOREACH(ev, &signalqueue, ev_signal_next) {
                ncalls = evsigcaught[EVENT_SIGNAL(ev)];