Add SIGTERM handler 67/284967/3
authorChanggyu Choi <changyu.choi@samsung.com>
Fri, 2 Dec 2022 01:21:02 +0000 (10:21 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Fri, 2 Dec 2022 01:28:17 +0000 (01:28 +0000)
when the coreclr receives a sigterm, it attempts to forcibly exit without checking the thread status.
As a result, there is a problem that the app-core context disappears before the mainloop.
So a SIGTERM handler is added.

Change-Id: I4baa3a401cbf50ed1e17d8169e48f517a8b73a17
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
tizen-cpp/app-core-cpp/CMakeLists.txt
tizen-cpp/app-core-cpp/app_core_base.cc

index 81264e4..3a12ebb 100644 (file)
@@ -18,6 +18,7 @@ APPLY_PKG_CONFIG(${TARGET_APP_CORE_CPP} PUBLIC
   BUNDLE_DEPS
   CAPI_SYSTEM_INFO_DEPS
   DLOG_DEPS
+  ECORE_DEPS
   GIO_2_DEPS
   SENSOR_DEPS
   TTRACE_DEPS
index 63e5d31..03452e6 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <Ecore.h>
 #include <aul.h>
 #include <aul_app_lifecycle.h>
 #include <aul_watchdog.h>
@@ -27,6 +28,7 @@
 #include <locale.h>
 #include <malloc.h>
 #include <sensor_internal.h>
+#include <signal.h>
 #include <stdbool.h>
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -1184,6 +1186,16 @@ void AppCoreBase::Init(int argc, char** argv) {
     impl_->loop_delegator_->OnLoopInit(argc, argv);
   else
     OnLoopInit(argc, argv);
+
+  signal(SIGTERM, [](int n) {
+    ecore_main_loop_thread_safe_call_sync(
+        [](void* data) -> void* {
+          _W("sigterm handler");
+          ecore_main_loop_quit();
+          return nullptr;
+        }, nullptr);
+  });
+
   traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
 
   if (impl_->feature_ & FEATURE_BACKGROUND_MANAGEMENT)