From b00679ee301547f24194eda0bffed1f48919acfc Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 24 Apr 2026 20:35:13 +0500 Subject: [PATCH] engine: make Sys_LogFileNo return -1 when log file isn't opened --- engine/common/sys_con.c | 2 ++ engine/platform/posix/crash_libbacktrace.c | 7 +++++-- engine/platform/posix/crash_posix.c | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/engine/common/sys_con.c b/engine/common/sys_con.c index 8a261dc4..2d6bb612 100644 --- a/engine/common/sys_con.c +++ b/engine/common/sys_con.c @@ -61,6 +61,8 @@ SYSTEM LOG */ int Sys_LogFileNo( void ) { + if( !s_ld.logfile ) + return -1; return s_ld.logfileno; } diff --git a/engine/platform/posix/crash_libbacktrace.c b/engine/platform/posix/crash_libbacktrace.c index 223ca4f2..84d51d08 100644 --- a/engine/platform/posix/crash_libbacktrace.c +++ b/engine/platform/posix/crash_libbacktrace.c @@ -55,8 +55,11 @@ static void Sys_AppendPrint( struct print_data *pd, const char *fmt, ... ) { char ch = '\n'; - write( pd->logfd, pd->message, len ); - write( pd->logfd, &ch, 1 ); + if( pd->logfd >= 0 ) + { + write( pd->logfd, pd->message, len ); + write( pd->logfd, &ch, 1 ); + } write( STDERR_FILENO, pd->message, len ); write( STDERR_FILENO, &ch, 1 ); diff --git a/engine/platform/posix/crash_posix.c b/engine/platform/posix/crash_posix.c index d9cc6f3c..2e7ae0a8 100644 --- a/engine/platform/posix/crash_posix.c +++ b/engine/platform/posix/crash_posix.c @@ -44,7 +44,8 @@ static void Sys_Crash( int signal, siginfo_t *si, void *context ) // now get log fd and write trace directly to log logfd = Sys_LogFileNo(); - write( logfd, message, len ); + if( logfd >= 0 ) + write( logfd, message, len ); #if HAVE_LIBBACKTRACE if( have_libbacktrace && !detailed_message )