mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-12-13 22:31:03 +00:00
Replace macros with static functions, rename size int to bt_size.
This commit is contained in:
parent
50a34d85dd
commit
c5e69fcf94
1 changed files with 31 additions and 32 deletions
|
@ -259,28 +259,29 @@ UINT8 keyboard_started = false;
|
||||||
|
|
||||||
#ifdef UNIXBACKTRACE
|
#ifdef UNIXBACKTRACE
|
||||||
|
|
||||||
// NOTE: if written ends up ever being -1, all further writes end up being cancelled.
|
static void bt_write_file(int fd, const char *string) {
|
||||||
// i figure an error is a reason to stop writing...
|
ssize_t written = 0;
|
||||||
#define WRITE_FILE(string) \
|
ssize_t sourcelen = strlen(string);
|
||||||
sourcelen = strlen(string); \
|
|
||||||
while (fd != -1 && (written != -1 && errno != EINTR) && written < sourcelen) \
|
while (fd != -1 && (written != -1 && errno != EINTR) && written < sourcelen)
|
||||||
written = write(fd, string, sourcelen);
|
written = write(fd, string, sourcelen);
|
||||||
|
}
|
||||||
|
|
||||||
#define WRITE_STDERR(string) \
|
static void bt_write_stderr(const char *string) {
|
||||||
I_OutputMsg("%s", string);
|
bt_write_file(STDERR_FILENO, string);
|
||||||
|
}
|
||||||
|
|
||||||
#define WRITE_ALL(string) \
|
static void bt_write_all(int fd, const char *string) {
|
||||||
WRITE_FILE(string); \
|
bt_write_file(fd, string);
|
||||||
WRITE_STDERR(string);
|
bt_write_file(STDERR_FILENO, string);
|
||||||
|
}
|
||||||
|
|
||||||
static void write_backtrace(INT32 signal)
|
static void write_backtrace(INT32 signal)
|
||||||
{
|
{
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
ssize_t written = 0;
|
|
||||||
ssize_t sourcelen = 0;
|
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
size_t size;
|
size_t bt_size;
|
||||||
|
|
||||||
enum { BT_SIZE = 1024, STR_SIZE = 32 };
|
enum { BT_SIZE = 1024, STR_SIZE = 32 };
|
||||||
void *funcptrs[BT_SIZE];
|
void *funcptrs[BT_SIZE];
|
||||||
|
@ -291,49 +292,47 @@ static void write_backtrace(INT32 signal)
|
||||||
fd = open(filename, O_CREAT|O_APPEND|O_RDWR, S_IRUSR|S_IWUSR);
|
fd = open(filename, O_CREAT|O_APPEND|O_RDWR, S_IRUSR|S_IWUSR);
|
||||||
|
|
||||||
if (fd == -1) // File handle error
|
if (fd == -1) // File handle error
|
||||||
WRITE_STDERR("\nWARNING: Couldn't open crash log for writing! Make sure your permissions are correct. Please save the below report!\n");
|
bt_write_stderr("\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.
|
// Get the current time as a string.
|
||||||
time(&rawtime);
|
time(&rawtime);
|
||||||
localtime_r(&rawtime, &timeinfo);
|
localtime_r(&rawtime, &timeinfo);
|
||||||
strftime(timestr, STR_SIZE, "%a, %d %b %Y %T %z", &timeinfo);
|
strftime(timestr, STR_SIZE, "%a, %d %b %Y %T %z", &timeinfo);
|
||||||
|
|
||||||
WRITE_FILE("------------------------\n"); // Nice looking seperator
|
bt_write_file(fd, "------------------------\n"); // Nice looking seperator
|
||||||
|
|
||||||
WRITE_ALL("\n"); // Newline to look nice for both outputs.
|
bt_write_all(fd, "\n"); // Newline to look nice for both outputs.
|
||||||
WRITE_ALL("An error occurred within SRB2! Send this stack trace to someone who can help!\n");
|
bt_write_all(fd, "An error occurred within SRB2! Send this stack trace to someone who can help!\n");
|
||||||
|
|
||||||
if (fd != -1) // If the crash log exists,
|
if (fd != -1) // If the crash log exists,
|
||||||
WRITE_STDERR("(Or find crash-log.txt in your SRB2 directory.)\n"); // tell the user where the crash log is.
|
bt_write_stderr("(Or find crash-log.txt in your SRB2 directory.)\n"); // tell the user where the crash log is.
|
||||||
|
|
||||||
// Tell the log when we crashed.
|
// Tell the log when we crashed.
|
||||||
WRITE_FILE("Time of crash: ");
|
bt_write_file(fd, "Time of crash: ");
|
||||||
WRITE_FILE(timestr);
|
bt_write_file(fd, timestr);
|
||||||
WRITE_FILE("\n");
|
bt_write_file(fd, "\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.
|
||||||
WRITE_FILE("Cause: ");
|
bt_write_file(fd, "Cause: ");
|
||||||
WRITE_FILE(strsignal(signal));
|
bt_write_file(fd, strsignal(signal));
|
||||||
WRITE_FILE("\n"); // Newline for the signal name
|
bt_write_file(fd, "\n"); // Newline for the signal name
|
||||||
|
|
||||||
WRITE_ALL("\nBacktrace:\n");
|
bt_write_all(fd, "\nBacktrace:\n");
|
||||||
|
|
||||||
// Flood the output and log with the backtrace
|
// Flood the output and log with the backtrace
|
||||||
size = backtrace(funcptrs, BT_SIZE);
|
bt_size = backtrace(funcptrs, BT_SIZE);
|
||||||
backtrace_symbols_fd(funcptrs, size, fd);
|
backtrace_symbols_fd(funcptrs, bt_size, fd);
|
||||||
backtrace_symbols_fd(funcptrs, size, STDERR_FILENO);
|
backtrace_symbols_fd(funcptrs, bt_size, STDERR_FILENO);
|
||||||
|
|
||||||
WRITE_FILE("\n"); // Write another newline to the log so it looks nice :)
|
bt_write_file(fd, "\n"); // Write another newline to the log so it looks nice :)
|
||||||
|
|
||||||
if (fd != -1) {
|
if (fd != -1) {
|
||||||
fsync(fd); // reaaaaally make sure we got that data written.
|
fsync(fd); // reaaaaally make sure we got that data written.
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#undef WRITE_FILE
|
|
||||||
#undef WRITE_STDERR
|
|
||||||
#undef WRITE_ALL
|
|
||||||
#endif // UNIXBACKTRACE
|
#endif // UNIXBACKTRACE
|
||||||
|
|
||||||
static void I_ReportSignal(int num, int coredumped)
|
static void I_ReportSignal(int num, int coredumped)
|
||||||
|
|
Loading…
Reference in a new issue