From 5f0a12215490d46be1a4f3aa60ca9f5d27219793 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Mon, 13 Jul 2020 09:56:13 +0900 Subject: [PATCH 01/16] Release version 0.15.9 Changes: - Fix Launchpad Recovery Feature Change-Id: I318cfd0a3f062ce0305c8551c98437d0b7fcb884 Signed-off-by: Changgyu Choi --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index f9660e6..8668758 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.8 +Version: 0.15.9 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 8832dd73ee084822c5631c3bdc2ebef64557f2f0 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Mon, 20 Jul 2020 10:36:31 +0900 Subject: [PATCH 02/16] Add to check pid from __accept_candidate_process() Check whether different cpc and received socket pid, when accept client socket. If they are different, It is invalid accept. Change-Id: I2f2a3e9896fc07fc6ee77d4ca77d47042fa6d958 Signed-off-by: Changgyu Choi --- src/common/src/launchpad_common.c | 2 +- src/launchpad/src/launchpad.c | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/common/src/launchpad_common.c b/src/common/src/launchpad_common.c index 1521634..05d8bef 100644 --- a/src/common/src/launchpad_common.c +++ b/src/common/src/launchpad_common.c @@ -679,7 +679,7 @@ int _connect_to_launchpad(int type, int id) send_ret = send(fd, &client_pid, sizeof(client_pid), MSG_NOSIGNAL); _D("send(%d) : %d", client_pid, send_ret); if (send_ret == -1) { - _E("send error"); + _E("send error(%d)", errno); close(fd); return -1; } diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c index 9db8b9d..c665796 100644 --- a/src/launchpad/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -591,11 +591,13 @@ error: } static int __accept_candidate_process(int server_fd, int *out_client_fd, - int *out_client_pid) + int *out_client_pid, int cpc_pid) { int client_fd = -1; - int client_pid = 0; - int recv_ret = 0; + int recv_pid = 0; + int ret; + socklen_t len; + struct ucred cred = {}; if (server_fd == -1 || out_client_fd == NULL || out_client_pid == NULL) { @@ -614,15 +616,29 @@ static int __accept_candidate_process(int server_fd, int *out_client_fd, goto error; } - recv_ret = recv(client_fd, &client_pid, sizeof(client_pid), - MSG_WAITALL); - if (recv_ret == -1) { + ret = recv(client_fd, &recv_pid, sizeof(recv_pid), MSG_WAITALL); + if (ret == -1) { _E("recv error!"); goto error; } + len = sizeof(cred); + ret = getsockopt(client_fd, SOL_SOCKET, SO_PEERCRED, &cred, &len); + if (ret < 0) { + _E("getsockopt error"); + goto error; + } + + if (cred.pid != cpc_pid) { + _E("Invalid accept. pid(%d)", cred.pid); + goto error; + } + + if (cred.pid != recv_pid) + _W("Not equal recv and real pid"); + *out_client_fd = client_fd; - *out_client_pid = client_pid; + *out_client_pid = cred.pid; return *out_client_fd; @@ -1432,7 +1448,8 @@ static bool __handle_loader_event(int fd, io_condition_e cond, void *data) return false; if (!cpc->prepared) { - ret = __accept_candidate_process(fd, &client_fd, &client_pid); + ret = __accept_candidate_process(fd, &client_fd, &client_pid, + cpc->pid); if (ret >= 0) { /* for hydra need to set pid to pid of non-hydra candidate, */ /* which is connecting now */ @@ -1470,7 +1487,8 @@ static bool __handle_hydra_event(int fd, io_condition_e cond, void *data) return false; if (!cpc->prepared) { - ret = __accept_candidate_process(fd, &client_fd, &client_pid); + ret = __accept_candidate_process(fd, &client_fd, &client_pid, + cpc->pid); if (ret >= 0) { cpc->hydra_fd = client_fd; @@ -1536,6 +1554,7 @@ static bool __handle_label_monitor(int fd, io_condition_e cond, void *data) return false; } + _D("fd(%d) condition(%d)", fd, cond); _log_print("[LABEL]", "fd(%d), condition(%d)", fd, cond); security_manager_app_labels_monitor_process(label_monitor); -- 2.7.4 From 5ad8d40be0658e89de5cc085f95af1984f593b09 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Mon, 20 Jul 2020 13:54:56 +0900 Subject: [PATCH 03/16] Release version 0.15.10 Changes: - Add to check pid from __accept_candidate_process() Change-Id: I297cd5cb2a16f32fef93a4d1536e9325a5f2c7f5 Signed-off-by: Changgyu Choi --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 8668758..20ec450 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.9 +Version: 0.15.10 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From d29ee599373eae8cb83236405374fde1f8efc84d Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 22 Jul 2020 12:56:07 +0900 Subject: [PATCH 04/16] Fix Memory Monitor If previous memory status is equal to current memory status, the callback function is not called. Change-Id: Ie5c96ef10e19a4f0614b33ec6331ef0db01349c5 Signed-off-by: Hwankyu Jhun --- src/launchpad/src/launchpad_memory_monitor.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/launchpad/src/launchpad_memory_monitor.c b/src/launchpad/src/launchpad_memory_monitor.c index dacf3ab..bc99ec1 100644 --- a/src/launchpad/src/launchpad_memory_monitor.c +++ b/src/launchpad/src/launchpad_memory_monitor.c @@ -33,6 +33,7 @@ struct memory_monitor_s { unsigned int prev_used_ratio; unsigned int base_interval; unsigned int interval; + bool low_memory; guint tag; memory_monitor_cb callback; void *user_data; @@ -44,27 +45,14 @@ static void __memory_monitor_start(void); static gboolean __memory_check_cb(gpointer data) { - unsigned int mem_used_ratio = 0; - int ret; + bool low_memory; __monitor.tag = 0; - ret = _proc_get_mem_used_ratio(&mem_used_ratio); - if (ret != 0) { - _E("Failed to get mem used ratio"); - __monitor.interval = __monitor.base_interval; - __memory_monitor_start(); - return G_SOURCE_REMOVE; - } - - if (__monitor.callback) { - __monitor.callback(mem_used_ratio > __monitor.threshold, - __monitor.user_data); - } - - _D("previous used ratio(%u), current used ratio(%u)", - __monitor.prev_used_ratio, mem_used_ratio); + low_memory = _memory_monitor_is_low_memory(); + if (__monitor.low_memory != low_memory && __monitor.callback) + __monitor.callback(low_memory, __monitor.user_data); - __monitor.prev_used_ratio = mem_used_ratio; + __monitor.low_memory = low_memory; __memory_monitor_start(); return G_SOURCE_REMOVE; @@ -106,6 +94,10 @@ bool _memory_monitor_is_low_memory(void) unsigned int mem_used_ratio = 0; _proc_get_mem_used_ratio(&mem_used_ratio); + + _D("previous used ratio(%u), current used ratio(%u)", + __monitor.prev_used_ratio, mem_used_ratio); + __monitor.prev_used_ratio = mem_used_ratio; if (mem_used_ratio > __monitor.threshold) -- 2.7.4 From f14b7343765273890fbe72a12dfc9ec60b542719 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 22 Jul 2020 15:01:09 +0900 Subject: [PATCH 05/16] Release version 0.15.11 Changes: - Fix Memory Monitor Change-Id: I280478744858d4e95e5bb27ec929e5e9fe4be1c8 Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 20ec450..dcf1061 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.10 +Version: 0.15.11 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 5a37684b244f9b03717bf5f656c315c65ea03a4d Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 22 Jul 2020 13:46:18 +0900 Subject: [PATCH 06/16] Fix Launchpad Library - Removes calling _launchpad_plugin_prepare_app() Change-Id: I9f4d1737c446c4749f4a7e454add23145487fd68 Signed-off-by: Hwankyu Jhun --- src/lib/src/launchpad_lib.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/lib/src/launchpad_lib.c b/src/lib/src/launchpad_lib.c index 9852ecd..68c2ac4 100644 --- a/src/lib/src/launchpad_lib.c +++ b/src/lib/src/launchpad_lib.c @@ -35,7 +35,6 @@ #include "launchpad.h" #include "launchpad_common.h" -#include "launchpad_plugin.h" #include "launchpad_types.h" #include "preexec.h" @@ -72,12 +71,6 @@ static int __prepare_exec(const char *appid, const char *app_path, __preexec_run(pkg_type, appid, app_path); - ret = _launchpad_plugin_prepare_app(appid, kb); - if (ret != 0) { - _E("_launchpad_plugin_prepare_app() is failed. error(%d)", ret); - return -1; - } - ret = _enable_external_pkg(kb, pkgid, global ? GLOBAL_USER : getuid()); if (ret < 0) return -1; -- 2.7.4 From 8d75728f642f4d5ad78aaaa69fc1af2d6a26466a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 27 Jul 2020 11:34:19 +0900 Subject: [PATCH 07/16] Fix wrong implementation Change-Id: I9629c44391733c43ef8d9ff00cf428cb68fdec52 Signed-off-by: Hwankyu Jhun --- src/launchpad/src/launchpad.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c index c665796..1b941b9 100644 --- a/src/launchpad/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -1488,7 +1488,7 @@ static bool __handle_hydra_event(int fd, io_condition_e cond, void *data) if (!cpc->prepared) { ret = __accept_candidate_process(fd, &client_fd, &client_pid, - cpc->pid); + cpc->hydra_pid); if (ret >= 0) { cpc->hydra_fd = client_fd; -- 2.7.4 From 9363cb876c3acf314125b86662b0171cb57530ea Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 27 Jul 2020 12:52:09 +0900 Subject: [PATCH 08/16] Release version 0.15.12 Changes: - Fix Launchpad Library - Fix wrong implementation Change-Id: I8a8cae0b277f8302ed6ec0a4b68060195d4b304d Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index dcf1061..a28cfde 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.11 +Version: 0.15.12 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 24f14678f28f2432cf3349a93f51e45aed1e33ad Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 31 Jul 2020 10:00:47 +0900 Subject: [PATCH 09/16] Fix exception handling about printing log If the logger initialization is failed, printing log will be skipped. Change-Id: I2e94fb628ed6cc2b42312e9d83bcbfebd5c24c3a Signed-off-by: Hwankyu Jhun --- src/launchpad/src/launchpad_log.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/launchpad/src/launchpad_log.c b/src/launchpad/src/launchpad_log.c index 00acc46..a8d00a3 100644 --- a/src/launchpad/src/launchpad_log.c +++ b/src/launchpad/src/launchpad_log.c @@ -30,15 +30,9 @@ int _log_print(const char *tag, const char *format, ...) { char formatted_buf[LAUNCHPAD_LOG_MAX_STRING_SIZE]; va_list ap; - int ret; - if (!__logger) { - ret = _logger_create(PATH_LAUNCHPAD_LOG, &__logger); - if (ret != 0) { - _E("Failed to create log file. error(%d)", ret); - return -1; - } - } + if (!__logger) + return 0; va_start(ap, format); vsnprintf(formatted_buf, sizeof(formatted_buf), format, ap); -- 2.7.4 From 7ef36ed3b13415cd6014642bf0db70dfd2f70e85 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 31 Jul 2020 10:09:15 +0900 Subject: [PATCH 10/16] Release version 0.15.13 Changes: - Fix exception handling about printing log Change-Id: I48573b405361a58988de64720987f188b08ab5d6 Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index a28cfde..7af3e8c 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.12 +Version: 0.15.13 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 5899cef0a312ca0e764c66a30d8d51e1b5d96c50 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 5 Aug 2020 08:35:02 +0900 Subject: [PATCH 11/16] Add debugging logs Change-Id: I77be8ed0eac2ceb39776bb362f30a87597b7e56d Signed-off-by: Hwankyu Jhun --- src/launchpad/src/launchpad.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c index 1b941b9..6e9864d 100644 --- a/src/launchpad/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -1517,7 +1517,9 @@ static void __handle_sigchild(int pid, void *user_data) appid = g_hash_table_lookup(__pid_table, GINT_TO_POINTER(pid)); if (appid) { + _W("security_manager_cleanup_app() ++"); security_manager_cleanup_app(appid, getuid(), pid); + _W("security_manager_cleanup_app() --"); g_hash_table_remove(__pid_table, GINT_TO_POINTER(pid)); } -- 2.7.4 From f410e532bd20e6814a898c112d8807c5985c590f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 5 Aug 2020 08:41:09 +0900 Subject: [PATCH 12/16] Release version 0.15.14 Changes: - Add debugging logs Change-Id: I28fac4fa8d4f3125e2ee65ce67aab2529ccbf6fa Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 7af3e8c..41af01e 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.13 +Version: 0.15.14 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 9d0812ce40cc6509dd24e650c9947abcec8172bb Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 7 Aug 2020 14:49:08 +0900 Subject: [PATCH 13/16] Fix client pid check If the loader context is a hydra loader, launchpad doesn't check the client process ID. The child process of the hydra loader tries to connect to the launchpad-process-pool. If launchpad rejects the request, the child process of the hydra loader will be terminated. Change-Id: If4898ba64acb75f647086e266289a669f83673d5 Signed-off-by: Hwankyu Jhun --- src/launchpad/src/launchpad.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c index 6e9864d..804aa23 100644 --- a/src/launchpad/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -629,7 +629,7 @@ static int __accept_candidate_process(int server_fd, int *out_client_fd, goto error; } - if (cred.pid != cpc_pid) { + if (cpc_pid != -1 && cred.pid != cpc_pid) { _E("Invalid accept. pid(%d)", cred.pid); goto error; } @@ -1449,7 +1449,7 @@ static bool __handle_loader_event(int fd, io_condition_e cond, void *data) if (!cpc->prepared) { ret = __accept_candidate_process(fd, &client_fd, &client_pid, - cpc->pid); + cpc->is_hydra ? -1 : cpc->pid); if (ret >= 0) { /* for hydra need to set pid to pid of non-hydra candidate, */ /* which is connecting now */ -- 2.7.4 From 967463983c504940fca928338c99f245f148f23c Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 7 Aug 2020 15:49:46 +0900 Subject: [PATCH 14/16] Release version 0.15.15 Changes: - Fix client pid check Change-Id: I75c21585d3379a59be25e9e2b732f1422a217f33 Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 41af01e..8b02454 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.14 +Version: 0.15.15 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From ade3ffee277cf050df19c4aa2524fe7c3e202062 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 10 Aug 2020 09:34:05 +0900 Subject: [PATCH 15/16] Add worker thread for cleanup app To avoid blocking launchpad, a new worker thread is added for calling security_manager_cleanup_app(). While installing / uninstalling / updating the package, security-manager daemon can be blocked. If launchpad calls security_manager_cleanup_app() at that time, launchpad will be blocked. Change-Id: I1e88ec38f61eabe21afa754f39f511606c85f148 Signed-off-by: Hwankyu Jhun --- src/launchpad/inc/launchpad_worker.h | 38 +++++++++ src/launchpad/src/launchpad.c | 69 ++++++++++++++- src/launchpad/src/launchpad_worker.c | 161 +++++++++++++++++++++++++++++++++++ 3 files changed, 265 insertions(+), 3 deletions(-) create mode 100644 src/launchpad/inc/launchpad_worker.h create mode 100644 src/launchpad/src/launchpad_worker.c diff --git a/src/launchpad/inc/launchpad_worker.h b/src/launchpad/inc/launchpad_worker.h new file mode 100644 index 0000000..cee3000 --- /dev/null +++ b/src/launchpad/inc/launchpad_worker.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 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. + */ + +#ifndef __LAUNCHPAD_WORKER_H__ +#define __LAUNCHPAD_WORKER_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef bool (*worker_job_cb)(void *user_data); + +int _worker_add_job(worker_job_cb callback, void *user_data); + +int _worker_init(void); + +void _worker_fini(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __LAUNCHPAD_WORKER_H__ */ diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c index 804aa23..b74dbb2 100644 --- a/src/launchpad/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -54,6 +54,7 @@ #include "launchpad_proc.h" #include "launchpad_signal.h" #include "launchpad_types.h" +#include "launchpad_worker.h" #include "loader_info.h" #include "perf.h" @@ -159,6 +160,11 @@ struct app_info { bool exists; }; +struct cleanup_info_s { + char *appid; + int pid; +}; + static int __sys_hwacc; static GList *loader_info_list; static GList *app_defined_loader_info_list; @@ -1510,16 +1516,68 @@ static bool __handle_hydra_event(int fd, io_condition_e cond, void *data) return true; } +static void __destroy_cleanup_info(struct cleanup_info_s *info) +{ + if (!info) + return; + + free(info->appid); + free(info); +} + +static struct cleanup_info_s *__create_cleanup_info(const char *appid, int pid) +{ + struct cleanup_info_s *info; + + info = malloc(sizeof(struct cleanup_info_s)); + if (!info) { + _E("Out of memory"); + return NULL; + } + + info->appid = strdup(appid); + if (!info->appid) { + _E("strdup(%s) is failed", appid); + __destroy_cleanup_info(info); + return NULL; + } + + info->pid = pid; + + return info; +} + +static bool __cleanup_app_cb(void *user_data) +{ + struct cleanup_info_s *info = (struct cleanup_info_s *)user_data; + + _W("security_manager_cleanup_app() ++"); + security_manager_cleanup_app(info->appid, getuid(), info->pid); + _W("security_manager_cleanup_app() --"); + __destroy_cleanup_info(info); + return false; +} + static void __handle_sigchild(int pid, void *user_data) { candidate_process_context_t *cpc; + struct cleanup_info_s *info; char *appid; + int ret = -1; appid = g_hash_table_lookup(__pid_table, GINT_TO_POINTER(pid)); if (appid) { - _W("security_manager_cleanup_app() ++"); - security_manager_cleanup_app(appid, getuid(), pid); - _W("security_manager_cleanup_app() --"); + info = __create_cleanup_info(appid, pid); + if (info) + ret = _worker_add_job(__cleanup_app_cb, info); + + if (ret != 0) { + __destroy_cleanup_info(info); + _W("security_manager_cleanup_app() ++"); + security_manager_cleanup_app(appid, getuid(), pid); + _W("security_manager_cleanup_app() --"); + } + g_hash_table_remove(__pid_table, GINT_TO_POINTER(pid)); } @@ -3077,6 +3135,10 @@ static int __before_loop(int argc, char **argv) return -1; } + ret = _worker_init(); + if (ret < 0) + return ret; + __register_vconf_events(); __init_app_defined_loader_monitor(); _memory_monitor_init(); @@ -3091,6 +3153,7 @@ static void __after_loop(void) _log_fini(); _memory_monitor_fini(); __unregister_vconf_events(); + _worker_fini(); if (__pid_table) g_hash_table_destroy(__pid_table); diff --git a/src/launchpad/src/launchpad_worker.c b/src/launchpad/src/launchpad_worker.c new file mode 100644 index 0000000..3f600d7 --- /dev/null +++ b/src/launchpad/src/launchpad_worker.c @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2020 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. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "launchpad_worker.h" +#include "log_private.h" + +struct job_s { + worker_job_cb callback; + void *user_data; +}; + +struct worker_s { + GThread *thread; + GMutex mutex; + GCond cond; + GQueue *queue; +}; + +static struct worker_s __worker; + +int _worker_add_job(worker_job_cb callback, void *user_data) +{ + struct job_s *job; + + if (!callback) { + _E("Invalid parameter"); + return -EINVAL; + } + + job = malloc(sizeof(struct job_s)); + if (!job) { + _E("Out of memory"); + return -ENOMEM; + } + + job->callback = callback; + job->user_data = user_data; + + g_mutex_lock(&__worker.mutex); + g_queue_push_tail(__worker.queue, job); + g_cond_signal(&__worker.cond); + g_mutex_unlock(&__worker.mutex); + + return 0; +} + +static int __set_comm(const char *name) +{ + int fd; + ssize_t bytes_written; + char path[PATH_MAX]; + pid_t tid = syscall(__NR_gettid); + + _I("[%s] TID(%d)", name, tid); + snprintf(path, sizeof(path), "/proc/%d/comm", tid); + fd = open(path, O_WRONLY); + if (fd < 0) { + _E("Failed to open %s. error(%d)", path, errno); + return -1; + } + + bytes_written = write(fd, name, strlen(name) + 1); + if (bytes_written < 0) { + _E("Failed to write name(%s)", name); + close(fd); + return -1; + } + + close(fd); + return 0; +} + +static gpointer __worker_thread_cb(gpointer data) +{ + struct worker_s *worker = (struct worker_s *)data; + struct job_s *job; + bool done = false; + + __set_comm("worker"); + do { + g_mutex_lock(&worker->mutex); + if (g_queue_is_empty(worker->queue)) + g_cond_wait(&worker->cond, &worker->mutex); + + job = (struct job_s *)g_queue_pop_head(worker->queue); + g_mutex_unlock(&worker->mutex); + done = job->callback(job->user_data); + free(job); + } while (!done); + + return NULL; +} + +int _worker_init(void) +{ + _W("WORKER_INIT"); + + g_mutex_init(&__worker.mutex); + g_cond_init(&__worker.cond); + + __worker.queue = g_queue_new(); + if (!__worker.queue) { + _E("g_queue_new() is failed"); + return -ENOMEM; + } + + __worker.thread = g_thread_new("worker", __worker_thread_cb, &__worker); + if (!__worker.thread) { + _E("g_thread_new() is failed"); + return -ENOMEM; + } + + return 0; +} + +static bool __worker_done_cb(void *user_data) +{ + _W("Done"); + return true; +} + +void _worker_fini(void) +{ + _W("WORKER_FINI"); + + if (__worker.thread) { + _worker_add_job(__worker_done_cb, NULL); + g_thread_join(__worker.thread); + } + + if (__worker.queue) + g_queue_free_full(__worker.queue, (GDestroyNotify)free); + + g_cond_clear(&__worker.cond); + g_mutex_clear(&__worker.mutex); +} -- 2.7.4 From 595f745eb89b3e890e741c44d6f736e506755b83 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 10 Aug 2020 10:58:39 +0900 Subject: [PATCH 16/16] Release version 0.15.16 Changes: - Add worker thread for cleanup app Change-Id: I4df5b28af75beffc299bb80fa140acc87b43ca87 Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 8b02454..233d3e8 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.15 +Version: 0.15.16 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4