From 67527db567db540f9dccab0726653ed9424da90d Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 14 Jul 2022 13:23:49 +0900 Subject: [PATCH 01/16] Add a new environemtn variable Before executing an application, the process sets GCOV_PREFIX="/tmp" for code coverage measurement. Change-Id: Ifbdc216f7fb507a522ad4cbe631c2b81af3bb5c1 Signed-off-by: Hwankyu Jhun --- src/lib/common/src/launchpad_common.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/common/src/launchpad_common.c b/src/lib/common/src/launchpad_common.c index 4286a74..0717c95 100644 --- a/src/lib/common/src/launchpad_common.c +++ b/src/lib/common/src/launchpad_common.c @@ -794,6 +794,8 @@ void _set_env(appinfo_t *menu_info, bundle *kb) #ifdef TIZEN_FEATURE_SET_PERSONALITY_32 __set_execution_domain(); #endif /* TIZEN_FEATURE_SET_PERSONALITY_32 */ + + setenv("GCOV_PREFIX", "/tmp", 1); } char **_create_argc_argv(bundle *kb, int *margc) -- 2.7.4 From 734051cd151271c31d8fb5532355b021b333db9c Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 14 Jul 2022 15:40:18 +0900 Subject: [PATCH 02/16] Release version 0.18.12 Changes: - Add a new environemtn variable Change-Id: I83a4a7a3b151bea2910f59c69f184637b1219c84 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 3254e80..001dcc0 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.18.11 +Version: 0.18.12 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From a6844133bfc3786f279dd7bdab165e723dd88f17 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Mon, 25 Jul 2022 10:45:27 +0900 Subject: [PATCH 03/16] Revert "Add cpu priority inheritance" This reverts commit b67f9e7e9a31a6b2ff4f2867d2c63edd9fda7209. Change-Id: I80317085c0a8b60ce463ab855313716f27d8709f Signed-off-by: Changgyu Choi --- CMakeLists.txt | 1 - packaging/launchpad.spec | 2 +- src/launchpad-process-pool/CMakeLists.txt | 1 - src/launchpad-process-pool/src/launchpad.c | 28 ---------------------------- 4 files changed, 1 insertion(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 267df09..fb3d5ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,5 @@ PKG_CHECK_MODULES(SECURITY_MANAGER_DEPS REQUIRED security-manager) PKG_CHECK_MODULES(TANCHOR_DEPS REQUIRED tanchor) PKG_CHECK_MODULES(TTRACE_DEPS REQUIRED ttrace) PKG_CHECK_MODULES(VCONF_DEPS REQUIRED vconf) -PKG_CHECK_MODULES(CAPI_SYSTEM_RESOURCE_DEPS REQUIRED capi-system-resource) ADD_SUBDIRECTORY(src) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 001dcc0..aeb02df 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -33,7 +33,6 @@ BuildRequires: pkgconfig(iniparser) BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(pkgmgr-installer) -BuildRequires: pkgconfig(capi-system-resource) Requires(post): /sbin/ldconfig Requires(post): /usr/bin/systemctl @@ -192,3 +191,4 @@ ln -sf ../launchpad-process-pool.service %{buildroot}%{_unitdir_user}/basic.targ %{_libdir}/*.so %{_libdir}/pkgconfig/liblaunchpad.pc %{_libdir}/pkgconfig/liblaunchpad-hydra.pc + diff --git a/src/launchpad-process-pool/CMakeLists.txt b/src/launchpad-process-pool/CMakeLists.txt index caec083..b0af4fe 100644 --- a/src/launchpad-process-pool/CMakeLists.txt +++ b/src/launchpad-process-pool/CMakeLists.txt @@ -39,7 +39,6 @@ APPLY_PKG_CONFIG(${TARGET_LAUNCHPAD_PROCESS_POOL} PUBLIC TANCHOR_DEPS TTRACE_DEPS VCONF_DEPS - CAPI_SYSTEM_RESOURCE_DEPS ) TARGET_LINK_LIBRARIES(${TARGET_LAUNCHPAD_PROCESS_POOL} PUBLIC "-lm -ldl") diff --git a/src/launchpad-process-pool/src/launchpad.c b/src/launchpad-process-pool/src/launchpad.c index 745ffa4..79bc219 100644 --- a/src/launchpad-process-pool/src/launchpad.c +++ b/src/launchpad-process-pool/src/launchpad.c @@ -15,7 +15,6 @@ */ #define _GNU_SOURCE -#include #include #include #include @@ -73,7 +72,6 @@ #define LOADERS_PATH "loaders" #define APP_DEFINED_LOADER_INFO_PATH OPT_SHARE_PATH "/" LOADERS_PATH #define COMMON_LOADER_NAME "common-loader1" -#define LAUNCHPAD_PROCESS_NAME "launchpad-process-pool" #define LAUNCHER_INFO_PATH LOADER_INFO_PATH #define REGULAR_UID_MIN 5000 @@ -786,13 +784,6 @@ static int __fork_app_process(int (*child_fn)(void *), void *arg) } if (pid == 0) { - resource_pid_t resource_st = { - pid = getpid(), - }; - ret = resource_clear_cpu_boosting(resource_st); - if (ret != 0) - _E("Failed to clear cpu boosting. error(%d)", ret); - _W("security_manager_prepare_app_candidate ++"); ret = security_manager_prepare_app_candidate(); _W("security_manager_prepare_app_candidate --"); @@ -3165,9 +3156,6 @@ static gboolean __launchpad_recovery_cb(gpointer data) static int __before_loop(int argc, char **argv) { int ret; - resource_pid_t resource_st = { - .pid = getpid(), - }; _print_hwc_log("%s(%d): START", __FUNCTION__, __LINE__); ret = __sequencer_init(); @@ -3239,27 +3227,11 @@ static int __before_loop(int argc, char **argv) _log_init(); _print_hwc_log("%s(%d): END", __FUNCTION__, __LINE__); - ret = resource_register_cpu_inheritance_destination( - (char*)LAUNCHPAD_PROCESS_NAME, resource_st); - if (ret != 0) { - _E("Failed to register cpu inheritance destination. error(%d)", - ret); - } - return 0; } static void __after_loop(void) { - int ret; - - ret = resource_unregister_cpu_inheritance_destination( - (char*)LAUNCHPAD_PROCESS_NAME); - if (ret != 0) { - _E("Failed to unregister cpu inheritance destination. " - "error(%d)", ret); - } - _log_fini(); _memory_monitor_fini(); __unregister_vconf_events(); -- 2.7.4 From 7d2a342559db65e37c749ce749ef22d69a03de41 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Mon, 25 Jul 2022 11:41:06 +0900 Subject: [PATCH 04/16] Release version 0.18.13 Changes: - Revert "Add cpu priority inheritance" Change-Id: I70f6b48c13e553bba15b980cff572b5e46fc98b2 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 aeb02df..8fc68bf 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.18.12 +Version: 0.18.13 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 293aabbf9a36260b1f0187fa6820ac35d0006376 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 25 Jul 2022 14:36:00 +0900 Subject: [PATCH 05/16] Send and receive candidate process ID The hydra loader sends a launched candidate process ID to launchpad-process-pool. When disposing the candidate process, launchpad-process-pool checks whether the candidate process is running or not to send SIGKILL signal. In the provious implementation, there is a problem that the candidate process was not terminated while it's executing. Change-Id: I88fe989f80007d9c5b6f4bb381c5ad2d863be4e8 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/src/launchpad.c | 14 ++++++++++++++ src/lib/launchpad-hydra/src/launchpad_hydra.c | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/src/launchpad-process-pool/src/launchpad.c b/src/launchpad-process-pool/src/launchpad.c index 79bc219..85e3c7a 100644 --- a/src/launchpad-process-pool/src/launchpad.c +++ b/src/launchpad-process-pool/src/launchpad.c @@ -1451,6 +1451,8 @@ static bool __handle_hydra_client_event(int fd, io_condition_e cond, void *data) { candidate_process_context_t *cpc = data; + int recv_pid = -1; + int ret; if (cpc == NULL) return false; @@ -1464,6 +1466,18 @@ static bool __handle_hydra_client_event(int fd, io_condition_e cond, return false; } + if (cond & IO_IN) { + ret = recv(cpc->hydra_fd, &recv_pid, sizeof(recv_pid), + MSG_WAITALL); + if (ret == -1) { + _E("recv() is failed. errno(%d)", errno); + } else { + _W("candidate process: %d", recv_pid); + if (recv_pid > 1) + cpc->pid = recv_pid; + } + } + return true; } diff --git a/src/lib/launchpad-hydra/src/launchpad_hydra.c b/src/lib/launchpad-hydra/src/launchpad_hydra.c index aa737fd..ba385db 100644 --- a/src/lib/launchpad-hydra/src/launchpad_hydra.c +++ b/src/lib/launchpad-hydra/src/launchpad_hydra.c @@ -202,6 +202,10 @@ retry_recv: __context.candidate_pid = __fork_process(__run_loader, NULL); _D("[__HYDRA__] candidate process(%d)", __context.candidate_pid); + len = send(fd, &__context.candidate_pid, + sizeof(__context.candidate_pid), MSG_NOSIGNAL); + if (len == -1) + _E("[__HYDRA__] send() is failed. errno(%d)", errno); return 0; err: @@ -437,6 +441,10 @@ API int launchpad_hydra_main(int argc, char **argv, __context.candidate_pid = __fork_process(__run_loader, NULL); _D("[__HYDRA__] candidate process(%d)", __context.candidate_pid); + if (send(__context.client_fd, &__context.candidate_pid, + sizeof(__context.candidate_pid), + MSG_NOSIGNAL) == -1) + _E("[__HYDRA__] send() is failed. errno(%d)", errno); __run_loop(); -- 2.7.4 From 548c72467ab53340443b48d4ea4f03131f500667 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 25 Jul 2022 15:17:42 +0900 Subject: [PATCH 06/16] Release version 0.18.14 Changes: - Send and receive candidate process ID Change-Id: I619a48d0f237aebf3f2a3511c533ffb9fcd95919 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 8fc68bf..91785ee 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.18.13 +Version: 0.18.14 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From e88b06163982ade242e336e4d93a748b756af0ba Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Tue, 19 Jul 2022 15:43:17 +0900 Subject: [PATCH 07/16] Implement launch of light user application Change-Id: I9ab41fe9e0dca4e2b40051a741182067a20f99f9 Signed-off-by: Ilho Kim --- src/launchpad-process-pool/src/launchpad.c | 8 +++++--- src/lib/common/inc/key.h | 1 + src/lib/launchpad/src/launchpad_lib.c | 8 +++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/launchpad-process-pool/src/launchpad.c b/src/launchpad-process-pool/src/launchpad.c index 85e3c7a..1ba060b 100644 --- a/src/launchpad-process-pool/src/launchpad.c +++ b/src/launchpad-process-pool/src/launchpad.c @@ -1230,6 +1230,7 @@ static int __prepare_exec(const char *appid, const char *app_path, appinfo_t *menu_info, bundle *kb) { char *file_name; + const char *enabled_light_user; char process_name[AUL_PR_NAME]; int ret; @@ -1267,9 +1268,10 @@ static int __prepare_exec(const char *appid, const char *app_path, _debug_change_mount_namespace(); /* SET PRIVILEGES*/ - _W("security_manager_prepare_app ++"); - ret = security_manager_prepare_app(appid); - _W("security_manager_prepare_app --"); + enabled_light_user = bundle_get_val(kb, AUL_K_ENABLED_LIGHT_USER); + _W("security_manager_prepare_app2 ++"); + ret = security_manager_prepare_app2(appid, enabled_light_user); + _W("security_manager_prepare_app2 --"); if (ret != SECURITY_MANAGER_SUCCESS) return PAD_ERR_REJECTED; diff --git a/src/lib/common/inc/key.h b/src/lib/common/inc/key.h index 19493c6..8889cca 100644 --- a/src/lib/common/inc/key.h +++ b/src/lib/common/inc/key.h @@ -51,6 +51,7 @@ extern "C" { #define AUL_K_INSTALLED_STORAGE "__AUL_INSTALLED_STORAGE__" #define AUL_K_MOUNT_GLOBAL_RES_DIR "__AUL_MOUNT_GLOBAL_RES_DIR__" #define AUL_K_MOUNT_ALLOWED_RES_DIR "__AUL_MOUNT_ALLOWED_RES_DIR__" +#define AUL_K_ENABLED_LIGHT_USER "__AUL_ENABLED_LIGHT_USER__" #ifdef __cplusplus } diff --git a/src/lib/launchpad/src/launchpad_lib.c b/src/lib/launchpad/src/launchpad_lib.c index e14894f..437dbbe 100644 --- a/src/lib/launchpad/src/launchpad_lib.c +++ b/src/lib/launchpad/src/launchpad_lib.c @@ -65,6 +65,7 @@ static int __prepare_exec(const char *appid, const char *app_path, const char *root_path, bool global, bundle *kb) { const char *file_name = NULL; + const char *enabled_light_user; char process_name[AUL_PR_NAME] = { 0, }; int ret; struct buxton_client *bxt_cli; @@ -94,9 +95,10 @@ static int __prepare_exec(const char *appid, const char *app_path, if (ret < 0) return -1; - _W("security_manager_prepare_app ++"); - ret = security_manager_prepare_app(appid); - _W("security_manager_prepare_app --"); + enabled_light_user = bundle_get_val(kb, AUL_K_ENABLED_LIGHT_USER); + _W("security_manager_prepare_app2 ++"); + ret = security_manager_prepare_app2(appid, enabled_light_user); + _W("security_manager_prepare_app2 --"); if (ret != SECURITY_MANAGER_SUCCESS) { _E("Failed to set privileges %s:%d", appid, ret); return -1; -- 2.7.4 From 03ae0ef0750fef5422a3b29233fe31a967105436 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Fri, 5 Aug 2022 10:27:17 +0900 Subject: [PATCH 08/16] Release version 0.19.0 Changes: - Implement launch of light user application Change-Id: I090af4f7c74ff05a8fee7d1ea82df059a8a42dc7 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 91785ee..0525399 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.18.14 +Version: 0.19.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From ab8d49d2fdf501ced10464e69275c8de86eced5f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 19 Sep 2022 07:45:29 +0000 Subject: [PATCH 09/16] Fix resource leak The allocated memory has to be released. The xmlGetProp() returns the allocated value. It should be released using xmlFree(). Change-Id: I031d76c587ad8dcab9141c585d732893d916eea9 Signed-off-by: Hwankyu Jhun --- src/launchpad-parser/launchpad_parser_plugin.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/launchpad-parser/launchpad_parser_plugin.cc b/src/launchpad-parser/launchpad_parser_plugin.cc index f873673..d8b23c0 100644 --- a/src/launchpad-parser/launchpad_parser_plugin.cc +++ b/src/launchpad-parser/launchpad_parser_plugin.cc @@ -103,15 +103,21 @@ int LaunchpadParser::Install(xmlDocPtr doc, std::string pkgid) { continue; xmlChar* val = xmlGetProp(node, reinterpret_cast("id")); + if (val == nullptr) + continue; + std::shared_ptr info = std::make_shared(std::string(reinterpret_cast(val))); + xmlFree(val); if (!IsValidId(info->GetId(), pkgid)) return -1; xmlChar* ttl = xmlGetProp(node, reinterpret_cast("time-to-live")); - if (ttl) + if (ttl) { info->SetTimeToLive(std::stoi(std::string(reinterpret_cast(ttl)))); + xmlFree(ttl); + } for (xmlNode* iter = node->children; iter; iter = iter->next) { if (!iter->name) @@ -120,10 +126,11 @@ int LaunchpadParser::Install(xmlDocPtr doc, std::string pkgid) { std::string(reinterpret_cast(iter->name)); if (child_name == "preload-library") { xmlChar* libname = xmlGetProp(iter, - reinterpret_cast("name")); + reinterpret_cast("name")); if (!libname) continue; info->AddPreloadLib(std::string(reinterpret_cast(libname))); + xmlFree(libname); } } loader_list_.push_back(info); @@ -158,6 +165,7 @@ int LaunchpadParser::UnInstall(xmlDocPtr doc, std::string pkgid) { return -1; std::string id = std::string(reinterpret_cast(val)); + xmlFree(val); if (!IsValidId(id, pkgid)) return -1; remove(GetFilePath(id).c_str()); -- 2.7.4 From bbedcfaa2bbe9e8971a4f3688117f3167850481e Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 19 Sep 2022 07:57:12 +0000 Subject: [PATCH 10/16] Release version 0.19.1 Changes: - Fix resource leak Change-Id: Idc73789582823bab17303215ca0d10b31b59bc3b 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 0525399..9ce9f6c 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.19.0 +Version: 0.19.1 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 9a607a8212db01af57616c36eb55ba4b4887b454 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Mon, 17 Oct 2022 12:12:25 +0900 Subject: [PATCH 11/16] Fix static analysis issues Change-Id: I6ef67f0f1b6423756955a94370fbcee51b1d81ee Signed-off-by: Changgyu Choi --- src/launchpad-process-pool/src/launchpad.c | 6 ++-- src/lib/common/src/launchpad_common.c | 8 ++--- src/lib/common/src/launchpad_socket.c | 58 +++++++++++++++--------------- 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/launchpad-process-pool/src/launchpad.c b/src/launchpad-process-pool/src/launchpad.c index 1ba060b..83e1d21 100644 --- a/src/launchpad-process-pool/src/launchpad.c +++ b/src/launchpad-process-pool/src/launchpad.c @@ -93,7 +93,7 @@ typedef struct { int type; bool prepared; int pid; /* for hydra this pid is not the pid of hydra itself */ - /* but pid of non-hydra candidate, which was forked from hydra */ + /* but pid of non-hydra candidate, which was forked from hydra */ int hydra_pid; int loader_id; int caller_pid; @@ -627,7 +627,7 @@ static int __accept_candidate_process(int server_fd, int *out_client_fd, goto error; } - len = sizeof(cred); + len = (socklen_t)sizeof(cred); ret = getsockopt(client_fd, SOL_SOCKET, SO_PEERCRED, &cred, &len); if (ret < 0) { _E("getsockopt error"); @@ -847,7 +847,7 @@ static void __set_live_timer(candidate_process_context_t *cpc) static int __hydra_send_request(int fd, enum hydra_cmd cmd) { int sent = 0; - int size = sizeof(cmd); + int size = (int)sizeof(cmd); int send_ret = 0; while (sent != size) { diff --git a/src/lib/common/src/launchpad_common.c b/src/lib/common/src/launchpad_common.c index 0717c95..0db3125 100644 --- a/src/lib/common/src/launchpad_common.c +++ b/src/lib/common/src/launchpad_common.c @@ -415,12 +415,10 @@ retry_recv: app_pkt_t *_accept_recv_pkt_raw(int fd, int *clifd, struct ucred *cr) { struct sockaddr_un aul_addr = { 0, }; - int sun_size; + int sun_size = (int)sizeof(struct sockaddr_un); app_pkt_t *pkt; int newfd; - int cl = sizeof(struct ucred); - - sun_size = sizeof(struct sockaddr_un); + int cl = (int)sizeof(struct ucred); newfd = accept(fd, (struct sockaddr *)&aul_addr, (socklen_t *) &sun_size); @@ -1513,7 +1511,7 @@ void _print_hwc_log(const char *format, ...) static int __get_mount_opt(const char *srcs[], size_t srcs_len, const char *dest, char *opt, size_t opt_len) { - int i; + size_t i; char buf[PATH_MAX]; int ret; diff --git a/src/lib/common/src/launchpad_socket.c b/src/lib/common/src/launchpad_socket.c index a79905b..16241f7 100644 --- a/src/lib/common/src/launchpad_socket.c +++ b/src/lib/common/src/launchpad_socket.c @@ -42,26 +42,26 @@ struct socket_s { static int __set_socket_option(int fd, bool client) { - struct timeval tv = { 5, 200 * 1000 }; /* 5.2 sec */ - int size = LAUNCHPAD_SOCKET_MAX_BUFF; - int flag; - int ret; + struct timeval tv = { 5, 200 * 1000 }; /* 5.2 sec */ + int size = LAUNCHPAD_SOCKET_MAX_BUFF; + int flag; + int ret; - ret = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)); - if (ret < 0) { + ret = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)); + if (ret < 0) { ret = -errno; _E("setsockopt(SO_SNDBUF) is failed. fd(%d), errno(%d)", fd, errno); - return ret; - } + return ret; + } - ret = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)); - if (ret < 0) { + ret = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)); + if (ret < 0) { ret = -errno; _E("setsockopt(SO_RCVBUF) is failed. fd(%d), errno(%d)", fd, errno); - return ret; - } + return ret; + } if (!client) return 0; @@ -83,7 +83,7 @@ static int __set_socket_option(int fd, bool client) return ret; } - return 0; + return 0; } static int __create_server_socket(const char *path) @@ -136,27 +136,27 @@ static int __create_client_socket(const char *path) int fd; fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); - if (fd < 0) { + if (fd < 0) { ret = -errno; _E("socket() is failed. path(%s), errno(%d)", path, errno); - return ret; - } + return ret; + } - addr.sun_family = AF_UNIX; - snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path); - while (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - if (errno != ETIMEDOUT || retry <= 0) { + addr.sun_family = AF_UNIX; + snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path); + while (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { + if (errno != ETIMEDOUT || retry <= 0) { ret = -errno; _E("connect() is failed. path(%s), errno(%d)", path, errno); - close(fd); - return ret; - } + close(fd); + return ret; + } - usleep(LAUNCHPAD_SOCKET_RETRY_TIME); - retry--; - _W("Retry(%d) to connect to %s", retry, path); - } + usleep(LAUNCHPAD_SOCKET_RETRY_TIME); + retry--; + _W("Retry(%d) to connect to %s", retry, path); + } ret = __set_socket_option(fd, true); if (ret < 0) { @@ -273,8 +273,8 @@ int _socket_accept(socket_h handle, socket_h *client_socket) struct socket_s *sock; struct sockaddr_un addr = { 0, }; struct ucred cred = { 0, }; - socklen_t addr_size = sizeof(struct sockaddr_un); - socklen_t cred_size = sizeof(struct ucred); + socklen_t addr_size = (socklen_t)sizeof(struct sockaddr_un); + socklen_t cred_size = (socklen_t)sizeof(struct ucred); int client_fd; int ret; -- 2.7.4 From 27c46a599f0ff9df93cd29f939515174a754a400 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Tue, 18 Oct 2022 11:26:24 +0900 Subject: [PATCH 12/16] Release version 0.19.2 Changes: - Fix static analysis issues Change-Id: I5fd2f82cf99c3ab8360780f98db913f81496f378 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 9ce9f6c..b4f0553 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.19.1 +Version: 0.19.2 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 0baf8cf694388fe40535340a9a5dc1569006333c Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 18 Oct 2022 09:22:59 +0000 Subject: [PATCH 13/16] Add an environmant variable related to ASAN While getting a launch request for ASAN debugging, the launchpad adds 'TIZEN_ASAN_ACTIVATION' environment variable for activating ASAN. Related: - https://review.tizen.org/gerrit/#/c/platform/upstream/gcc/+/283119/ Change-Id: I5d6fdf47d872de4f7985e074ada550368ebaced3 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/src/launchpad_debug.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/launchpad-process-pool/src/launchpad_debug.c b/src/launchpad-process-pool/src/launchpad_debug.c index 8040f45..da59159 100644 --- a/src/launchpad-process-pool/src/launchpad_debug.c +++ b/src/launchpad-process-pool/src/launchpad_debug.c @@ -403,6 +403,9 @@ void _debug_prepare_debugger(bundle *kb) if (debugger == NULL) return; + if (!strcmp(debugger, "ASAN")) + setenv("TIZEN_ASAN_ACTIVATION", "1", 1); + ret = __redirect_std_fds(kb); if (ret < 0) _E("[DEBUG] Failed to redirect standard fds"); -- 2.7.4 From 5f6582e1e6befd3eb8ccd620e9bdb7325404fed2 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 18 Oct 2022 10:36:39 +0000 Subject: [PATCH 14/16] Release version 0.19.3 Changes: - Add an environmant variable related to ASAN Change-Id: Ib84a6127f8d2a0a041a07cb7b371a2a36f3b844b 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 b4f0553..574dbae 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.19.2 +Version: 0.19.3 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 7a0291e7ff6c31fa9c8f89b5beb6d884ca053a6b Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 8 Nov 2022 01:48:16 +0000 Subject: [PATCH 15/16] Create a child process in the worker thread To avoid blocking main thread of launchpad-process-pool, the worker thread creates a child process. Change-Id: I6cd499a6d6a5fc3d0d2d81f2256e299f4067eb68 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/inc/launchpad_worker.h | 8 +- src/launchpad-process-pool/src/launchpad.c | 702 +++++++++++++++------- src/launchpad-process-pool/src/launchpad_worker.c | 77 ++- 3 files changed, 536 insertions(+), 251 deletions(-) diff --git a/src/launchpad-process-pool/inc/launchpad_worker.h b/src/launchpad-process-pool/inc/launchpad_worker.h index cee3000..0276545 100644 --- a/src/launchpad-process-pool/inc/launchpad_worker.h +++ b/src/launchpad-process-pool/inc/launchpad_worker.h @@ -23,13 +23,15 @@ extern "C" { #endif +typedef struct worker_s *worker_h; + typedef bool (*worker_job_cb)(void *user_data); -int _worker_add_job(worker_job_cb callback, void *user_data); +int _worker_add_job(worker_h worker, worker_job_cb callback, void *user_data); -int _worker_init(void); +int _worker_create(const char *name, worker_h *worker); -void _worker_fini(void); +void _worker_destroy(worker_h worker); #ifdef __cplusplus } diff --git a/src/launchpad-process-pool/src/launchpad.c b/src/launchpad-process-pool/src/launchpad.c index 83e1d21..3d03c43 100644 --- a/src/launchpad-process-pool/src/launchpad.c +++ b/src/launchpad-process-pool/src/launchpad.c @@ -165,6 +165,33 @@ struct cleanup_info_s { int pid; }; +typedef struct candidate_info_s { + char **argv; + int argc; + int loader_id; + int type; + pid_t pid; +} candidate_info_t; + +typedef struct request_s { + app_pkt_t *pkt; + appinfo_t *menu_info; + bundle *kb; + candidate_process_context_t *cpc; + candidate_process_context_t *org_cpc; + const char *app_path; + int clifd; + int cmd; + int loader_id; + pid_t caller_pid; + uid_t caller_uid; + pid_t pid; /* result */ +} request_t; + +typedef request_t *request_h; + +typedef int (*request_handler)(request_h request); + static int __sys_hwacc; static GList *loader_info_list; static GList *app_defined_loader_info_list; @@ -184,6 +211,8 @@ static io_channel_h __logger_channel; static io_channel_h __label_monitor_channel; static io_channel_h __launchpad_channel; static int __client_fd = -1; +static worker_h __cleaner; +static worker_h __forker; static candidate_process_context_t *__add_slot(int type, int loader_id, int caller_pid, const char *loader_name, @@ -754,30 +783,12 @@ static int __real_send(int clifd, int ret) return 0; } -static void __send_result_to_caller(int clifd, int ret) -{ - _W("send result: %d", ret); - - if (clifd == -1) - return; - - if (ret <= 1) { - _E("launching failed"); - __real_send(clifd, ret); - return; - } - - if (__real_send(clifd, ret) < 0) - __kill_process(ret); -} - static int __fork_app_process(int (*child_fn)(void *), void *arg) { int pid; int ret; pid = fork(); - if (pid == -1) { _E("failed to fork child process"); return -1; @@ -872,52 +883,131 @@ static int __hydra_send_launch_candidate_request(int fd) return __hydra_send_request(fd, LAUNCH_CANDIDATE); } -static int __prepare_candidate_process(int type, int loader_id) +static void __candidate_info_free(candidate_info_t *info) +{ + int i; + + if (info == NULL) + return; + + if (info->argv) { + for (i = 0; i < info->argc; i++) + free(info->argv[i]); + + free(info->argv); + } + + free(info); +} + +static int __candidate_info_create(candidate_process_context_t *cpt, + candidate_info_t **candidate_info) { - int pid; char type_str[12] = {0, }; char loader_id_str[12] = {0, }; char argbuf[LOADER_ARG_LEN]; - char *argv[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL}; - candidate_process_context_t *cpt = __find_slot(type, loader_id); + candidate_info_t *info; if (cpt == NULL) - return -1; + return -EINVAL; - if (cpt->is_hydra && cpt->hydra_pid != HYDRA_NONE) - return __hydra_send_launch_candidate_request(cpt->hydra_fd); + info = calloc(1, sizeof(candidate_info_t)); + if (info == NULL) { + _E("calloc() is failed"); + return -ENOMEM; + } + + info->argv = calloc(LOADER_ARG_DUMMY + 1, sizeof(char *)); + if (info->argv == NULL) { + _E("calloc() is failed"); + __candidate_info_free(info); + return -ENOMEM; + } - _D("prepare candidate process / type:%d", type); memset(argbuf, ' ', LOADER_ARG_LEN); argbuf[LOADER_ARG_LEN - 1] = '\0'; - argv[LOADER_ARG_DUMMY] = argbuf; + info->argv[LOADER_ARG_DUMMY] = strdup(argbuf); - cpt->last_exec_time = time(NULL); + snprintf(loader_id_str, sizeof(loader_id_str), "%d", cpt->loader_id); + snprintf(type_str, sizeof(type_str), "%d", cpt->type); + info->argv[LOADER_ARG_PATH] = strdup(cpt->loader_path); + info->argv[LOADER_ARG_TYPE] = strdup(type_str); + info->argv[LOADER_ARG_ID] = strdup(loader_id_str); + info->argv[LOADER_ARG_HYDRA] = strdup(cpt->is_hydra ? "1" : "0"); + info->argv[LOADER_ARG_EXTRA] = strdup(cpt->loader_extra); - snprintf(loader_id_str, sizeof(loader_id_str), "%d", loader_id); - snprintf(type_str, sizeof(type_str), "%d", type); - argv[LOADER_ARG_PATH] = cpt->loader_path; - argv[LOADER_ARG_TYPE] = type_str; - argv[LOADER_ARG_ID] = loader_id_str; - argv[LOADER_ARG_HYDRA] = cpt->is_hydra ? "1" : "0"; - argv[LOADER_ARG_EXTRA] = cpt->loader_extra; + info->argc = LOADER_ARG_DUMMY + 1; + info->type = cpt->type; + info->loader_id = cpt->loader_id; - pid = __fork_app_process(__exec_loader_process, argv); - if (pid == -1) { - _E("Failed to fork candidate_process"); - return -1; - } + *candidate_info = info; + return 0; +} - if (cpt->is_hydra) { - cpt->hydra_pid = pid; - } else { - cpt->pid = pid; - __set_live_timer(cpt); +static gboolean __handle_exec_loader_process(gpointer user_data) +{ + candidate_process_context_t *cpt; + candidate_info_t *info = user_data; + + _W("Candidate process. type: %d, loader_id: %d, pid: %d", + info->type, info->loader_id, info->pid); + if (info->pid > 0) { + cpt = __find_slot(info->type, info->loader_id); + cpt->last_exec_time = time(NULL); + if (cpt->is_hydra) { + cpt->hydra_pid = info->pid; + } else { + cpt->pid = info->pid; + __set_live_timer(cpt); + } + + _log_print("[CANDIDATE]", "pid(%7d) | type(%d) | loader(%s)", + info->pid, cpt->loader_id, cpt->loader_name); + _memory_monitor_reset_timer(); } - _log_print("[CANDIDATE]", "pid(%7d) | type(%d) | loader(%s)", - pid, cpt->loader_id, cpt->loader_name); - _memory_monitor_reset_timer(); + __candidate_info_free(info); + return G_SOURCE_REMOVE; +} + +static bool __exec_loader_process_cb(void *user_data) +{ + candidate_info_t *info = user_data; + + if (info == NULL) + return false; + + info->pid = __fork_app_process(__exec_loader_process, info->argv); + if (info->pid == -1) + _E("Failed to create a child process"); + + g_idle_add(__handle_exec_loader_process, info); + return false; +} + +static int __prepare_candidate_process(int type, int loader_id) +{ + candidate_process_context_t *cpt = __find_slot(type, loader_id); + candidate_info_t *info; + int ret; + + if (cpt == NULL) + return -1; + + if (cpt->is_hydra && cpt->hydra_pid != HYDRA_NONE) + return __hydra_send_launch_candidate_request(cpt->hydra_fd); + + _D("prepare candidate process / type:%d", type); + ret = __candidate_info_create(cpt, &info); + if (ret < 0) + return ret; + + ret = _worker_add_job(__forker, __exec_loader_process_cb, info); + if (ret != 0) { + _E("_worker_add_job() is failed"); + __candidate_info_free(info); + return -1; + } return 0; } @@ -1612,7 +1702,7 @@ static void __handle_sigchild(int pid, void *user_data) if (appid) { info = __create_cleanup_info(appid, pid); if (info) - ret = _worker_add_job(__cleanup_app_cb, info); + ret = _worker_add_job(__cleaner, __cleanup_app_cb, info); if (ret != 0) { __destroy_cleanup_info(info); @@ -2160,228 +2250,391 @@ static void __update_slot_state(candidate_process_context_t *cpc, int method, } } -static bool __handle_launch_event(int fd, io_condition_e cond, void *data) +static void __request_destroy(request_t *request) +{ + if (request == NULL) + return; + + if (request->clifd > -1) + close(request->clifd); + if (request->menu_info) + _appinfo_free(request->menu_info); + if (request->kb) + bundle_free(request->kb); + if (request->pkt) + free(request->pkt); + free(request); +} + +static int __request_create(int fd, request_t **request) { - bundle *kb = NULL; - app_pkt_t *pkt = NULL; - appinfo_t *menu_info = NULL; - candidate_process_context_t *cpc = NULL; - candidate_process_context_t *org_cpc = NULL; - const char *app_path = NULL; - int pid = -1; - int clifd = -1; struct ucred cr; - int type = -1; - int loader_id; - int ret; + request_t *req; - if (cond & (IO_ERR | IO_HUP | IO_NVAL)) { - _E("fd(%d), condition(%d)", fd, cond); - g_idle_add(__launchpad_recovery_cb, __launchpad_channel); - __launchpad_channel = NULL; - return false; + if (request == NULL) { + _E("Invalid parameter"); + return -EINVAL; } - traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "LAUNCHPAD:LAUNCH"); - pkt = _accept_recv_pkt_raw(fd, &clifd, &cr); - if (!pkt) { - _E("packet is NULL"); - goto end; + req = calloc(1, sizeof(request_t)); + if (req == NULL) { + _E("calloc() is failed"); + return -ENOMEM; } - _W("cmd(%d), caller(%d)", pkt->cmd, cr.pid); - if (cr.uid >= REGULAR_UID_MIN) { - if (__check_caller_by_pid(cr.pid) < 0) { - _E("Invalid caller pid"); - goto end; - } + req->clifd = -1; + req->pkt = _accept_recv_pkt_raw(fd, &req->clifd, &cr); + if (req->pkt == NULL) { + _E("_accept_recv_pkt_raw() is failed"); + __request_destroy(req); + return -ECOMM; } - kb = bundle_decode(pkt->data, pkt->len); - if (!kb) { - _E("bundle decode error"); - goto end; + req->kb = bundle_decode(req->pkt->data, req->pkt->len); + if (req->kb == NULL) { + _E("bundle_decode() is failed"); + __real_send(req->clifd, -EINVAL); + req->clifd = -1; + __request_destroy(req); + return -EINVAL; } - if (bundle_get_type(kb, AUL_K_SDK) != BUNDLE_TYPE_NONE) - _debug_init(); + req->cmd = req->pkt->cmd; + req->caller_pid = cr.pid; + req->caller_uid = cr.uid; + *request = req; + return 0; +} - switch (pkt->cmd) { - case PAD_CMD_VISIBILITY: - ret = __dispatch_cmd_hint(kb, METHOD_VISIBILITY); - __real_send(clifd, ret); - clifd = -1; - goto end; - case PAD_CMD_ADD_LOADER: - ret = __dispatch_cmd_add_loader(kb); - __real_send(clifd, ret); - clifd = -1; - goto end; - case PAD_CMD_REMOVE_LOADER: - ret = __dispatch_cmd_remove_loader(kb); - __real_send(clifd, ret); - clifd = -1; - goto end; - case PAD_CMD_MAKE_DEFAULT_SLOTS: - ret = __add_default_slots(); - if (ret != 0) - _E("Failed to make default slots"); - __real_send(clifd, ret); - clifd = -1; - goto end; - case PAD_CMD_PREPARE_APP_DEFINED_LOADER: - ret = __dispatch_cmd_add_app_defined_loader(kb); - __real_send(clifd, ret); - clifd = -1; - goto end; - case PAD_CMD_DEMAND: - ret = __dispatch_cmd_hint(kb, METHOD_DEMAND); - __real_send(clifd, ret); - clifd = -1; - goto end; - case PAD_CMD_PING: - __real_send(clifd, getpid()); - clifd = -1; - goto end; - case PAD_CMD_UPDATE_APP_TYPE: - __dispatch_cmd_update_app_type(kb); - close(clifd); - clifd = -1; - goto end; - case PAD_CMD_CONNECT: - _W("Connected. fd(%d)", clifd); - if (__client_fd != -1) - close(__client_fd); +static void __request_send_result(request_h request, int result) +{ + if (request->clifd < 0) + return; - __client_fd = clifd; - clifd = -1; - goto end; - } + __real_send(request->clifd, result); + request->clifd = -1; +} - INIT_PERF(kb); - PERF("packet processing start"); +static int __visibility_request_handler(request_h request) +{ + int ret = __dispatch_cmd_hint(request->kb, METHOD_VISIBILITY); - menu_info = _appinfo_create(kb); - if (menu_info == NULL) { - _E("such pkg no found"); - __send_result_to_caller(clifd, -EINVAL); - clifd = -1; - goto end; + __request_send_result(request, ret); + _D("[PAD_CMD_VISIBILITY] result: %d", ret); + return ret; +} + +static int __add_loader_request_handler(request_h request) +{ + int ret = __dispatch_cmd_add_loader(request->kb); + + __request_send_result(request, ret); + _D("[PAD_CMD_ADD_LOADER] result: %d", ret); + return ret; +} + +static int __remove_loader_request_handler(request_h request) +{ + int ret = __dispatch_cmd_remove_loader(request->kb); + + __request_send_result(request, ret); + _D("[PAD_CMD_REMOVE_LOADER] result: %d", ret); + return ret; +} + +static int __make_default_slots_request_handler(request_h request) +{ + int ret = __add_default_slots(); + + __request_send_result(request, ret); + _D("[PAD_CMD_MAKE_DEFAULT_SLOTS] result: %d", ret); + return ret; +} + +static int __prepare_app_defined_loader_request_handler(request_h request) +{ + int ret = __dispatch_cmd_add_app_defined_loader(request->kb); + + __request_send_result(request, ret); + _D("[PAD_CMD_PREPARE_APP_DEFINED_LOADER] result: %d", ret); + return ret; +} + +static int __demand_request_handler(request_h request) +{ + int ret = __dispatch_cmd_hint(request->kb, METHOD_DEMAND); + + __request_send_result(request, ret); + _D("[PAD_CMD_DEMAND] result: %d", ret); + return ret; +} + +static int __ping_request_handler(request_h request) +{ + __request_send_result(request, getpid()); + _D("[PAD_CMD_PING] result: %d", getpid()); + return 0; +} + +static int __update_app_type_request_handler(request_h request) +{ + int ret = __dispatch_cmd_update_app_type(request->kb); + + _D("[PAD_CMD_UPDATE_APP_TYPE] result: %d", ret); + return ret; +} + +static int __connect_request_handler(request_h request) +{ + if (__client_fd != -1) + close(__client_fd); + + __client_fd = request->clifd; + request->clifd = -1; + _D("[PAD_CMD_CONNECT] client fd: %d", __client_fd); + return 0; +} + +static int __launch_request_prepare(request_h request) +{ + const appinfo_t *menu_info; + int type = -1; + + request->menu_info = _appinfo_create(request->kb); + if (request->menu_info == NULL) { + _E("_appinfo_create() is failed"); + return -1; } - app_path = _appinfo_get_app_path(menu_info); - if (app_path == NULL) { - _E("app_path is NULL"); - __send_result_to_caller(clifd, -EINVAL); - clifd = -1; - goto end; + request->app_path = _appinfo_get_app_path(request->menu_info); + if (request->app_path == NULL) { + _E("_appinfo_get_app_path() is failed"); + return -1; } - if (app_path[0] != '/') { - _E("app_path is not absolute path"); - __send_result_to_caller(clifd, -EINVAL); - clifd = -1; - goto end; + if (request->app_path[0] != '/') { + _E("app path is not absolute path"); + return -1; } + menu_info = request->menu_info; if (menu_info->hwacc == NULL) { - _E("[launchpad] Failed to find H/W acceleration type"); - __send_result_to_caller(clifd, -EINVAL); - clifd = -1; - goto end; + _E("Failed to find HW acceeleration type"); + return -1; } - SECURE_LOGD("exec : %s", menu_info->app_path); - SECURE_LOGD("comp_type : %s", menu_info->comp_type); - SECURE_LOGD("internal pool : %s", menu_info->internal_pool); - SECURE_LOGD("hwacc : %s", menu_info->hwacc); - SECURE_LOGD("app_type : %s", menu_info->app_type); - SECURE_LOGD("pkg_type : %s", menu_info->pkg_type); + SECURE_LOGD("appid: %s", menu_info->appid); + SECURE_LOGD("exec: %s", menu_info->app_path); + SECURE_LOGD("comp_type: %s", menu_info->comp_type); + SECURE_LOGD("internal pool: %s", menu_info->internal_pool); + SECURE_LOGD("hwacc: %s", menu_info->hwacc); + SECURE_LOGD("app_type: %s", menu_info->app_type); + SECURE_LOGD("pkg_type: %s", menu_info->pkg_type); - if (menu_info->comp_type && - strcmp(menu_info->comp_type, "svcapp") == 0) { - loader_id = __get_loader_id(kb); - if (loader_id > PAD_LOADER_ID_DYNAMIC_BASE) { + if (menu_info->comp_type && !strcmp(menu_info->comp_type, "svcapp")) { + request->loader_id = __get_loader_id(request->kb); + if (request->loader_id > PAD_LOADER_ID_DYNAMIC_BASE) { type = LAUNCHPAD_LOADER_TYPE_DYNAMIC; - cpc = __find_slot(type, loader_id); - if (cpc && !cpc->prepared) - cpc = NULL; + request->cpc = __find_slot(type, request->loader_id); + if (request->cpc && !request->cpc->prepared) + request->cpc = NULL; } else { - loader_id = PAD_LOADER_ID_DIRECT; + request->loader_id = PAD_LOADER_ID_DIRECT; } } else if (menu_info->comp_type && menu_info->app_type && - strcmp(menu_info->comp_type, "widgetapp") == 0 && - strcmp(menu_info->app_type, "webapp") == 0) { - loader_id = PAD_LOADER_ID_DIRECT; + !strcmp(menu_info->comp_type, "widgetapp") && + !strcmp(menu_info->app_type, "webapp")) { + request->loader_id = PAD_LOADER_ID_DIRECT; } else { - loader_id = __get_loader_id(kb); - if (loader_id <= PAD_LOADER_ID_STATIC) { - cpc = __find_available_slot(menu_info->hwacc, + request->loader_id = __get_loader_id(request->kb); + if (request->loader_id <= PAD_LOADER_ID_STATIC) { + request->cpc = __find_available_slot(menu_info->hwacc, menu_info->app_type, - menu_info->loader_name, &org_cpc); + menu_info->loader_name, + &request->org_cpc); } else { type = LAUNCHPAD_LOADER_TYPE_DYNAMIC; - cpc = __find_slot(type, loader_id); - if (cpc && !cpc->prepared) - cpc = NULL; + request->cpc = __find_slot(type, request->loader_id); + if (request->cpc && !request->cpc->prepared) + request->cpc = NULL; } } - _modify_bundle(kb, cr.pid, menu_info, pkt->cmd); + _modify_bundle(request->kb, request->caller_pid, request->menu_info, + request->cmd); if (menu_info->appid == NULL) { - _E("unable to get appid from menu_info"); - __send_result_to_caller(clifd, -EINVAL); - clifd = -1; - goto end; + _E("Unable to get appid from app info"); + return -1; } - PERF("get package information & modify bundle done"); + PERF("Getting package information & modifying bundle done"); + return 0; +} - if (loader_id == PAD_LOADER_ID_DIRECT || cpc == NULL) { - _W("Launch directly %d %p", loader_id, cpc); - pid = __launch_directly(menu_info->appid, app_path, clifd, kb, - menu_info, NULL); - if (org_cpc && (!org_cpc->app_check || org_cpc->app_exists) && - org_cpc->pid == CANDIDATE_NONE && - !__sequencer_slot_exist(org_cpc)) { - if (org_cpc->timer > 0) { - g_source_remove(org_cpc->timer); - org_cpc->timer = 0; - } +static void __launch_request_complete(request_h request) +{ + _memory_monitor_reset_timer(); + __request_send_result(request, request->pid); - __update_slot_state(org_cpc, METHOD_REQUEST, true); - __set_timer(org_cpc); + if (request->pid > 0) { + _dbus_send_app_launch_signal(request->pid, + request->menu_info->appid); + g_hash_table_insert(__pid_table, GINT_TO_POINTER(request->pid), + strdup(request->menu_info->appid)); + _log_print("[LAUNCH]", "pid(%7d) | appid(%s)", + request->pid, request->menu_info->appid); + } +} + +static gboolean __handle_direct_launch(gpointer user_data) +{ + request_h request = user_data; + + if (request->org_cpc && (!request->org_cpc->app_check || + request->org_cpc->app_exists) && + request->org_cpc->pid == CANDIDATE_NONE && + !__sequencer_slot_exist(request->org_cpc)) { + if (request->org_cpc->timer > 0) { + g_source_remove(request->org_cpc->timer); + request->org_cpc->timer = 0; } - } else { - _W("Launch %d type process", cpc->type); - pid = __send_launchpad_loader(cpc, pkt, app_path, clifd); + + __update_slot_state(request->org_cpc, METHOD_REQUEST, true); + __set_timer(request->org_cpc); } - _memory_monitor_reset_timer(); - __send_result_to_caller(clifd, pid); - clifd = -1; -end: - if (clifd != -1) - close(clifd); + __launch_request_complete(request); + __request_destroy(request); + return G_SOURCE_REMOVE; +} - if (pid > 0) { - _dbus_send_app_launch_signal(pid, menu_info->appid); - g_hash_table_insert(__pid_table, GINT_TO_POINTER(pid), - strdup(menu_info->appid)); - _log_print("[LAUNCH]", "pid(%7d) | appid(%s)", - pid, menu_info->appid); +static bool __fork_processing_cb(void *user_data) +{ + request_h request = user_data; + + if (bundle_get_type(request->kb, AUL_K_SDK) != BUNDLE_TYPE_NONE) + _debug_init(); + + _W("appid: %s", request->menu_info->appid); + request->pid = __launch_directly(request->menu_info->appid, + request->app_path, request->clifd, request->kb, + request->menu_info, NULL); + if (request->pid == -1) { + _E("Failed to create a child process. appid(%s)", + request->menu_info->appid); + } + + __request_send_result(request, request->pid); + _W("appid: %s, pid: %d", request->menu_info->appid, request->pid); + g_idle_add(__handle_direct_launch, request); + return false; +} + +static int __launch_request_do(request_h request) +{ + int ret; + + if (request->loader_id == PAD_LOADER_ID_DIRECT || + request->cpc == NULL) { + ret = _worker_add_job(__forker, __fork_processing_cb, request); + if (ret != 0) + return -1; + + return 1; } - if (menu_info != NULL) - _appinfo_free(menu_info); + _W("Launch %d type process. appid(%s)", + request->cpc->type, request->menu_info->appid); + request->pid = __send_launchpad_loader(request->cpc, request->pkt, + request->app_path, request->clifd); + return 0; +} - if (kb != NULL) - bundle_free(kb); - if (pkt != NULL) - free(pkt); +static int __launch_request_handler(request_h request) +{ + int ret; + traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "LAUNCHPAD:LAUNCH"); + INIT_PERF(kb); + PERF("Packet processing start"); + + ret = __launch_request_prepare(request); + if (ret < 0) { + traceEnd(TTRACE_TAG_APPLICATION_MANAGER); + __request_send_result(request, ret); + return ret; + } + + ret = __launch_request_do(request); + if (ret == 1) { + traceEnd(TTRACE_TAG_APPLICATION_MANAGER); + return ret; + } + + if (ret < 0) + request->pid = ret; + + __launch_request_complete(request); traceEnd(TTRACE_TAG_APPLICATION_MANAGER); + _D("[PAD_CMD_LAUNCH] appid: %s, result: %d", + request->menu_info->appid, request->pid); + return 0; +} +static request_handler __request_handlers[] = { + [PAD_CMD_VISIBILITY] = __visibility_request_handler, + [PAD_CMD_ADD_LOADER] = __add_loader_request_handler, + [PAD_CMD_REMOVE_LOADER] = __remove_loader_request_handler, + [PAD_CMD_MAKE_DEFAULT_SLOTS] = __make_default_slots_request_handler, + [PAD_CMD_PREPARE_APP_DEFINED_LOADER] = + __prepare_app_defined_loader_request_handler, + [PAD_CMD_DEMAND] = __demand_request_handler, + [PAD_CMD_PING] = __ping_request_handler, + [PAD_CMD_UPDATE_APP_TYPE] = __update_app_type_request_handler, + [PAD_CMD_CONNECT] = __connect_request_handler, + [PAD_CMD_LAUNCH] = __launch_request_handler, +}; + +static bool __handle_launch_event(int fd, io_condition_e cond, void *data) +{ + request_t *request = NULL; + int ret; + + if (cond & (IO_ERR | IO_HUP | IO_NVAL)) { + _E("fd(%d), condition(%d)", fd, cond); + g_idle_add(__launchpad_recovery_cb, __launchpad_channel); + __launchpad_channel = NULL; + return false; + } + + ret = __request_create(fd, &request); + if (ret != 0) + return true; + + _W("cmd(%d), caller(%d)", request->cmd, request->caller_pid); + if (request->caller_uid >= REGULAR_UID_MIN) { + if (__check_caller_by_pid(request->caller_pid) < 0) { + _E("Permission denied. pid(%d)", request->caller_pid); + __request_send_result(request, -EPERM); + __request_destroy(request); + return true; + } + } + + if (request->cmd < 0 || request->cmd > ARRAY_SIZE(__request_handlers) || + __request_handlers[request->cmd] == NULL) { + _E("Unknown command: %d", request->cmd); + __request_send_result(request, -EINVAL); + return true; + } + + ret = __request_handlers[request->cmd](request); + if (ret == 1) { + _W("Request is forwarded to the worker thread"); + return true; + } + + __request_destroy(request); return true; } @@ -3232,7 +3485,11 @@ static int __before_loop(int argc, char **argv) return -1; } - ret = _worker_init(); + ret = _worker_create("cleaner+", &__cleaner); + if (ret < 0) + return ret; + + ret = _worker_create("forker+", &__forker); if (ret < 0) return ret; @@ -3251,7 +3508,8 @@ static void __after_loop(void) _log_fini(); _memory_monitor_fini(); __unregister_vconf_events(); - _worker_fini(); + _worker_destroy(__forker); + _worker_destroy(__cleaner); if (__pid_table) g_hash_table_destroy(__pid_table); diff --git a/src/launchpad-process-pool/src/launchpad_worker.c b/src/launchpad-process-pool/src/launchpad_worker.c index 3f600d7..019e4a2 100644 --- a/src/launchpad-process-pool/src/launchpad_worker.c +++ b/src/launchpad-process-pool/src/launchpad_worker.c @@ -35,19 +35,18 @@ struct job_s { }; struct worker_s { + char *name; GThread *thread; GMutex mutex; GCond cond; GQueue *queue; }; -static struct worker_s __worker; - -int _worker_add_job(worker_job_cb callback, void *user_data) +int _worker_add_job(worker_h worker, worker_job_cb callback, void *user_data) { struct job_s *job; - if (!callback) { + if (!worker || !callback) { _E("Invalid parameter"); return -EINVAL; } @@ -61,10 +60,10 @@ int _worker_add_job(worker_job_cb callback, void *user_data) 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); + g_mutex_lock(&worker->mutex); + g_queue_push_tail(worker->queue, job); + g_cond_signal(&worker->cond); + g_mutex_unlock(&worker->mutex); return 0; } @@ -101,7 +100,7 @@ static gpointer __worker_thread_cb(gpointer data) struct job_s *job; bool done = false; - __set_comm("worker"); + __set_comm(worker->name); do { g_mutex_lock(&worker->mutex); if (g_queue_is_empty(worker->queue)) @@ -116,25 +115,46 @@ static gpointer __worker_thread_cb(gpointer data) return NULL; } -int _worker_init(void) +int _worker_create(const char *name, worker_h *worker) { - _W("WORKER_INIT"); + struct worker_s *handle; + + if (name == NULL || worker == NULL) { + _E("Invalid parameter"); + return -EINVAL; + } + + handle = calloc(1, sizeof(struct worker_s)); + if (handle == NULL) { + _E("calloc() is failed"); + return -ENOMEM; + } + + g_mutex_init(&handle->mutex); + g_cond_init(&handle->cond); - g_mutex_init(&__worker.mutex); - g_cond_init(&__worker.cond); + handle->name = strdup(name); + if (!handle->name) { + _E("strdup() is failed"); + _worker_destroy(handle); + return -ENOMEM; + } - __worker.queue = g_queue_new(); - if (!__worker.queue) { + handle->queue = g_queue_new(); + if (!handle->queue) { _E("g_queue_new() is failed"); + _worker_destroy(handle); return -ENOMEM; } - __worker.thread = g_thread_new("worker", __worker_thread_cb, &__worker); - if (!__worker.thread) { + handle->thread = g_thread_new(name, __worker_thread_cb, handle); + if (!handle->thread) { _E("g_thread_new() is failed"); + _worker_destroy(handle); return -ENOMEM; } + *worker = handle; return 0; } @@ -144,18 +164,23 @@ static bool __worker_done_cb(void *user_data) return true; } -void _worker_fini(void) +void _worker_destroy(worker_h worker) { - _W("WORKER_FINI"); + if (worker == NULL) + return; - if (__worker.thread) { - _worker_add_job(__worker_done_cb, NULL); - g_thread_join(__worker.thread); + if (worker->thread) { + _worker_add_job(worker, __worker_done_cb, NULL); + g_thread_join(worker->thread); } - if (__worker.queue) - g_queue_free_full(__worker.queue, (GDestroyNotify)free); + if (worker->queue) + g_queue_free_full(worker->queue, (GDestroyNotify)free); + + if (worker->name) + free(worker->name); - g_cond_clear(&__worker.cond); - g_mutex_clear(&__worker.mutex); + g_cond_clear(&worker->cond); + g_mutex_clear(&worker->mutex); + free(worker); } -- 2.7.4 From dd012c262f60b26e2ff75d4187b0e34d0496cd36 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 14 Nov 2022 05:40:02 +0000 Subject: [PATCH 16/16] Release version 0.20.0 Changes: - Create a child process in the worker thread Change-Id: I411e8cc77ff26bb7f733c0d0c974312eb2acba57 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 574dbae..fb74f55 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.19.3 +Version: 0.20.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4