signal handler satefy improvements from Theo DeRaadt

svn:r186
This commit is contained in:
Niels Provos 2005-12-03 17:52:47 +00:00
parent 65644dfb80
commit 68292e2f45

View File

@ -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)];