diff --git a/client/src/main.c b/client/src/main.c index 19c3b7c6..8c86f188 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -2064,7 +2064,7 @@ int main(int argc, char * argv[]) DEBUG_INFO("Locking Method: " LG_LOCK_MODE); cpuInfo_log(); - if (!installCrashHandler("/proc/self/exe")) + if (!installCrashHandler("/proc/self/exe", argv[0])) DEBUG_WARN("Failed to install the crash handler"); lgPathsInit("looking-glass"); diff --git a/common/include/common/crash.h b/common/include/common/crash.h index 57b187c3..4913c9f4 100644 --- a/common/include/common/crash.h +++ b/common/include/common/crash.h @@ -23,7 +23,7 @@ #include -bool installCrashHandler(const char * exe); +bool installCrashHandler(const char * exe, char * argv0); void cleanupCrashHandler(void); void printAllThreadBacktraces(void); diff --git a/common/src/platform/linux/crash.c b/common/src/platform/linux/crash.c index 6a0d47b3..6b91af33 100644 --- a/common/src/platform/linux/crash.c +++ b/common/src/platform/linux/crash.c @@ -41,6 +41,7 @@ #include #include #define CRASH_MAX_FRAMES 64 +#define CRASH_REPORTER_NAME "lg_crash_handler" enum CrashRequestType { @@ -305,8 +306,26 @@ raw: DEBUG_ERROR("[trace]: (%u) 0x%" PRIxPTR, i, request->frames[i]); } -static void reporterLoop(pid_t parent, int requestFd, int responseFd) +static void reporterLoop( + pid_t parent, int requestFd, int responseFd, char * argv0) { + if (prctl(PR_SET_NAME, CRASH_REPORTER_NAME) != 0) + DEBUG_WARN("Unable to set the crash reporter process name"); + + if (argv0) + { + const size_t capacity = strlen(argv0); + const size_t nameLength = strlen(CRASH_REPORTER_NAME); + const size_t copyLength = + capacity < nameLength ? capacity : nameLength; + + memset(argv0, 0, capacity); + memcpy(argv0, CRASH_REPORTER_NAME, copyLength); + + if (capacity < nameLength) + DEBUG_WARN("Unable to set the full crash reporter command line name"); + } + // Do not leave an orphaned reporter if the client exits unexpectedly before // it closes the request pipe. prctl(PR_SET_PDEATHSIG, SIGKILL); @@ -328,7 +347,7 @@ static void reporterLoop(pid_t parent, int requestFd, int responseFd) } } -static bool startReporter(void) +static bool startReporter(char * argv0) { int requestPipe[2]; int responsePipe[2]; @@ -368,7 +387,7 @@ static bool startReporter(void) { close(requestPipe [1]); close(responsePipe[0]); - reporterLoop(parent, requestPipe[0], responsePipe[1]); + reporterLoop(parent, requestPipe[0], responsePipe[1], argv0); close(requestPipe [0]); close(responsePipe[1]); _exit(0); @@ -511,11 +530,11 @@ static void crit_err_hdlr(int sig_num, siginfo_t * info, void * ucontext) _exit(128 + sig_num); } -bool installCrashHandler(const char * exe) +bool installCrashHandler(const char * exe, char * argv0) { (void)exe; - if (!startReporter()) + if (!startReporter(argv0)) return false; struct sigaction sigact = { 0 }; @@ -536,8 +555,10 @@ bool installCrashHandler(const char * exe) #else //ENABLE_BACKTRACE -bool installCrashHandler(const char * exe) +bool installCrashHandler(const char * exe, char * argv0) { + (void)exe; + (void)argv0; return true; } diff --git a/common/src/platform/windows/crash.c b/common/src/platform/windows/crash.c index ec1b8345..c769be58 100644 --- a/common/src/platform/windows/crash.c +++ b/common/src/platform/windows/crash.c @@ -148,8 +148,10 @@ fail: return EXCEPTION_CONTINUE_SEARCH; } -bool installCrashHandler(const char * exe) +bool installCrashHandler(const char * exe, char * argv0) { + (void)exe; + (void)argv0; SetUnhandledExceptionFilter(exception_filter); return true; } @@ -159,8 +161,10 @@ void printAllThreadBacktraces(void) } #else -bool installCrashHandler(const char * exe) +bool installCrashHandler(const char * exe, char * argv0) { + (void)exe; + (void)argv0; return true; } diff --git a/host/src/app.c b/host/src/app.c index 2810b577..8f70094d 100644 --- a/host/src/app.c +++ b/host/src/app.c @@ -886,7 +886,7 @@ fail_init: // this is called from the platform specific startup routine int app_main(int argc, char * argv[]) { - if (!installCrashHandler(os_getExecutable())) + if (!installCrashHandler(os_getExecutable(), argv[0])) DEBUG_WARN("Failed to install the crash handler"); // make sure rng is actually seeded for LGMP diff --git a/profile/client/src/main.c b/profile/client/src/main.c index 0457a530..3ced64db 100644 --- a/profile/client/src/main.c +++ b/profile/client/src/main.c @@ -212,7 +212,7 @@ int main(int argc, char * argv[]) { DEBUG_INFO("Looking Glass (" BUILD_VERSION ") - Client Profiler"); - if (!installCrashHandler("/proc/self/exe")) + if (!installCrashHandler("/proc/self/exe", argv[0])) DEBUG_WARN("Failed to install the crash handler"); option_register(options);