summaryrefslogtreecommitdiff
path: root/src/vm/exceptionhandling.cpp
diff options
context:
space:
mode:
authorTom Deseyn <tom.deseyn@gmail.com>2019-01-15 21:43:08 +0100
committerJan Kotas <jkotas@microsoft.com>2019-01-15 12:43:08 -0800
commit3f0903598d0e269e6aaf8e237b47269abe4ab7e8 (patch)
treeaff29f9a428caf4b1591987dff07fd146d15909b /src/vm/exceptionhandling.cpp
parent86b4ac59ef9d19e8f635086ea6a20a291c1dd26a (diff)
downloadcoreclr-3f0903598d0e269e6aaf8e237b47269abe4ab7e8.tar.gz
coreclr-3f0903598d0e269e6aaf8e237b47269abe4ab7e8.tar.bz2
coreclr-3f0903598d0e269e6aaf8e237b47269abe4ab7e8.zip
On SIGTERM default to a non-zero exit code (#21300)
* On SIGTERM default to a non-zero exit code * Fix Windows builds * Improve SIG_DFL/SIG_IGN handling * Remove PAL_GetTerminationExitCode * Use sa_handler/sa_sigaction based on SA_SIGINFO; remove HAVE_SIGINFO_T. * configure.cmake: remove siginfo_t check * Move restore_signal_and_resend so OSX can use it; add function documentation * Fix OSX build: include pal/process.h for gPID * Check SIG_IGN and SIG_DFL against sa_handler * Don't use sa_handler when SA_SIGINFO is set * Fix equality check * Swap order of checking SA_SIGINFO and SIG_IGN/SIG_DFL
Diffstat (limited to 'src/vm/exceptionhandling.cpp')
-rw-r--r--src/vm/exceptionhandling.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/vm/exceptionhandling.cpp b/src/vm/exceptionhandling.cpp
index 869084cff9..8e6da16e8b 100644
--- a/src/vm/exceptionhandling.cpp
+++ b/src/vm/exceptionhandling.cpp
@@ -16,6 +16,7 @@
#include "perfcounters.h"
#include "eventtrace.h"
#include "virtualcallstub.h"
+#include "utilcode.h"
#if defined(_TARGET_X86_)
#define USE_CURRENT_CONTEXT_IN_FILTER
@@ -203,10 +204,23 @@ static inline void UpdatePerformanceMetrics(CrawlFrame *pcfThisFrame, BOOL bIsRe
ETW::ExceptionLog::ExceptionThrown(pcfThisFrame, bIsRethrownException, bIsNewException);
}
-void ShutdownEEAndExitProcess()
+#ifdef FEATURE_PAL
+static LONG volatile g_termination_triggered = 0;
+
+void HandleTerminationRequest(int terminationExitCode)
{
- ForceEEShutdown(SCA_ExitProcessWhenShutdownComplete);
+ // We set a non-zero exit code to indicate the process didn't terminate cleanly.
+ // This value can be changed by the user by setting Environment.ExitCode in the
+ // ProcessExit event. We only start termination on the first SIGTERM signal
+ // to ensure we don't overwrite an exit code already set in ProcessExit.
+ if (InterlockedCompareExchange(&g_termination_triggered, 1, 0) == 0)
+ {
+ SetLatchedExitCode(terminationExitCode);
+
+ ForceEEShutdown(SCA_ExitProcessWhenShutdownComplete);
+ }
}
+#endif
void InitializeExceptionHandling()
{
@@ -229,7 +243,7 @@ void InitializeExceptionHandling()
PAL_SetGetGcMarkerExceptionCode(GetGcMarkerExceptionCode);
// Register handler for termination requests (e.g. SIGTERM)
- PAL_SetTerminationRequestHandler(ShutdownEEAndExitProcess);
+ PAL_SetTerminationRequestHandler(HandleTerminationRequest);
#endif // FEATURE_PAL
}