summaryrefslogtreecommitdiff
path: root/signal.c
diff options
context:
space:
mode:
Diffstat (limited to 'signal.c')
-rw-r--r--signal.c14
1 files 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)];