From 0bc457063f045499b825daa4a082aa3455fd9b45 Mon Sep 17 00:00:00 2001 From: dhewg Date: Fri, 6 Jul 2012 01:27:46 +0200 Subject: [PATCH] Get rid of the signal handler SDL covers this via e.g. SDL_QUIT event on ctrl+c. --- neo/CMakeLists.txt | 2 - neo/sys/posix/posix_main.cpp | 3 - neo/sys/posix/posix_public.h | 3 - neo/sys/posix/posix_signal.cpp | 141 --------------------------------- 4 files changed, 149 deletions(-) delete mode 100644 neo/sys/posix/posix_signal.cpp diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index c86cb8f0..1c43d86e 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -663,7 +663,6 @@ if (APPLE) sys/events.cpp sys/sys_local.cpp sys/posix/posix_net.cpp - sys/posix/posix_signal.cpp sys/posix/posix_main.cpp ) @@ -700,7 +699,6 @@ else() sys/events.cpp sys/sys_local.cpp sys/posix/posix_net.cpp - sys/posix/posix_signal.cpp sys/posix/posix_main.cpp sys/linux/main.cpp ) diff --git a/neo/sys/posix/posix_main.cpp b/neo/sys/posix/posix_main.cpp index 55f8bfdd..b93b0036 100644 --- a/neo/sys/posix/posix_main.cpp +++ b/neo/sys/posix/posix_main.cpp @@ -87,8 +87,6 @@ void Posix_Exit(int ret) { 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 if ( exit_spawn[0] ) { @@ -360,7 +358,6 @@ Posix_EarlyInit */ void Posix_EarlyInit( void ) { exit_spawn[0] = '\0'; - Posix_InitSigs(); } /* diff --git a/neo/sys/posix/posix_public.h b/neo/sys/posix/posix_public.h index bf1e6e10..c03fbbf9 100644 --- a/neo/sys/posix/posix_public.h +++ b/neo/sys/posix/posix_public.h @@ -40,9 +40,6 @@ void Posix_EarlyInit( ); // called after common has been initialized void Posix_LateInit( ); -void Posix_InitSigs( ); -void Posix_ClearSigs( ); - void Posix_Exit( int ret ); void Posix_SetExit(int ret); // override the exit code void Posix_SetExitSpawn( const char *exeName ); // set the process to be spawned when we quit diff --git a/neo/sys/posix/posix_signal.cpp b/neo/sys/posix/posix_signal.cpp deleted file mode 100644 index 774c5f7c..00000000 --- a/neo/sys/posix/posix_signal.cpp +++ /dev/null @@ -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 . - -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 -#include -#include - -#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 ); -}