From 11432b8c9c406a2084c1f1eec15703904251fd1e Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sat, 27 Aug 2022 21:56:03 +0200 Subject: [PATCH] fix: Handle failure to write to stderr when failing to write to log file This can happen with CCACHE_LOGFILE=/dev/stdout ccache compiler ... |& head -n 1 or similar. --- src/Logging.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Logging.cpp b/src/Logging.cpp index 46b62f554..82e4b1c23 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -66,10 +66,14 @@ bool debug_log_enabled = false; print_fatal_error_and_exit() { // Note: Can't throw Fatal since that would lead to recursion. - PRINT(stderr, - "ccache: error: Failed to write to {}: {}\n", - logfile_path, - strerror(errno)); + try { + PRINT(stderr, + "ccache: error: Failed to write to {}: {}\n", + logfile_path, + strerror(errno)); + } catch (std::runtime_error&) { + // Ignore since we can't do anything about it. + } exit(EXIT_FAILURE); } -- 2.47.2