signal -> sigaction

This commit is contained in:
Toad King 2012-06-19 14:14:00 -04:00
parent 0337e4fc0f
commit 3e1b621e7a
2 changed files with 18 additions and 11 deletions

View File

@ -66,12 +66,12 @@ typedef struct {
#endif
} rpi_t;
static bool rpi_shutdown = false;
static volatile sig_atomic_t rpi_shutdown = 0;
static void rpi_kill(int sig)
{
(void)sig;
rpi_shutdown = true;
rpi_shutdown = 1;
}
static void rpi_set_nonblock_state(void *data, bool state)
@ -219,8 +219,12 @@ static void *rpi_init(const video_info_t *video, const input_driver_t **input, v
}
#endif
signal(SIGINT, rpi_kill);
signal(SIGTERM, rpi_kill);
struct sigaction sa;
sa.sa_handler = rpi_kill;
sa.sa_flags = SA_RESTART;
sigemptyset(&sa.sa_mask);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
return rpi;
}

View File

@ -164,7 +164,6 @@ static void linuxraw_resetKbmd()
static void linuxraw_exitGracefully(int sig)
{
linuxraw_resetKbmd();
signal(sig, SIG_DFL);
kill(getpid(), sig);
}
@ -199,13 +198,17 @@ static void *linuxraw_input_init(void)
return NULL;
}
struct sigaction sa;
sa.sa_handler = linuxraw_exitGracefully;
sa.sa_flags = SA_RESTART | SA_RESETHAND;
sigemptyset(&sa.sa_mask);
// trap some standard termination codes so we can restore the keyboard before we lose control
signal(SIGABRT, linuxraw_exitGracefully);
signal(SIGBUS, linuxraw_exitGracefully);
signal(SIGFPE, linuxraw_exitGracefully);
signal(SIGILL, linuxraw_exitGracefully);
signal(SIGQUIT, linuxraw_exitGracefully);
signal(SIGSEGV, linuxraw_exitGracefully);
sigaction(SIGABRT, &sa, NULL);
sigaction(SIGBUS, &sa, NULL);
sigaction(SIGFPE, &sa, NULL);
sigaction(SIGILL, &sa, NULL);
sigaction(SIGQUIT, &sa, NULL);
sigaction(SIGSEGV, &sa, NULL);
atexit(linuxraw_resetKbmd);