Fix the SIGSEGV handling

We can't use libev's signal handling here but have to use sigaction() directly,
because libev only writes to a pipe in the real signal handler and then calls
our callback in the next main loop iteration.
The problem here is that returning from a SIGSEGV signal handler is a in
general a Bad Idea (tm) and thus we need to use a "direct" signal handler.

Signed-off-by: Uli Schlachter <psychon@znc.in>
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Uli Schlachter 2009-06-05 23:44:37 +02:00 committed by Julien Danjou
parent 4b27986680
commit 60bceccafe

View file

@ -236,7 +236,7 @@ xerrorstart(void * data __attribute__ ((unused)),
}
static void
signal_fatal(EV_P_ ev_signal *w, int revents)
signal_fatal(int signum)
{
buffer_t buf;
backtrace_get(&buf);
@ -408,7 +408,6 @@ main(int argc, char **argv)
ev_signal_init(&sigint, exit_on_signal, SIGINT);
ev_signal_init(&sigterm, exit_on_signal, SIGTERM);
ev_signal_init(&sighup, restart_on_signal, SIGHUP);
ev_signal_init(&sighup, signal_fatal, SIGSEGV);
ev_signal_start(globalconf.loop, &sigint);
ev_signal_start(globalconf.loop, &sigterm);
ev_signal_start(globalconf.loop, &sighup);
@ -416,6 +415,10 @@ main(int argc, char **argv)
ev_unref(globalconf.loop);
ev_unref(globalconf.loop);
struct sigaction sa = { .sa_handler = signal_fatal, .sa_flags = 0 };
sigemptyset(&sa.sa_mask);
sigaction(SIGSEGV, &sa, 0);
/* X stuff */
globalconf.connection = xcb_connect(NULL, &globalconf.default_screen);
if(xcb_connection_has_error(globalconf.connection))