Make it more async-signal-safe
This commit is contained in:
parent
bdb28a06f4
commit
a0396d5e43
|
@ -256,10 +256,11 @@ static void write_backtrace(INT32 signal)
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
size_t size;
|
size_t size;
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm * timeinfo;
|
struct tm timeinfo;
|
||||||
|
|
||||||
enum { MAX_SIZE = 1024 };
|
enum { BT_SIZE = 1024, STR_SIZE = 32 };
|
||||||
void *array[MAX_SIZE];
|
void *array[BT_SIZE];
|
||||||
|
char timestr[STR_SIZE];
|
||||||
|
|
||||||
const char *error = "An error occurred within SRB2! Send this stack trace to someone who can help!\n";
|
const char *error = "An error occurred within SRB2! Send this stack trace to someone who can help!\n";
|
||||||
const char *error2 = "(Or find crash-log.txt in your SRB2 directory.)\n"; // Shown only to stderr.
|
const char *error2 = "(Or find crash-log.txt in your SRB2 directory.)\n"; // Shown only to stderr.
|
||||||
|
@ -269,8 +270,10 @@ static void write_backtrace(INT32 signal)
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
I_OutputMsg("\nWARNING: Couldn't open crash log for writing! Make sure your permissions are correct. Please save the below report!\n");
|
I_OutputMsg("\nWARNING: Couldn't open crash log for writing! Make sure your permissions are correct. Please save the below report!\n");
|
||||||
|
|
||||||
|
// Get the current time as a string.
|
||||||
time(&rawtime);
|
time(&rawtime);
|
||||||
timeinfo = localtime(&rawtime);
|
localtime_r(&rawtime, &timeinfo);
|
||||||
|
strftime(timestr, STR_SIZE, "%a, %d %b %Y %T %z", &timeinfo);
|
||||||
|
|
||||||
CRASHLOG_WRITE("------------------------\n"); // Nice looking seperator
|
CRASHLOG_WRITE("------------------------\n"); // Nice looking seperator
|
||||||
|
|
||||||
|
@ -280,7 +283,8 @@ static void write_backtrace(INT32 signal)
|
||||||
|
|
||||||
// Tell the log when we crashed.
|
// Tell the log when we crashed.
|
||||||
CRASHLOG_WRITE("Time of crash: ");
|
CRASHLOG_WRITE("Time of crash: ");
|
||||||
CRASHLOG_WRITE(asctime(timeinfo));
|
CRASHLOG_WRITE(timestr);
|
||||||
|
CRASHLOG_WRITE("\n");
|
||||||
|
|
||||||
// Give the crash log the cause and a nice 'Backtrace:' thing
|
// Give the crash log the cause and a nice 'Backtrace:' thing
|
||||||
// The signal is given to the user when the parent process sees we crashed.
|
// The signal is given to the user when the parent process sees we crashed.
|
||||||
|
@ -291,7 +295,7 @@ static void write_backtrace(INT32 signal)
|
||||||
CRASHLOG_STDERR_WRITE("\nBacktrace:\n");
|
CRASHLOG_STDERR_WRITE("\nBacktrace:\n");
|
||||||
|
|
||||||
// Flood the output and log with the backtrace
|
// Flood the output and log with the backtrace
|
||||||
size = backtrace(array, MAX_SIZE);
|
size = backtrace(array, BT_SIZE);
|
||||||
backtrace_symbols_fd(array, size, fd);
|
backtrace_symbols_fd(array, size, fd);
|
||||||
backtrace_symbols_fd(array, size, STDERR_FILENO);
|
backtrace_symbols_fd(array, size, STDERR_FILENO);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue