Add an signal handler for SIGINT and SIGTERM

This allows the user to shut the client down by pressing ctrl-c in it's
terminal or by sendig SIGTERM.
This commit is contained in:
Yamagi Burmeister 2014-01-01 11:17:28 +01:00
parent ab220c10d6
commit be14aea08d
1 changed files with 13 additions and 1 deletions

View File

@ -20,7 +20,8 @@
* ======================================================================= * =======================================================================
* *
* This is a signal handler for printing some hints to debug problem in * This is a signal handler for printing some hints to debug problem in
* the case of a crash. On Linux a backtrace is printed. * the case of a crash. On Linux a backtrace is printed. Additionally
* a special handler for SIGINT and SIGTERM ist supplied.
* *
* ======================================================================= * =======================================================================
*/ */
@ -117,11 +118,22 @@ signalhandler(int sig)
raise(sig); raise(sig);
} }
void
terminate(int sig)
{
Cbuf_AddText("quit");
}
void void
registerHandler(void) registerHandler(void)
{ {
/* Crash */
signal(SIGSEGV, signalhandler); signal(SIGSEGV, signalhandler);
signal(SIGILL, signalhandler); signal(SIGILL, signalhandler);
signal(SIGFPE, signalhandler); signal(SIGFPE, signalhandler);
signal(SIGABRT, signalhandler); signal(SIGABRT, signalhandler);
/* User abort */
signal(SIGINT, terminate);
signal(SIGTERM, terminate);
} }