From d8343b17367950df1c30434cdf291eefd9f37c1a Mon Sep 17 00:00:00 2001 From: Woongsuk Cho Date: Fri, 27 Jul 2018 13:34:18 +0900 Subject: [PATCH] donot create coredump file for unhandled exception Change-Id: I6cf6f566357250d7161effb34bbbd26d473791af --- NativeLauncher/inc/log_manager.h | 1 + NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 44 +++++++++++++++++++++++ NativeLauncher/util/log_manager.cc | 10 ++++++ 3 files changed, 55 insertions(+) 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; +} -- 2.7.4