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 #endif
} rpi_t; } rpi_t;
static bool rpi_shutdown = false; static volatile sig_atomic_t rpi_shutdown = 0;
static void rpi_kill(int sig) static void rpi_kill(int sig)
{ {
(void)sig; (void)sig;
rpi_shutdown = true; rpi_shutdown = 1;
} }
static void rpi_set_nonblock_state(void *data, bool state) 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 #endif
signal(SIGINT, rpi_kill); struct sigaction sa;
signal(SIGTERM, rpi_kill); sa.sa_handler = rpi_kill;
sa.sa_flags = SA_RESTART;
sigemptyset(&sa.sa_mask);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
return rpi; return rpi;
} }

View File

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