From: Changgyu Choi Date: Mon, 10 Apr 2023 01:43:40 +0000 (+0900) Subject: Modify sigterm handling method X-Git-Tag: accepted/tizen/unified/20230411.161312~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=66dfb8ef9631415771d6128fda171bd570e92cb9;p=platform%2Fcore%2Fappfw%2Fapp-core.git Modify sigterm handling method When handling signals using the signal() API, there can be issues where the previous behavior is not properly finished and interrupted. This patch switches to using g_unix_signal_add() for safer signal handling. Change-Id: I73caf0d88b7fbbfd5171d32322eb81d681ec8b31 Signed-off-by: Changgyu Choi --- diff --git a/tizen-cpp/app-core-cpp/app_core_base.cc b/tizen-cpp/app-core-cpp/app_core_base.cc index 5e8803a..9d22bb1 100644 --- a/tizen-cpp/app-core-cpp/app_core_base.cc +++ b/tizen-cpp/app-core-cpp/app_core_base.cc @@ -22,13 +22,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include #include #include @@ -258,6 +258,7 @@ class AppCoreBase::Impl { int feature_ = 0; IAppCore* core_delegator_ = nullptr; IMainLoop* loop_delegator_ = nullptr; + guint signal_handler_source_ = 0; }; AppCoreBase::EventBase::EventBase(Type type) @@ -1232,11 +1233,19 @@ void AppCoreBase::Init(int argc, char** argv) { else OnLoopInit(argc, argv); - signal(SIGTERM, [](int n) { - _W("sigterm handler"); - if (context_ != nullptr) - context_->Exit(); - }); + impl_->signal_handler_source_ = g_unix_signal_add(SIGTERM, + [](gpointer data) -> gboolean { + _W("sigterm handler"); + if (context_ != nullptr) { + context_->Exit(); + context_->impl_->signal_handler_source_ = 0; + } + + return G_SOURCE_REMOVE; + }, nullptr); + + if (impl_->signal_handler_source_ == 0) + _E("Failed to add sigterm handler."); traceEnd(TTRACE_TAG_APPLICATION_MANAGER); @@ -1290,6 +1299,11 @@ void AppCoreBase::Init(int argc, char** argv) { } void AppCoreBase::Fini() { + if (impl_->signal_handler_source_) { + g_source_remove(impl_->signal_handler_source_); + impl_->signal_handler_source_ = 0; + } + Dispose(); }