mirror of
https://github.com/troglobit/libuev.git
synced 2026-10-01 05:22:25 +07:00
New siginfo member in uev_t for signal watchers
This patch adds support for exporting the signalfd_siginfo struct read from the signal fd descriptor on signals. This allows watcher callbacks to, e.g., figure out who sent a signal. See signalfd(2) for details on struct signalfd_siginfo. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/signalfd.h>
|
||||
|
||||
/*
|
||||
* List functions.
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
/*
|
||||
|
||||
+7
-1
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user