donot create coredump file for unhandled exception 11/185211/1 accepted/tizen/unified/20180802.134837 submit/tizen/20180727.050745
authorWoongsuk Cho <ws77.cho@samsung.com>
Fri, 27 Jul 2018 04:34:18 +0000 (13:34 +0900)
committerWoongsuk Cho <ws77.cho@samsung.com>
Fri, 27 Jul 2018 04:34:18 +0000 (13:34 +0900)
Change-Id: I6cf6f566357250d7161effb34bbbd26d473791af

NativeLauncher/inc/log_manager.h
NativeLauncher/launcher/dotnet/dotnet_launcher.cc
NativeLauncher/util/log_manager.cc

index bf60651..32414fd 100644 (file)
@@ -20,5 +20,6 @@
 int initializeLogManager();
 int redirectFD();
 int runLoggingThread();
+int hasException();
 
 #endif /* __LOG_MANAGER_H__ */
index 884a5a2..18a5c3e 100644 (file)
@@ -16,6 +16,7 @@
 
 
 #include <dlfcn.h>
+#include <signal.h>
 
 #include <string>
 #include <fstream>
@@ -116,6 +117,47 @@ static void setEnvFromFile()
        }
 }
 
+struct sigaction sig_abrt_new;
+struct sigaction sig_abrt_old;
+
+static bool checkOnSigabrt = false;
+static void onSigabrt(int signum)
+{
+    fprintf(stderr, "onSigabrt is called!!!\n");
+
+    if (checkOnSigabrt) {
+        fprintf(stderr, "SIGABRT is already handled. Go to exit\n");
+        exit(0);
+    }
+
+    if (hasException()) {
+        fprintf(stderr, "Unhandled exception is occured. Ignore coredump creation and terminate normally\n");
+        exit(0);
+    } else {
+        fprintf(stderr, "SIGABRT from native. raise(%d)\n", signum);
+        checkOnSigabrt = true;
+               if (sigaction(SIGABRT, &sig_abrt_old, NULL) == 0) {
+                       if (raise(signum) < 0) {
+                               fprintf(stderr, "Fail to raise SIGABRT\n");
+                       }
+               } else {
+                       fprintf(stderr, "Fail to set original SIGABRT handler\n");
+               }
+    }
+}
+
+static void registerSigHandler()
+{
+       sig_abrt_new.sa_handler = onSigabrt;
+       if (sigemptyset(&sig_abrt_new.sa_mask) == 0) {
+               _ERR("Fail to initialize signal set");
+       }
+
+       if (sigaction(SIGABRT, &sig_abrt_new, &sig_abrt_old) < 0) {
+               _ERR("Fail to add sig handler");
+       }
+}
+
 CoreRuntime::CoreRuntime(const char* mode) :
        initializeClr(nullptr),
        executeAssembly(nullptr),
@@ -342,6 +384,8 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i
                        _ERR("Failed to redirect FD");
                        return -1;
                }
+
+               registerSigHandler();
        }
 
        pluginSetAppInfo(appId, path);
index 2268389..a9436f1 100644 (file)
@@ -23,6 +23,8 @@
 
 static int __pfd[2];
 static pthread_t loggingThread;
+static bool __hasException = false;
+
 
 static void *stdlog(void*)
 {
@@ -36,6 +38,10 @@ static void *stdlog(void*)
 
         buf[readSize] = 0;
 
+               if (strstr(buf, "Unhandled Exception:") != NULL) {
+                       __hasException = true;
+               }
+
         _LOGX("%s", buf);
     }
 
@@ -103,3 +109,7 @@ int runLoggingThread()
     return 0;
 }
 
+int hasException()
+{
+       return __hasException;
+}