summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHwankyu Jhun <h.jhun@samsung.com>2023-07-27 10:29:01 +0900
committerHwankyu Jhun <h.jhun@samsung.com>2023-07-27 10:54:45 +0900
commit9d0ea4da9a97b93b156bac802f7ba386c70c857c (patch)
tree6aefa847c848208067d2edc490c3290c32869e10
parent70747d724d024fae37397519b8005dc9a80e9c2d (diff)
downloadaul-1-9d0ea4da9a97b93b156bac802f7ba386c70c857c.tar.gz
aul-1-9d0ea4da9a97b93b156bac802f7ba386c70c857c.tar.bz2
aul-1-9d0ea4da9a97b93b156bac802f7ba386c70c857c.zip
Add new internal functions to kill loader process
The aul_kill_loader() function is added to send the kill request to launchpad-process-pool. Adds: - aul_kill_loader() - aul_kill_loader_for_uid() Change-Id: Id89226a0bf5dab959505ab437f340bfa6c28201d Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r--include/aul.h29
-rw-r--r--src/launch.cc44
-rw-r--r--tool/aul_test/tests/aul_kill_loader_test.cc51
3 files changed, 124 insertions, 0 deletions
diff --git a/include/aul.h b/include/aul.h
index 6482c758..c4ff8355 100644
--- a/include/aul.h
+++ b/include/aul.h
@@ -3315,6 +3315,35 @@ typedef void (*aul_reply_cb)(bundle *b, int is_cancel, void *user_data);
int aul_send_launch_request_for_uid(const char *appid, bundle *b, uid_t uid,
aul_reply_cb reply_cb, aul_result_cb result_cb, void *user_data);
+/**
+ * @brief Sends the kill request to the running loader process.
+ * @since_tizen 8.0
+ * @remarks This function is only available for system and user daemons.
+ * @param[in] loader_name The loader name
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ECOMM Communication error on send
+ * @retval #AUL_R_EILLACC Permission denied
+ */
+int aul_kill_loader(const char *loader_name);
+
+/**
+ * @brief Sends the kill request to the running loader process.
+ * @since_tizen 8.0
+ * @remarks This function is only available for system and user daemons.
+ * @param[in] loader_name The loader name
+ * @param[in] uid The target uid
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ECOMM Communication error on send
+ * @retval #AUL_R_EILLACC Permission denied
+ */
+int aul_kill_loader_for_uid(const char *loader_name, uid_t uid);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/launch.cc b/src/launch.cc
index fffa4370..18166447 100644
--- a/src/launch.cc
+++ b/src/launch.cc
@@ -29,7 +29,9 @@
#include <sys/types.h>
#include <ttrace.h>
+#include <filesystem>
#include <memory>
+#include <string>
#include <utility>
#include "app_request.h"
@@ -46,6 +48,10 @@ using namespace aul::internal;
namespace {
+constexpr const char kRunAulDaemonsPath[] = "/run/aul/daemons/";
+constexpr const char kLaunchpadProcessPoolSock[] =
+ ".launchpad-process-pool-sock";
+const int kPadCmdKillLoader = 19;
constexpr const int TEP_ISMOUNT_MAX_RETRY_CNT = 20;
class ResultInfo {
@@ -861,3 +867,41 @@ extern "C" API int aul_kill_pid_async(pid_t pid,
return AUL_R_OK;
}
+
+extern "C" API int aul_kill_loader(const char* loader_name) {
+ return aul_kill_loader_for_uid(loader_name, getuid());
+}
+
+extern "C" API int aul_kill_loader_for_uid(const char* loader_name,
+ uid_t uid) {
+ if (loader_name == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ if (uid < REGULAR_UID_MIN) {
+ uid = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
+ _W("Use system default user ID(%u)", uid);
+ }
+
+ std::string endpoint = kRunAulDaemonsPath + std::to_string(uid) + "/" +
+ std::string(kLaunchpadProcessPoolSock);
+ if (!std::filesystem::exists(endpoint)) {
+ _E("launchpad socket is not prepared");
+ return AUL_R_ENOENT;
+ }
+
+ int fd = aul_sock_create_launchpad_client(kLaunchpadProcessPoolSock, uid);
+ if (fd < 0) {
+ _E("Failed to create launchpad client socket. error(%d)", fd);
+ return aul_error_convert(fd);
+ }
+
+ tizen_base::Bundle b = { {AUL_K_LOADER_NAME, loader_name} };
+ int ret = aul_sock_send_bundle_with_fd(fd, kPadCmdKillLoader, b.GetHandle(),
+ AUL_SOCK_NOREPLY);
+ if (ret != AUL_R_OK)
+ return aul_error_convert(ret);
+
+ return AUL_R_OK;
+}
diff --git a/tool/aul_test/tests/aul_kill_loader_test.cc b/tool/aul_test/tests/aul_kill_loader_test.cc
new file mode 100644
index 00000000..85449b38
--- /dev/null
+++ b/tool/aul_test/tests/aul_kill_loader_test.cc
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 <stdlib.h>
+
+#include "include/aul.h"
+
+#include "aul_test.hh"
+#include "log_private.hh"
+
+namespace aul_test {
+
+class AulKillLoaderTest : public AulTest {
+ public:
+ AulKillLoaderTest()
+ : AulTest("kill_loader", "aul_kill_loader", "kill_loader <loader_name>") {
+ }
+
+ virtual ~AulKillLoaderTest() {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ int Test(int argc, char** argv) override {
+ if (argc < 3) {
+ Usage();
+ return -1;
+ }
+
+ _D("[aul_kill_loader test] %s", argv[2]);
+ return aul_kill_loader(argv[2]);
+ }
+};
+
+AUL_TEST_REGISTER(AulKillLoaderTest, kill_loader_test);
+
+} // namespace aul_test