summaryrefslogtreecommitdiff
path: root/src/appMain/life_cycle.cc
diff options
context:
space:
mode:
authorArtem Nosach <ANosach@luxoft.com>2015-08-31 18:46:23 +0300
committerArtem Nosach <ANosach@luxoft.com>2015-10-05 11:39:08 +0300
commitf0c029dfd85532038d30397796d656d4e0d28055 (patch)
treea6bca5a436c7feb472511a76b1fe91963ce80997 /src/appMain/life_cycle.cc
parent9b0e6fa62ff54a45c3a4cd209a46a0c518555efc (diff)
downloadsdl_core-f0c029dfd85532038d30397796d656d4e0d28055.tar.gz
Resend caught system signals to the main thread
Check for thread ID in signal handler and resend signal to main thread in case handler was running by another thread. It's needed to stop SDL correctly because main thread is waiting for signal and doesn't stop if signal has not come. Closes-bug: APPLINK-15828
Diffstat (limited to 'src/appMain/life_cycle.cc')
-rw-r--r--src/appMain/life_cycle.cc50
1 files changed, 32 insertions, 18 deletions
diff --git a/src/appMain/life_cycle.cc b/src/appMain/life_cycle.cc
index cb38d621db..a05b000a6a 100644
--- a/src/appMain/life_cycle.cc
+++ b/src/appMain/life_cycle.cc
@@ -344,30 +344,44 @@ bool LifeCycle::InitMessageSystem() {
#endif // MQUEUE_HMIADAPTER
namespace {
-
+ pthread_t main_thread;
void sig_handler(int sig) {
- // Do nothing
- }
-
- void agony(int sig) {
-// these actions are not signal safe
-// (in case logger is on)
-// but they cannot be moved to a separate thread
-// because the application most probably will crash as soon as this handler returns
-//
-// the application is anyway about to crash
- LOG4CXX_FATAL(logger_, "Stopping application due to segmentation fault");
-#ifdef ENABLE_LOG
- logger::LogMessageLoopThread::destroy();
-#endif
+ switch(sig) {
+ case SIGINT:
+ LOG4CXX_DEBUG(logger_, "SIGINT signal has been caught");
+ break;
+ case SIGTERM:
+ LOG4CXX_DEBUG(logger_, "SIGTERM signal has been caught");
+ break;
+ case SIGSEGV:
+ LOG4CXX_DEBUG(logger_, "SIGSEGV signal has been caught");
+ break;
+ default:
+ LOG4CXX_DEBUG(logger_, "Unexpected signal has been caught");
+ break;
+ }
+ /*
+ * Resend signal to the main thread in case it was
+ * caught by another thread
+ */
+ if(pthread_equal(pthread_self(), main_thread) == 0) {
+ LOG4CXX_DEBUG(logger_, "Resend signal to the main thread");
+ if(pthread_kill(main_thread, sig) != 0) {
+ LOG4CXX_FATAL(logger_, "Send signal to thread error");
+ }
+ }
}
-
} // namespace
void LifeCycle::Run() {
+ LOG4CXX_AUTO_TRACE(logger_);
+ main_thread = pthread_self();
// First, register signal handlers
- ::utils::SubscribeToTerminateSignal(&sig_handler);
- ::utils::SubscribeToFaultSignal(&agony);
+ if(!::utils::SubscribeToInterruptSignal(&sig_handler) ||
+ !::utils::SubscribeToTerminateSignal(&sig_handler) ||
+ !::utils::SubscribeToFaultSignal(&sig_handler)) {
+ LOG4CXX_FATAL(logger_, "Subscribe to system signals error");
+ }
// Now wait for any signal
pause();
}