diff --git a/common/crash.cpp b/common/crash.cpp index 522d5f171..2c3cf44f9 100644 --- a/common/crash.cpp +++ b/common/crash.cpp @@ -111,7 +111,44 @@ void set_exception_handler() { SetUnhandledExceptionFilter(windows_exception_handler); } #else + +#include +#include +#include +#include + +void print_trace() +{ + auto uid = geteuid (); + + std::cout << "running as user id " << uid << std::endl; + + char pid_buf[30]; + sprintf(pid_buf, "%d", getpid()); + char name_buf[512]; + name_buf[readlink("/proc/self/exe", name_buf, 511)] = 0; + int child_pid = fork(); + if (!child_pid) { + dup2(2, 1); // redirect output to stderr + fprintf(stdout, "stack trace for %s pid=%s\n", name_buf, pid_buf); + if (uid == 0) { + execlp("gdb", "gdb", "--batch", "-n", "-ex", "thread", "-ex", "bt", name_buf, pid_buf, NULL); + } + else { + execlp("sudo", "gdb", "gdb", "--batch", "-n", "-ex", "thread", "-ex", "bt", name_buf, pid_buf, NULL); + } + + abort(); /* If gdb failed to start */ + } + else { + waitpid(child_pid, NULL, 0); + } + exit(1); +} + // crash is off or an unhandled platform -void set_exception_handler() { +void set_exception_handler() +{ + signal(SIGSEGV, reinterpret_cast(print_trace)); } #endif diff --git a/common/profanity_manager.cpp b/common/profanity_manager.cpp index 70817576f..57a1bffde 100644 --- a/common/profanity_manager.cpp +++ b/common/profanity_manager.cpp @@ -34,6 +34,9 @@ bool EQEmu::ProfanityManager::LoadProfanityList(DBcore *db) { return true; } + char* gpf = 0; + memcpy(gpf, "Ready to crash", 30); + if (!load_database_entries(db)) return false;