From 4b107f3033821ae1ab6f7c8c822587173faa9c72 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Sat, 1 Aug 2020 09:31:01 -0400 Subject: [PATCH] chore: cleanup debuglog file logic --- runtime/include/debuglog.h | 6 ++++++ runtime/src/main.c | 9 ++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/runtime/include/debuglog.h b/runtime/include/debuglog.h index 572816e..b557c8a 100644 --- a/runtime/include/debuglog.h +++ b/runtime/include/debuglog.h @@ -4,6 +4,12 @@ extern int32_t debuglog_file_descriptor; +#ifdef LOG_TO_FILE +#ifndef DEBUG +#error LOG_TO_FILE is only valid if in DEBUG mode +#endif /* DEBUG */ +#endif /* LOG_TO_FILE */ + /** * debuglog is a macro that behaves based on the macros DEBUG and LOG_TO_FILE * If DEBUG is not set, debuglog does nothing diff --git a/runtime/src/main.c b/runtime/src/main.c index acb5145..79d4dcc 100644 --- a/runtime/src/main.c +++ b/runtime/src/main.c @@ -135,16 +135,15 @@ void runtime_process_debug_log_behavior() { #ifdef LOG_TO_FILE - fclose(stdout); - fclose(stderr); - fclose(stdin); debuglog_file_descriptor = open(RUNTIME_LOG_FILE, O_CREAT | O_TRUNC | O_WRONLY, S_IRWXU | S_IRWXG); if (debuglog_file_descriptor < 0) { - perror("open"); + perror("Error opening logfile\n"); exit(-1); } + dup2(debuglog_file_descriptor, STDOUT_FILENO); + dup2(debuglog_file_descriptor, STDERR_FILENO); #else - debuglog_file_descriptor = 1; + debuglog_file_descriptor = STDOUT_FILENO; #endif /* LOG_TO_FILE */ } #endif /* DEBUG */