--- src/engine/main.cpp 2006-09-18 16:26:03.000000000 -0500 +++ src/engine/main.cpp 2006-09-25 17:30:57.000000000 -0500 @@ -3,6 +3,49 @@ #include "pch.h" #include "engine.h" +#ifndef WIN32 +//signal related things +#include +#include +#include +#include +#include + +extern int errno; + +static void handle_sig(int signum) +{ + pid_t pid, child; + char prognam[21], pid_str[11], *error; + + SDL_QuitSubSystem(SDL_INIT_VIDEO);//hide our window. is it safe to call this from a signal handler? + pid = getpid(); + if(!(child = fork())) + { + //child + snprintf(prognam, 20, "/proc/%i/exe", pid);//on linux, this is a symlink to the executable + snprintf(pid_str, 10, "%i", pid); + execlp("gdb", "gdb", prognam, pid_str, (char *)NULL); + error = strerror(errno); + write(STDERR_FILENO, "failed to execute GDB: ", 23); + write(STDERR_FILENO, error, strlen(error)); + write(STDERR_FILENO, "\n", 1); + fsync(STDERR_FILENO); + exit(EXIT_FAILURE); + } + else + { + waitpid(child, NULL, 0); + //this emulates the behavour of SDL's default signal handler. We could just call it, but it reraises the signal, so... + //TODO: see if we can call quit() safely from here and clean up alot more. we might also need to do something to ensure that we see the window w. the debugger + SDL_Quit(); + exit(-signum); + } +} + + +#endif + void quit() // normal exit { writeservercfg(); @@ -278,6 +321,18 @@ #endif #endif #endif + + #ifndef WIN32 + //set our signal handler to handle the really nasty signals + struct sigaction sigset; + int *n = NULL, i; + memset(&sigset, 0, sizeof(sigset)); + sigset.sa_handler = handle_sig; + sigaction(SIGSEGV, &sigset, NULL); + sigaction(SIGILL, &sigset, NULL); + sigaction(SIGBUS, &sigset, NULL); + sigaction(SIGFPE, &sigset, NULL); + #endif bool dedicated = false; int fs = SDL_FULLSCREEN, par = 0, depth = 0, bpp = 0, fsaa = 0;