]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Handle failure to write to stderr when failing to write to log file
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 27 Aug 2022 19:56:03 +0000 (21:56 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 27 Aug 2022 20:03:46 +0000 (22:03 +0200)
This can happen with

    CCACHE_LOGFILE=/dev/stdout ccache compiler ... |& head -n 1

or similar.

src/Logging.cpp

index 46b62f5542ed769e5ebfa0ca7be8cbe465a480f6..82e4b1c237308fff44f22b64ed58fad01ecf00c1 100644 (file)
@@ -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);
 }