Get rid of the signal handler

SDL covers this via e.g. SDL_QUIT event on ctrl+c.
This commit is contained in:
dhewg 2012-07-06 01:27:46 +02:00
parent d2b7eac843
commit 0bc457063f
4 changed files with 0 additions and 149 deletions

View file

@ -663,7 +663,6 @@ if (APPLE)
sys/events.cpp sys/events.cpp
sys/sys_local.cpp sys/sys_local.cpp
sys/posix/posix_net.cpp sys/posix/posix_net.cpp
sys/posix/posix_signal.cpp
sys/posix/posix_main.cpp sys/posix/posix_main.cpp
) )
@ -700,7 +699,6 @@ else()
sys/events.cpp sys/events.cpp
sys/sys_local.cpp sys/sys_local.cpp
sys/posix/posix_net.cpp sys/posix/posix_net.cpp
sys/posix/posix_signal.cpp
sys/posix/posix_main.cpp sys/posix/posix_main.cpp
sys/linux/main.cpp sys/linux/main.cpp
) )

View file

@ -87,8 +87,6 @@ void Posix_Exit(int ret) {
Sys_Printf( "tcsetattr failed: %s\n", strerror( errno ) ); Sys_Printf( "tcsetattr failed: %s\n", strerror( errno ) );
} }
} }
// at this point, too late to catch signals
Posix_ClearSigs();
// process spawning. it's best when it happens after everything has shut down // process spawning. it's best when it happens after everything has shut down
if ( exit_spawn[0] ) { if ( exit_spawn[0] ) {
@ -360,7 +358,6 @@ Posix_EarlyInit
*/ */
void Posix_EarlyInit( void ) { void Posix_EarlyInit( void ) {
exit_spawn[0] = '\0'; exit_spawn[0] = '\0';
Posix_InitSigs();
} }
/* /*

View file

@ -40,9 +40,6 @@ void Posix_EarlyInit( );
// called after common has been initialized // called after common has been initialized
void Posix_LateInit( ); void Posix_LateInit( );
void Posix_InitSigs( );
void Posix_ClearSigs( );
void Posix_Exit( int ret ); void Posix_Exit( int ret );
void Posix_SetExit(int ret); // override the exit code void Posix_SetExit(int ret); // override the exit code
void Posix_SetExitSpawn( const char *exeName ); // set the process to be spawned when we quit void Posix_SetExitSpawn( const char *exeName ); // set the process to be spawned when we quit

View file

@ -1,141 +0,0 @@
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "sys/platform.h"
#include "framework/Common.h"
#include "sys/posix/posix_public.h"
const int siglist[] = {
SIGHUP,
SIGQUIT,
SIGILL,
SIGTRAP,
SIGIOT,
SIGBUS,
SIGSEGV,
SIGPIPE,
SIGABRT,
// SIGTTIN,
// SIGTTOU,
-1
};
const char *signames[] = {
"SIGHUP",
"SIGQUIT",
"SIGILL",
"SIGTRAP",
"SIGIOT",
"SIGBUS",
"SIGSEGV",
"SIGPIPE",
"SIGABRT",
// "SIGTTIN",
// "SIGTTOUT"
};
/*
================
Posix_ClearSigs
================
*/
void Posix_ClearSigs( ) {
struct sigaction action;
int i;
/* Set up the structure */
action.sa_handler = SIG_DFL;
sigemptyset( &action.sa_mask );
action.sa_flags = 0;
i = 0;
while ( siglist[ i ] != -1 ) {
if ( sigaction( siglist[ i ], &action, NULL ) != 0 ) {
Sys_Printf( "Failed to reset %s handler: %s\n", signames[ i ], strerror( errno ) );
}
i++;
}
}
/*
================
sig_handler
================
*/
static void sig_handler( int signum, siginfo_t *info, void *context ) {
static bool double_fault = false;
if ( double_fault ) {
Sys_Printf( "double fault %s, bailing out\n", strsignal( signum ) );
_exit( signum );
}
double_fault = true;
// NOTE: see sigaction man page, could verbose the whole siginfo_t and print human readable si_code
Sys_Printf( "signal caught: %s\nsi_code %d\n", strsignal( signum ), info->si_code );
Sys_Printf( "Trying to exit gracefully..\n" );
Posix_SetExit( signum );
common->Quit();
}
/*
================
Posix_InitSigs
================
*/
void Posix_InitSigs( ) {
struct sigaction action;
int i;
/* Set up the structure */
action.sa_sigaction = sig_handler;
sigemptyset( &action.sa_mask );
action.sa_flags = SA_SIGINFO | SA_NODEFER;
i = 0;
while ( siglist[ i ] != -1 ) {
if ( sigaction( siglist[ i ], &action, NULL ) != 0 ) {
Sys_Printf( "Failed to set %s handler: %s\n", signames[ i ], strerror( errno ) );
}
i++;
}
// if the process is backgrounded (running non interactively)
// then SIGTTIN or SIGTOU could be emitted, if not caught, turns into a SIGSTP
signal( SIGTTIN, SIG_IGN );
signal( SIGTTOU, SIG_IGN );
}