If the native upcall comes after starting coreclr shutdown steps, SIGABRT is raised...
[platform/core/dotnet/launcher.git] / NativeLauncher / launcher / dotnet / dotnet_launcher.cc
index 9757464..7cd16b9 100644 (file)
@@ -121,36 +121,46 @@ static void setEnvFromFile()
        }
 }
 
+#define _unused(x) ((void)(x))
+
 struct sigaction sig_abrt_new;
 struct sigaction sig_abrt_old;
 
 static bool checkOnSigabrt = false;
+static bool checkOnTerminate = false;
+
 static void onSigabrt(int signum)
 {
-       // ignore return value of write().
-       // this function is called when process go to die
-       // there is no need to handle return value for logging.
-       write(2, "onSigabrt called\n", 17);
+       // use unused variable to avoid build warning
+       ssize_t ret = write(STDERR_FILENO, "onSigabrt called\n", 17);
+
+       if (checkOnTerminate) {
+               ret = write(STDERR_FILENO, "onSigabrt called while terminate. go to exit\n", 45);
+               _unused(ret);
+               exit(0);
+       }
 
        if (checkOnSigabrt) {
-               write(2, "onSigabrt called again. go to exit\n", 35);
+               ret = write(STDERR_FILENO, "onSigabrt called again. go to exit\n", 35);
+               _unused(ret);
                exit(0);
        }
 
        if (hasException()) {
-               write(2, "******************************************************\n", 55);
-               write(2, "Unhandled exception is occured. check application code\n", 55);
-               write(2, "******************************************************\n", 55);
+               ret = write(STDERR_FILENO, "******************************************************\n", 55);
+               ret = write(STDERR_FILENO, "Unhandled exception is occured. check application code\n", 55);
+               ret = write(STDERR_FILENO, "******************************************************\n", 55);
        }
 
        checkOnSigabrt = true;
        if (sigaction(SIGABRT, &sig_abrt_old, NULL) == 0) {
                if (raise(signum) < 0) {
-                       write(2, "Fail to raise SIGABRT\n", 22);
+                       ret = write(STDERR_FILENO, "Fail to raise SIGABRT\n", 22);
                }
        } else {
-               write(2, "Fail to set original SIGABRT handler\n", 37);
+               ret = write(STDERR_FILENO, "Fail to set original SIGABRT handler\n", 37);
        }
+       _unused(ret);
 }
 
 static void registerSigHandler()
@@ -400,6 +410,12 @@ bool CoreRuntime::initializeCoreClr(const char* appId,
 
 void CoreRuntime::dispose()
 {
+       // call finalize plugin callback before shutdown coreclr
+       finalizePluginManager();
+
+       // ignore the signal generated by an exception that occurred during shutdown
+       checkOnTerminate = true;
+
        if (__hostHandle != nullptr) {
                int st = shutdown(__hostHandle, __domainId);
                if (st < 0)
@@ -415,7 +431,6 @@ void CoreRuntime::dispose()
                __coreclrLib = nullptr;
        }
 
-       finalizePluginManager();
        finalizePathManager();
 
        __envList.clear();