Skip to content

Commit 1f6a0e3

Browse files
committed
feat(crashreporter): Abort Listener
1 parent 55cf876 commit 1f6a0e3

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/crashreporter/CrashReport.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ bool BeginCrashListener() { return true; }
1919
#include <sstream>
2020

2121
#include <random>
22+
#include <atomic>
2223

2324
#include "../files/Files.h"
2425
#include "../common.h"
@@ -28,6 +29,8 @@ std::string startup_cmd = "None";
2829

2930
const char *ws = " \t\n\r\f\v";
3031

32+
std::atomic<bool> exitProgram(false);
33+
3134
// trim from end of string (right)
3235
inline std::string &rtrim(std::string &s, const char *t = ws)
3336
{
@@ -161,7 +164,7 @@ void signal_handler(int signumber)
161164
PLUGIN_PRINTF("Crash Reporter", "Error crash handling: %s\n", e.what());
162165
}
163166

164-
exit(EXIT_FAILURE);
167+
exitProgram = true;
165168
}
166169

167170
bool BeginCrashListener()
@@ -176,11 +179,12 @@ bool BeginCrashListener()
176179
}
177180

178181
::signal(SIGSEGV, &signal_handler);
182+
::signal(SIGABRT, &signal_handler);
179183

180184
startup_cmd = CommandLine()->GetCmdLine();
181185
std::vector<std::string> exp = explode(startup_cmd, " ");
182186
std::vector<std::string> exp2;
183-
for (int i = 1; i < exp.size(); i++)
187+
for (std::size_t i = 1; i < exp.size(); i++)
184188
{
185189
std::string str = trim(exp[i]);
186190
if (str.length() == 0)
@@ -196,4 +200,10 @@ bool BeginCrashListener()
196200
return true;
197201
}
198202

203+
void CrashReporterListener()
204+
{
205+
if (exitProgram.load())
206+
exit(EXIT_FAILURE);
207+
}
208+
199209
#endif

src/entrypoint.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,17 @@ GameFrameMsgPackCache gameFrameCache = {
350350
false,
351351
};
352352

353+
void CrashReporterListener();
354+
353355
void Swiftly::Hook_GameFrame(bool simulating, bool bFirstTick, bool bLastTick)
354356
{
355357
PERF_RECORD("GameFrame", "core")
356358
static double g_flNextUpdate = 0.0;
357359

360+
//////////////////////////////////////////////////////////////
361+
///////////////// Server List //////////////
362+
////////////////////////////////////////////////////////////
363+
358364
double curtime = Plat_FloatTime();
359365
if (curtime > g_flNextUpdate)
360366
{
@@ -364,6 +370,12 @@ void Swiftly::Hook_GameFrame(bool simulating, bool bFirstTick, bool bLastTick)
364370
g_flNextUpdate = curtime + 5.0;
365371
}
366372

373+
//////////////////////////////////////////////////////////////
374+
///////////////// Crash Reporter //////////////
375+
////////////////////////////////////////////////////////////
376+
377+
CrashReporterListener();
378+
367379
//////////////////////////////////////////////////////////////
368380
///////////////// Game Event //////////////
369381
////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)