From 0e32fd36c89383366f5ad3e340a3f4af62672f54 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Wed, 13 Jul 2022 23:05:59 -0400 Subject: [PATCH] Store Temporary Logs In Own Directory --- launcher/src/crash-report.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/launcher/src/crash-report.c b/launcher/src/crash-report.c index 8d609b8..88bf4b2 100644 --- a/launcher/src/crash-report.c +++ b/launcher/src/crash-report.c @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -44,6 +45,7 @@ static void exit_handler(__attribute__((unused)) int signal) { // Setup #define PIPE_READ 0 #define PIPE_WRITE 1 +#define MCPI_LOGS_DIR "/tmp/.minecraft-pi-logs" void setup_crash_report() { // Store Output int output_pipe[2]; @@ -100,8 +102,21 @@ void setup_crash_report() { #define BUFFER_SIZE 1024 char buf[BUFFER_SIZE]; + // Ensure Temporary Directory + { + // Check If It Exists + struct stat tmp_stat; + int exists = stat(MCPI_LOGS_DIR, &tmp_stat) != 0 ? 0 : S_ISDIR(tmp_stat.st_mode); + if (!exists) { + // Doesn't Exist + if (mkdir(MCPI_LOGS_DIR, S_IRUSR | S_IWUSR | S_IXUSR) != 0) { + ERR("Unable To Create Temporary Folder: %s", strerror(errno)); + } + } + } + // Create Temporary File - char log_filename[] = "/tmp/.minecraft-pi-log-XXXXXX"; + char log_filename[] = MCPI_LOGS_DIR "/XXXXXX"; int log_file_fd = mkstemp(log_filename); if (log_file_fd == -1) { ERR("Unable To Create Log File: %s", strerror(errno));