From 68292e2f45dabe21a301c0bb5864e2c2026176f3 Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Sat, 3 Dec 2005 17:52:47 +0000 Subject: [PATCH] signal handler satefy improvements from Theo DeRaadt svn:r186 --- signal.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/signal.c b/signal.c index 19a85f14..978b7ba2 100644 --- 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)]; -- 2.40.0