From 9e28c989118c6ca55b6fd879503676cc472b9a73 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 30 Sep 2024 03:24:39 +0300 Subject: [PATCH] engine: print to stderr if writing message to logfile failed --- engine/common/sys_con.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/engine/common/sys_con.c b/engine/common/sys_con.c index bec6e089..e3c41fd6 100644 --- a/engine/common/sys_con.c +++ b/engine/common/sys_con.c @@ -230,13 +230,20 @@ static void Sys_PrintLogfile( const int fd, const char *logtime, const char *msg if( p == NULL ) { - write( fd, msg, Q_strlen( msg )); + if( write( fd, msg, Q_strlen( msg )) < 0 ) + { + // don't call engine Msg, might cause recursion + fprintf( stderr, "%s: write failed: %s\n", __func__, strerror( errno )); + } break; } else if( IsColorString( p )) { if( p != msg ) - write( fd, msg, p - msg ); + { + if( write( fd, msg, p - msg ) < 0 ) + fprintf( stderr, "%s: write failed: %s\n", __func__, strerror( errno )); + } msg = p + 2; if( colorize ) @@ -244,7 +251,8 @@ static void Sys_PrintLogfile( const int fd, const char *logtime, const char *msg } else { - write( fd, msg, p - msg + 1 ); + if( write( fd, msg, p - msg + 1 ) < 0 ) + fprintf( stderr, "%s: write failed: %s\n", __func__, strerror( errno )); msg = p + 1; } }