mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-28 12:09:53 +00:00
components/crashcatcher C++ it, we need not use old c style for this
This commit is contained in:
parent
dfadcf2a43
commit
fed44b1995
1 changed files with 13 additions and 20 deletions
|
@ -1,18 +1,12 @@
|
||||||
#include <stdio.h>
|
#include <cstdio>
|
||||||
#include <stdlib.h>
|
#include <cstdlib>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
#include <errno.h>
|
#include <cerrno>
|
||||||
#include <limits.h>
|
#include <climits>
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <sys/ptrace.h>
|
|
||||||
|
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
|
|
||||||
|
@ -205,10 +199,10 @@ static void gdb_info(pid_t pid)
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sys_info(void)
|
static void sys_info()
|
||||||
{
|
{
|
||||||
#ifdef __unix__
|
#ifdef __unix__
|
||||||
struct utsname info;
|
struct utsname info{};
|
||||||
if(uname(&info))
|
if(uname(&info))
|
||||||
printf("!!! Failed to get system information\n");
|
printf("!!! Failed to get system information\n");
|
||||||
else
|
else
|
||||||
|
@ -236,9 +230,8 @@ static size_t safe_write(int fd, const void *buf, size_t len)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void crash_catcher(int signum, siginfo_t *siginfo, void *context)
|
static void crash_catcher(int signum, siginfo_t *siginfo, [[maybe_unused]] void *context)
|
||||||
{
|
{
|
||||||
//ucontext_t *ucontext = (ucontext_t*)context;
|
|
||||||
pid_t dbg_pid;
|
pid_t dbg_pid;
|
||||||
int fd[2];
|
int fd[2];
|
||||||
|
|
||||||
|
@ -259,7 +252,7 @@ static void crash_catcher(int signum, siginfo_t *siginfo, void *context)
|
||||||
|
|
||||||
crash_info.signum = signum;
|
crash_info.signum = signum;
|
||||||
crash_info.pid = getpid();
|
crash_info.pid = getpid();
|
||||||
crash_info.has_siginfo = !!siginfo;
|
crash_info.has_siginfo = siginfo != nullptr;
|
||||||
if(siginfo)
|
if(siginfo)
|
||||||
crash_info.siginfo = *siginfo;
|
crash_info.siginfo = *siginfo;
|
||||||
if(cc_user_info)
|
if(cc_user_info)
|
||||||
|
@ -302,7 +295,7 @@ static void crash_catcher(int signum, siginfo_t *siginfo, void *context)
|
||||||
raise(signum);
|
raise(signum);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while(1);
|
} while(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,7 +444,7 @@ static void getExecPath(char **argv)
|
||||||
|
|
||||||
if(argv[0][0] == '/')
|
if(argv[0][0] == '/')
|
||||||
snprintf(argv0, sizeof(argv0), "%s", argv[0]);
|
snprintf(argv0, sizeof(argv0), "%s", argv[0]);
|
||||||
else if (getcwd(argv0, sizeof(argv0)) != NULL)
|
else if (getcwd(argv0, sizeof(argv0)) != nullptr)
|
||||||
{
|
{
|
||||||
cwdlen = strlen(argv0);
|
cwdlen = strlen(argv0);
|
||||||
snprintf(argv0+cwdlen, sizeof(argv0)-cwdlen, "/%s", argv[0]);
|
snprintf(argv0+cwdlen, sizeof(argv0)-cwdlen, "/%s", argv[0]);
|
||||||
|
@ -460,7 +453,7 @@ static void getExecPath(char **argv)
|
||||||
|
|
||||||
int crashCatcherInstallHandlers(int argc, char **argv, int num_signals, int *signals, const char *logfile, int (*user_info)(char*, char*))
|
int crashCatcherInstallHandlers(int argc, char **argv, int num_signals, int *signals, const char *logfile, int (*user_info)(char*, char*))
|
||||||
{
|
{
|
||||||
struct sigaction sa;
|
struct sigaction sa{};
|
||||||
stack_t altss;
|
stack_t altss;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
|
@ -562,7 +555,7 @@ static bool is_debugger_present()
|
||||||
void crashCatcherInstall(int argc, char **argv, const std::string &crashLogPath)
|
void crashCatcherInstall(int argc, char **argv, const std::string &crashLogPath)
|
||||||
{
|
{
|
||||||
if (const auto env = std::getenv("OPENMW_DISABLE_CRASH_CATCHER"))
|
if (const auto env = std::getenv("OPENMW_DISABLE_CRASH_CATCHER"))
|
||||||
if (std::atol(env) != 0)
|
if (std::strtol(env, nullptr, 10) != 0)
|
||||||
return;
|
return;
|
||||||
if ((argc == 2 && strcmp(argv[1], crash_switch) == 0) || !is_debugger_present())
|
if ((argc == 2 && strcmp(argv[1], crash_switch) == 0) || !is_debugger_present())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue