From: Woongsuk Cho Date: Fri, 27 Jul 2018 04:34:18 +0000 (+0900) Subject: donot create coredump file for unhandled exception X-Git-Tag: accepted/tizen/unified/20180802.134837^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d8343b17367950df1c30434cdf291eefd9f37c1a;p=platform%2Fcore%2Fdotnet%2Flauncher.git donot create coredump file for unhandled exception Change-Id: I6cf6f566357250d7161effb34bbbd26d473791af --- diff --git a/NativeLauncher/inc/log_manager.h b/NativeLauncher/inc/log_manager.h index bf60651..32414fd 100644 --- a/NativeLauncher/inc/log_manager.h +++ b/NativeLauncher/inc/log_manager.h @@ -20,5 +20,6 @@ int initializeLogManager(); int redirectFD(); int runLoggingThread(); +int hasException(); #endif /* __LOG_MANAGER_H__ */ diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index 884a5a2..18a5c3e 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -16,6 +16,7 @@ #include +#include #include #include @@ -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); diff --git a/NativeLauncher/util/log_manager.cc b/NativeLauncher/util/log_manager.cc index 2268389..a9436f1 100644 --- a/NativeLauncher/util/log_manager.cc +++ b/NativeLauncher/util/log_manager.cc @@ -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; +}