chore: cleanup debuglog file logic

main
Sean McBride 4 years ago
parent 0707f44989
commit 4b107f3033

@ -4,6 +4,12 @@
extern int32_t debuglog_file_descriptor; 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 * debuglog is a macro that behaves based on the macros DEBUG and LOG_TO_FILE
* If DEBUG is not set, debuglog does nothing * If DEBUG is not set, debuglog does nothing

@ -135,16 +135,15 @@ void
runtime_process_debug_log_behavior() runtime_process_debug_log_behavior()
{ {
#ifdef LOG_TO_FILE #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); debuglog_file_descriptor = open(RUNTIME_LOG_FILE, O_CREAT | O_TRUNC | O_WRONLY, S_IRWXU | S_IRWXG);
if (debuglog_file_descriptor < 0) { if (debuglog_file_descriptor < 0) {
perror("open"); perror("Error opening logfile\n");
exit(-1); exit(-1);
} }
dup2(debuglog_file_descriptor, STDOUT_FILENO);
dup2(debuglog_file_descriptor, STDERR_FILENO);
#else #else
debuglog_file_descriptor = 1; debuglog_file_descriptor = STDOUT_FILENO;
#endif /* LOG_TO_FILE */ #endif /* LOG_TO_FILE */
} }
#endif /* DEBUG */ #endif /* DEBUG */

Loading…
Cancel
Save