Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Unified Diff: src/IceCompileServer.cpp

Issue 1382653002: Fix pnacl-sz to return with staus 0 in report_fatal_error. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceCompileServer.cpp
diff --git a/src/IceCompileServer.cpp b/src/IceCompileServer.cpp
index db0694b9556653f230c8af08b6271dd2baff9f69..f0ae43a2273eda525e6806721b316082018c5afe 100644
--- a/src/IceCompileServer.cpp
+++ b/src/IceCompileServer.cpp
@@ -93,6 +93,30 @@ ErrorCodes getReturnValue(const Ice::ClFlagsExtra &Flags, ErrorCodes Val) {
return Val;
}
+// Reports fatal error message, and then exits with success status 0.
+void reportFatalErrorThenExitSuccess(void *UserData,
+ const std::string &Reason,
+ bool gen_crash_diag) {
Jim Stichnoth 2015/09/30 21:32:13 Should probably be GenCrashDiag or something. But
Karl 2015/09/30 22:02:21 Marking UserData and gen_crash_dag as unused. Surp
+ // Note: This code is (mostly) copied from llvm/lib/Support/ErrorHandling.cpp
+
+ // Blast the result out to stderr. We don't try hard to make sure this
+ // succeeds (e.g. handling EINTR) and we can't use errs() here because
+ // raw ostreams can call report_fatal_error.
+ llvm::SmallVector<char, 64> Buffer;
+ llvm::raw_svector_ostream OS(Buffer);
+ OS << "LLVM ERROR: " << Reason << "\n";
+ llvm::StringRef MessageStr = OS.str();
+ ssize_t written = ::write(2, MessageStr.data(), MessageStr.size());
+ (void)written; // If something went wrong, we deliberately just give up.
+
+ // If we reached here, we are failing ungracefully. Run the interrupt handlers
+ // to make sure any special cleanups get done, in particular that we remove
+ // files registered with RemoveFileOnSignal.
+ llvm::sys::RunInterruptHandlers();
+
+ exit(0);
+}
+
} // end of anonymous namespace
void CLCompileServer::run() {
@@ -105,6 +129,10 @@ void CLCompileServer::run() {
ClFlags::getParsedClFlags(Flags);
ClFlags::getParsedClFlagsExtra(ExtraFlags);
+ // Override report_fatal_error if we want to exit with 0 status.
+ if (ExtraFlags.getAlwaysExitSuccess())
+ llvm::install_fatal_error_handler(reportFatalErrorThenExitSuccess, this);
+
std::error_code EC;
std::unique_ptr<Ostream> Ls = makeStream(ExtraFlags.getLogFilename(), EC);
if (EC) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698