This commit is contained in:
Akkadius 2019-09-23 00:47:57 -05:00
parent 54053f7e24
commit 161edef2a8
2 changed files with 41 additions and 1 deletions

View File

@ -111,7 +111,44 @@ void set_exception_handler() {
SetUnhandledExceptionFilter(windows_exception_handler);
}
#else
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
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<void (*)(int)>(print_trace));
}
#endif

View File

@ -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;