diff --git a/src/private.h b/src/private.h index 1238a9d..6714f06 100644 --- a/src/private.h +++ b/src/private.h @@ -27,6 +27,7 @@ #include #include +#include /* * List functions. diff --git a/src/uev.c b/src/uev.c index d839b05..9b2e6af 100644 --- a/src/uev.c +++ b/src/uev.c @@ -369,7 +369,9 @@ int uev_run(uev_ctx_t *ctx, int flags) uev_signal_stop(w); events = UEV_ERROR; } - } + memset(&w->siginfo, 0, sizeof(w->siginfo)); + } else + w->siginfo = fdsi; break; case UEV_TIMER_TYPE: diff --git a/src/uev.h b/src/uev.h index 5e25b90..b860b8c 100644 --- a/src/uev.h +++ b/src/uev.h @@ -61,6 +61,9 @@ typedef struct uev { int signo; int fd; uev_ctx_t *ctx; + + /* Extra data for certain watcher types */ + struct signalfd_siginfo siginfo; } uev_t; /* diff --git a/tests/signal.c b/tests/signal.c index 6a25d10..b989d67 100644 --- a/tests/signal.c +++ b/tests/signal.c @@ -67,14 +67,20 @@ static int callback(arg_t *arg, int event, void *foo) static void sigsegv_cb(uev_t *w, void *arg, int events) { + printf("Got SIGSEGV (%d) from PID %d\n", w->siginfo.ssi_signo, + w->siginfo.ssi_pid); warnx("PID %d caused segfault.", getpid()); exit(-1); } static void sigchld_cb(uev_t *w, void *arg, int events) { - pid_t pid = waitpid(-1, NULL, WNOHANG); + pid_t pid; + printf("Got SIGCHLD (%d) from PID %d\n", + w->siginfo.ssi_signo, w->siginfo.ssi_pid); + + pid = waitpid(-1, NULL, WNOHANG); if (-1 != pid) warnx("PID %d exited, bye.", pid); }