mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-08-02 05:12:02 +00:00
[common] debug: set the crash handler process name
This commit is contained in:
@@ -2064,7 +2064,7 @@ int main(int argc, char * argv[])
|
|||||||
DEBUG_INFO("Locking Method: " LG_LOCK_MODE);
|
DEBUG_INFO("Locking Method: " LG_LOCK_MODE);
|
||||||
cpuInfo_log();
|
cpuInfo_log();
|
||||||
|
|
||||||
if (!installCrashHandler("/proc/self/exe"))
|
if (!installCrashHandler("/proc/self/exe", argv[0]))
|
||||||
DEBUG_WARN("Failed to install the crash handler");
|
DEBUG_WARN("Failed to install the crash handler");
|
||||||
|
|
||||||
lgPathsInit("looking-glass");
|
lgPathsInit("looking-glass");
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
bool installCrashHandler(const char * exe);
|
bool installCrashHandler(const char * exe, char * argv0);
|
||||||
void cleanupCrashHandler(void);
|
void cleanupCrashHandler(void);
|
||||||
void printAllThreadBacktraces(void);
|
void printAllThreadBacktraces(void);
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#define CRASH_MAX_FRAMES 64
|
#define CRASH_MAX_FRAMES 64
|
||||||
|
#define CRASH_REPORTER_NAME "lg_crash_handler"
|
||||||
|
|
||||||
enum CrashRequestType
|
enum CrashRequestType
|
||||||
{
|
{
|
||||||
@@ -305,8 +306,26 @@ raw:
|
|||||||
DEBUG_ERROR("[trace]: (%u) 0x%" PRIxPTR, i, request->frames[i]);
|
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
|
// Do not leave an orphaned reporter if the client exits unexpectedly before
|
||||||
// it closes the request pipe.
|
// it closes the request pipe.
|
||||||
prctl(PR_SET_PDEATHSIG, SIGKILL);
|
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 requestPipe[2];
|
||||||
int responsePipe[2];
|
int responsePipe[2];
|
||||||
@@ -368,7 +387,7 @@ static bool startReporter(void)
|
|||||||
{
|
{
|
||||||
close(requestPipe [1]);
|
close(requestPipe [1]);
|
||||||
close(responsePipe[0]);
|
close(responsePipe[0]);
|
||||||
reporterLoop(parent, requestPipe[0], responsePipe[1]);
|
reporterLoop(parent, requestPipe[0], responsePipe[1], argv0);
|
||||||
close(requestPipe [0]);
|
close(requestPipe [0]);
|
||||||
close(responsePipe[1]);
|
close(responsePipe[1]);
|
||||||
_exit(0);
|
_exit(0);
|
||||||
@@ -511,11 +530,11 @@ static void crit_err_hdlr(int sig_num, siginfo_t * info, void * ucontext)
|
|||||||
_exit(128 + sig_num);
|
_exit(128 + sig_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool installCrashHandler(const char * exe)
|
bool installCrashHandler(const char * exe, char * argv0)
|
||||||
{
|
{
|
||||||
(void)exe;
|
(void)exe;
|
||||||
|
|
||||||
if (!startReporter())
|
if (!startReporter(argv0))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
struct sigaction sigact = { 0 };
|
struct sigaction sigact = { 0 };
|
||||||
@@ -536,8 +555,10 @@ bool installCrashHandler(const char * exe)
|
|||||||
|
|
||||||
#else //ENABLE_BACKTRACE
|
#else //ENABLE_BACKTRACE
|
||||||
|
|
||||||
bool installCrashHandler(const char * exe)
|
bool installCrashHandler(const char * exe, char * argv0)
|
||||||
{
|
{
|
||||||
|
(void)exe;
|
||||||
|
(void)argv0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -148,8 +148,10 @@ fail:
|
|||||||
return EXCEPTION_CONTINUE_SEARCH;
|
return EXCEPTION_CONTINUE_SEARCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool installCrashHandler(const char * exe)
|
bool installCrashHandler(const char * exe, char * argv0)
|
||||||
{
|
{
|
||||||
|
(void)exe;
|
||||||
|
(void)argv0;
|
||||||
SetUnhandledExceptionFilter(exception_filter);
|
SetUnhandledExceptionFilter(exception_filter);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -159,8 +161,10 @@ void printAllThreadBacktraces(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
bool installCrashHandler(const char * exe)
|
bool installCrashHandler(const char * exe, char * argv0)
|
||||||
{
|
{
|
||||||
|
(void)exe;
|
||||||
|
(void)argv0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -886,7 +886,7 @@ fail_init:
|
|||||||
// this is called from the platform specific startup routine
|
// this is called from the platform specific startup routine
|
||||||
int app_main(int argc, char * argv[])
|
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");
|
DEBUG_WARN("Failed to install the crash handler");
|
||||||
|
|
||||||
// make sure rng is actually seeded for LGMP
|
// make sure rng is actually seeded for LGMP
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ int main(int argc, char * argv[])
|
|||||||
{
|
{
|
||||||
DEBUG_INFO("Looking Glass (" BUILD_VERSION ") - Client Profiler");
|
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");
|
DEBUG_WARN("Failed to install the crash handler");
|
||||||
|
|
||||||
option_register(options);
|
option_register(options);
|
||||||
|
|||||||
Reference in New Issue
Block a user