#include <vector>
#include "app-core-cpp/app_core_plugin_private.hh"
+#include "app-core-cpp/sigterm_handler_private.hh"
#include "common/glib_private.hh"
#include "common/log_private.hh"
};
AnrMonitor anr_monitor;
+internal::SigtermHandler sigterm_handler;
enum TizenProfile {
Unknown = 0x00,
impl_->argc_ = argc;
impl_->argv_ = argv;
traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:OPS_INIT");
+ sigterm_handler.Restore();
if (impl_->loop_delegator_)
impl_->loop_delegator_->OnLoopInit(argc, argv);
else
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "app-core-cpp/sigterm_handler_private.hh"
+
+#include <errno.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <sys/types.h>
+
+#include "common/log_private.hh"
+
+namespace tizen_cpp {
+namespace internal {
+namespace {
+
+struct sigaction old_action;
+bool restored = true;
+
+void RestoreSigaction() {
+ if (restored)
+ return;
+
+ if (sigaction(SIGTERM, &old_action, nullptr) != 0)
+ _W("sigaction() is failed. errno(%d)", errno);
+
+ restored = true;
+}
+
+void SignalHandler(int signo) {
+ _E("SIGTERM(%d) received", signo);
+ RestoreSigaction();
+ raise(signo);
+ exit(0);
+}
+
+void ChangeSigaction() {
+ struct sigaction action;
+ memset(&action, '\0', sizeof(action));
+ sigemptyset(&action.sa_mask);
+ action.sa_flags = SA_RESTART;
+ action.sa_handler = SignalHandler;
+
+ if (sigaction(SIGTERM, &action, &old_action) != 0)
+ _E("sigaction() is failed. errno(%d)", errno);
+
+ restored = false;
+}
+
+} // namespace
+
+SigtermHandler::SigtermHandler() {
+ ChangeSigaction();
+}
+
+SigtermHandler::~SigtermHandler() {
+ Restore();
+}
+
+void SigtermHandler::Restore() {
+ RestoreSigaction();
+}
+
+} // namespace internal
+} // namespace tizen_cpp
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CPP_APP_CORE_CPP_SIGTERM_HANDLER_PRIVATE_HH_
+#define TIZEN_CPP_APP_CORE_CPP_SIGTERM_HANDLER_PRIVATE_HH_
+
+namespace tizen_cpp {
+namespace internal {
+
+class SigtermHandler {
+ public:
+ SigtermHandler();
+ ~SigtermHandler();
+
+ SigtermHandler(const SigtermHandler&) = delete;
+ SigtermHandler& operator = (const SigtermHandler&) = delete;
+ SigtermHandler(SigtermHandler&&) = delete;
+ SigtermHandler& operator = (SigtermHandler&&) = delete;
+
+ void Restore();
+};
+
+} // namespace internal
+} // namespace tizen_cpp
+
+#endif // TIZEN_CPP_APP_CORE_CPP_SIGTERM_HANDLER_PRIVATE_HH_