medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit e6a259265b20e642e0c5a670f5bf98b9ae3169fb
parent ee78efce9cee4931b4ddbe1cd73d8707cb3d07e2
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Tue Oct 18 19:54:26 +0300

Really remove signal handlers + cleanup

Diffstat:
autogdb.h | 34++++++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 8 deletions(-)
diff --git a/autogdb.h b/autogdb.h @@ -10,14 +10,22 @@ #include <unistd.h> #include <err.h> +static void pause_forever( int signal ) { + while( true ) { + pause(); + } +} + static void uninstall_debug_signal_handlers() { signal( SIGINT, SIG_DFL ); - signal( SIGILL, SIG_DFL ); - signal( SIGABRT, SIG_DFL ); - signal( SIGSEGV, SIG_DFL ); + signal( SIGILL, pause_forever ); + signal( SIGABRT, pause_forever ); + signal( SIGSEGV, pause_forever ); } static void prompt_to_run_gdb( int signal ) { + uninstall_debug_signal_handlers(); + const char * signal_names[ NSIG ]; signal_names[ SIGINT ] = "SIGINT"; signal_names[ SIGILL ] = "SIGILL"; @@ -30,11 +38,15 @@ static void prompt_to_run_gdb( int signal ) { char buf[ 2 ]; read( STDIN_FILENO, &buf, sizeof( buf ) ); - if( buf[ 0 ] != 'y' ) exit( 1 ); + if( buf[ 0 ] != 'y' ) { + exit( 1 ); + } // fork off and run gdb pid_t child_pid = fork(); - if( child_pid == -1 ) err( 1, "fork" ); + if( child_pid == -1 ) { + err( 1, "fork" ); + } if( child_pid == 0 ) { execlp( "gdbx", "gdbx", "--", "-q", "-p", crashed_pid, ( char * ) 0 ); @@ -58,11 +70,15 @@ static void install_debug_signal_handlers( bool debug_on_sigint ) { static bool being_debugged() { pid_t parent_pid = getpid(); pid_t child_pid = fork(); - if( child_pid == -1 ) err( 1, "fork" ); + if( child_pid == -1 ) { + err( 1, "fork" ); + } if( child_pid == 0 ) { // if we can't ptrace the parent then gdb is already there - if( ptrace( PTRACE_ATTACH, parent_pid, NULL, NULL ) != 0 ) exit( 1 ); + if( ptrace( PTRACE_ATTACH, parent_pid, NULL, NULL ) != 0 ) { + exit( 1 ); + } // ptrace automatically stops the process so wait for SIGSTOP and send PTRACE_CONT waitpid( parent_pid, NULL, 0 ); @@ -75,7 +91,9 @@ static bool being_debugged() { int status; waitpid( child_pid, &status, 0 ); - if( !WIFEXITED( status ) ) err( 1, "WIFEXITED" ); + if( !WIFEXITED( status ) ) { + err( 1, "WIFEXITED" ); + } return WEXITSTATUS( status ) == 1; }