From 3943e0952e8b0c6846bca32d5926a058640770f6 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 13 May 2020 16:28:49 +0900 Subject: [PATCH 01/16] Print PSS usage after loading preload libraries Change-Id: I48fb1ee0266ed3624302a8e0f4cfcc7e06c37c40 Signed-off-by: Hwankyu Jhun --- src/{launchpad => common}/inc/launchpad_proc.h | 0 src/{launchpad => common}/src/launchpad_proc.c | 2 -- src/loader/src/launchpad_loader.c | 8 +++++++- 3 files changed, 7 insertions(+), 3 deletions(-) rename src/{launchpad => common}/inc/launchpad_proc.h (100%) rename src/{launchpad => common}/src/launchpad_proc.c (97%) diff --git a/src/launchpad/inc/launchpad_proc.h b/src/common/inc/launchpad_proc.h similarity index 100% rename from src/launchpad/inc/launchpad_proc.h rename to src/common/inc/launchpad_proc.h diff --git a/src/launchpad/src/launchpad_proc.c b/src/common/src/launchpad_proc.c similarity index 97% rename from src/launchpad/src/launchpad_proc.c rename to src/common/src/launchpad_proc.c index daad003..e491cff 100644 --- a/src/launchpad/src/launchpad_proc.c +++ b/src/common/src/launchpad_proc.c @@ -107,7 +107,6 @@ int _proc_get_mem_used_ratio(unsigned int *mem_used_ratio) used = mem_total - mem_available; used_ratio = used * 100 / mem_total; - _I("memory used ratio: %u %%", used_ratio); *mem_used_ratio = used_ratio; @@ -141,7 +140,6 @@ int _proc_get_mem_pss(int pid, unsigned int *mem_pss) } *mem_pss = total_pss; - _I("[%d] PSS: %u kB", pid, total_pss); return 0; } diff --git a/src/loader/src/launchpad_loader.c b/src/loader/src/launchpad_loader.c index fee50e6..b67484d 100644 --- a/src/loader/src/launchpad_loader.c +++ b/src/loader/src/launchpad_loader.c @@ -30,6 +30,7 @@ #include "launchpad_common.h" #include "launchpad_types.h" +#include "launchpad_proc.h" #include "launchpad.h" #include "key.h" @@ -150,6 +151,7 @@ static void __preload_lib(bundle *b) int i; int len = 0; const char **so_array; + unsigned int mem_pss = 0; if (!b) return; @@ -159,6 +161,8 @@ static void __preload_lib(bundle *b) if (!so_array) return; + _proc_get_mem_pss(getpid(), &mem_pss); + _W("PSS: %u kB", mem_pss); for (i = 0; i < len; i++) { if (!so_array[i]) { _E("so_array[%d] is nullptr", i); @@ -174,7 +178,9 @@ static void __preload_lib(bundle *b) _E("failed to load: %s, err: %s", so_array[i], dlerror()); } else { - _D("preload %s# - handle : %p", so_array[i], handle); + _proc_get_mem_pss(getpid(), &mem_pss); + _W("preload %s# - handle : %p, PSS: %u kB", + so_array[i], handle, mem_pss); } } } -- 2.7.4 From 2c51231ff4b4a833fb477b2b7eb12760b304e14f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 14 May 2020 11:17:06 +0900 Subject: [PATCH 02/16] Release version 0.14.3 Changes: - Print PSS usage after loading preload libraries Change-Id: I8ce772cc17fd0ccfa9f0dc3c25a1d6379f5fa5ef 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 ea794d5..40746cc 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.14.2 +Version: 0.14.3 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 0d54ed8af68d2f22c1acb057125f3fc3fd4920c0 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 15 May 2020 16:47:46 +0900 Subject: [PATCH 03/16] Check loader id validation Change-Id: I74f713afdd4ba9c367f4b4a7f9c0a9c2871e3c6c Signed-off-by: Hwankyu Jhun --- src/parser/launchpad_parser_plugin.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/parser/launchpad_parser_plugin.cc b/src/parser/launchpad_parser_plugin.cc index 95deccb..9abaeb2 100644 --- a/src/parser/launchpad_parser_plugin.cc +++ b/src/parser/launchpad_parser_plugin.cc @@ -62,6 +62,13 @@ int LaunchpadParser::WriteToFile(string pkgid) { } bool LaunchpadParser::IsValidId(string loader_id, string pkgid) { + std::string needle("../"); + std::size_t found = loader_id.find(needle); + if (found != std::string::npos) { + _E("Invalid loader_id(%s)", loader_id.c_str()); + return false; + } + ifstream in_file(GetFilePath(loader_id).c_str()); if (!in_file.good()) return true; -- 2.7.4 From e0be4a070cf9a6017db92a5bacdab9871bd38a46 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 15 May 2020 18:39:34 +0900 Subject: [PATCH 04/16] Release version 0.14.4 Changes: - Check loader id validation Change-Id: Ibc5a4184c79c42f3148f7f57627b8ab4d0f6c826 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 40746cc..895aa65 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.14.3 +Version: 0.14.4 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From c42584e660723713aa6896582b7dc37891f9c060 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 18 May 2020 12:38:26 +0900 Subject: [PATCH 05/16] Fix ASAN build issue Change-Id: Ife64bd725926ffac0b1cb4581b1b917ca3dd93bc Signed-off-by: Hwankyu Jhun --- src/hydra/src/launchpad_hydra.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/hydra/src/launchpad_hydra.c b/src/hydra/src/launchpad_hydra.c index f2c7779..3b94555 100644 --- a/src/hydra/src/launchpad_hydra.c +++ b/src/hydra/src/launchpad_hydra.c @@ -252,37 +252,35 @@ static int __handle_sigchld_event(sd_event_source *s, return 0; } -static int __create_client_socket(const char *path) +static int __create_client_socket(int type, int id) { struct sockaddr_un addr = { 0, }; int retry = CONNECT_RETRY_COUNT; int fd; - if (sizeof(addr.sun_path) <= strlen(path)) { - _E("lenght of path is too long"); - return -1; - } - fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); if (fd < 0) { - _E("Failed to create socket(%s). errno(%d)", path, errno); + _E("Failed to create socket(%d:%d). errno(%d)", + type, id, errno); return -1; } addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, path, sizeof(addr.sun_path)); - addr.sun_path[sizeof(addr.sun_path) - 1] = '\0'; + snprintf(addr.sun_path, sizeof(addr.sun_path), + "%s/daemons/%d/%s%d-%d", + SOCKET_PATH, getuid(), HYDRA_LOADER_SOCKET_NAME, + type, id); while (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { if (errno != ETIMEDOUT || retry <= 0) { _E("Failed to connect socket(%s). errno(%d)", - path, errno); + addr.sun_path, errno); close(fd); return -1; } usleep(CONNECT_RETRY_TIME); retry--; - _W("Retry(%d) to connect %s", retry, path); + _W("Retry(%d) to connect %s", retry, addr.sun_path); } return fd; @@ -290,7 +288,6 @@ static int __create_client_socket(const char *path) int __connect_to_launchpad_hydra(int type, int id) { - char path[PATH_MAX]; int fd; int send_ret; pid_t client_pid; @@ -298,10 +295,7 @@ int __connect_to_launchpad_hydra(int type, int id) _D("[hydra] enter, type: %d", type); - snprintf(path, sizeof(path), "%s/daemons/%d/%s%d-%d", - SOCKET_PATH, getuid(), HYDRA_LOADER_SOCKET_NAME, - type, id); - fd = __create_client_socket(path); + fd = __create_client_socket(type, id); if (fd < 0) return -1; -- 2.7.4 From 6d04a1ac515e6efd3db6f0fcf91d4cdd56826730 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 18 May 2020 13:45:32 +0900 Subject: [PATCH 06/16] Release version 0.14.5 Changes: - Fix ASAN build issue Change-Id: Id141f6e85ed86de829437f5a83b678ee70589495 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 895aa65..e39fa09 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.14.4 +Version: 0.14.5 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From ce958985b913488dc10b14fd9f9ce9be1e12c596 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 19 May 2020 08:29:07 +0900 Subject: [PATCH 07/16] Change project name of launchpad library Change-Id: I20640bb7e230e823388548748ebbbe4279dc9798 Signed-off-by: Hwankyu Jhun --- src/CMakeLists.txt | 4 ++-- src/lib/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 352038e..de3c1c6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,5 +7,5 @@ ADD_SUBDIRECTORY(app-defined-loader) ADD_SUBDIRECTORY(hydra) ADD_SUBDIRECTORY(parser) -ADD_DEPENDENCIES(launchpad-loader launchpad-lib) -ADD_DEPENDENCIES(app-defined-loader launchpad-lib) +ADD_DEPENDENCIES(launchpad-loader liblaunchpad) +ADD_DEPENDENCIES(app-defined-loader liblaunchpad) diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index d5a2ecd..1d42ce0 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,5 +1,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8) -PROJECT(launchpad-lib C) +PROJECT(liblaunchpad C) SET(LAUNCHPAD_LIB "launchpad") INCLUDE(FindPkgConfig) -- 2.7.4 From 3e9b00eb14490eb8ef40dd3942cf36555edca09c Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 18 May 2020 20:50:19 +0900 Subject: [PATCH 08/16] Fix loader management If the cpu check count has exceeded 10 times, the loader context is queuing and the next loader context will be checked. The platform developer can adjust the maximum CPU check count by modifying launchpad.conf file. Change-Id: I0e0917cff2b88cbf6d1a6ea2b0e2fedb983d9ebf Signed-off-by: Hwankyu Jhun --- src/launchpad/conf/launchpad.conf.in | 3 +++ src/launchpad/inc/launchpad_config.h | 1 + src/launchpad/src/launchpad.c | 30 ++++++++++++++++++++++++++---- src/launchpad/src/launchpad_config.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/launchpad/conf/launchpad.conf.in b/src/launchpad/conf/launchpad.conf.in index 3615188..6e7e6b2 100644 --- a/src/launchpad/conf/launchpad.conf.in +++ b/src/launchpad/conf/launchpad.conf.in @@ -7,3 +7,6 @@ NormalValue=1 [MemoryMonitor] Threshold=80 Interval=5000 + +[CpuChecker] +MaxCount=10 diff --git a/src/launchpad/inc/launchpad_config.h b/src/launchpad/inc/launchpad_config.h index 1d2ee1e..328f839 100644 --- a/src/launchpad/inc/launchpad_config.h +++ b/src/launchpad/inc/launchpad_config.h @@ -24,6 +24,7 @@ typedef enum { CONFIG_TYPE_MEMORY_STATUS_NORMAL_VALUE, CONFIG_TYPE_MEMORY_MONITOR_THRESHOLD, CONFIG_TYPE_MEMORY_MONITOR_INTERVAL, + CONFIG_TYPE_CPU_CHECKER_MAX_COUNT, } config_type_e; const char *_config_get_string_value(config_type_e type); diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c index da7042b..de35efb 100644 --- a/src/launchpad/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -122,6 +122,7 @@ typedef struct { io_channel_h hydra_channel; unsigned int score; unsigned int pss; + int cpu_check_count; } candidate_process_context_t; typedef struct { @@ -167,6 +168,7 @@ static int __memory_status_normal; static sequencer __sequencer; static int MEMORY_STATUS_LOW; static int MEMORY_STATUS_NORMAL; +static int MAX_CPU_CHECK_COUNT; static io_channel_h __logger_channel; static io_channel_h __label_monitor_channel; @@ -231,6 +233,7 @@ static gboolean __handle_queuing_slots(gpointer data) _get_cpu_idle(&total, &idle); cpc->cpu_idle_time = idle; cpc->cpu_total_time = total; + cpc->cpu_check_count = 0; __sequencer.idle_checker = g_timeout_add(CPU_CHECKER_TIMEOUT, __handle_idle_checker, cpc); @@ -1603,14 +1606,16 @@ static gboolean __handle_idle_checker(gpointer data) cpc = (candidate_process_context_t *)data; if (cpc->app_check && !cpc->app_exists) { - _W("The application is not installed. Type(%d)", cpc->type); + _W("The application is not installed. loader(%s:%d)", + cpc->loader_name, cpc->type); __sequencer.idle_checker = 0; __sequencer.running_cpc = NULL; return G_SOURCE_REMOVE; } if (cpc->state != CANDIDATE_PROCESS_STATE_RUNNING) { - _W("Slot state is not running. Type(%d)", cpc->type); + _W("Slot state is not running. loader(%s:%d)", + cpc->loader_name, cpc->type); __sequencer.idle_checker = 0; __sequencer.running_cpc = NULL; return G_SOURCE_REMOVE; @@ -1621,7 +1626,7 @@ static gboolean __handle_idle_checker(gpointer data) total++; per = (idle - cpc->cpu_idle_time) * 100 / (total - cpc->cpu_total_time); - _D("[CPU] Idle : %d / type : %d", per, cpc->type); + _D("[CPU] Idle : %d / loader(%s:%d)", per, cpc->loader_name, cpc->type); if (per >= cpc->threshold) { __update_threshold(cpc, -0.02f * (per - cpc->threshold)); @@ -1636,6 +1641,18 @@ static gboolean __handle_idle_checker(gpointer data) cpc->cpu_total_time = total; __update_threshold(cpc, 0.05f); + cpc->cpu_check_count++; + if (cpc->cpu_check_count == MAX_CPU_CHECK_COUNT) { + _W("CPU check count has exceeded %d times. loader(%s:%d)", + cpc->cpu_check_count, + cpc->loader_name, + cpc->type); + __sequencer.idle_checker = 0; + __sequencer.running_cpc = NULL; + __sequencer_add_slot(cpc); + return G_SOURCE_REMOVE; + } + return G_SOURCE_CONTINUE; } @@ -2298,6 +2315,7 @@ static candidate_process_context_t *__create_slot(int type, int loader_id, cpc->app_check = app_check; cpc->score = WIN_SCORE; cpc->pss = 0; + cpc->cpu_check_count = 0; if ((cpc->deactivation_method & METHOD_OUT_OF_MEMORY) && __is_low_memory()) @@ -2305,6 +2323,8 @@ static candidate_process_context_t *__create_slot(int type, int loader_id, else cpc->state = CANDIDATE_PROCESS_STATE_RUNNING; + _W("loader(%s), type(%d), state(%d)", + cpc->loader_name, cpc->type, cpc->state); return cpc; } @@ -2873,12 +2893,12 @@ static int __memory_monitor_cb(bool low_memory, void *user_data) { candidate_process_context_t *cpc; - _W("low memory(%s)", low_memory ? "true" : "false"); cpc = __get_running_slot(false); if (!cpc && low_memory) return -1; if (low_memory) { + _W("Low memory"); __update_slots_pss(); candidate_slot_list = g_list_sort(candidate_slot_list, @@ -2936,6 +2956,8 @@ static int __before_loop(int argc, char **argv) _inotify_init(); + MAX_CPU_CHECK_COUNT = _config_get_int_value( + CONFIG_TYPE_CPU_CHECKER_MAX_COUNT); __add_default_slots(); launcher_info_list = _launcher_info_load(LAUNCHER_INFO_PATH); diff --git a/src/launchpad/src/launchpad_config.c b/src/launchpad/src/launchpad_config.c index 5b517b0..0838dd7 100644 --- a/src/launchpad/src/launchpad_config.c +++ b/src/launchpad/src/launchpad_config.c @@ -40,6 +40,9 @@ #define KEY_MEMORY_MONITOR_THRESHOLD "Threshold" #define KEY_MEMORY_MONITOR_INTERVAL "Interval" +#define TAG_CPU_CHECKER "CpuChecker" +#define KEY_CPU_CHECKER_MAX_COUNT "MaxCount" + struct memory_status_s { char *low_key; int low_value; @@ -52,8 +55,13 @@ struct memory_monitor_s { int interval; }; +struct cpu_checker_s { + int max_count; +}; + static struct memory_status_s __memory_status; static struct memory_monitor_s __memory_monitor; +static struct cpu_checker_s __cpu_checker; const char *_config_get_string_value(config_type_e type) { @@ -92,6 +100,9 @@ int _config_get_int_value(config_type_e type) case CONFIG_TYPE_MEMORY_MONITOR_INTERVAL: value = __memory_monitor.interval; break; + case CONFIG_TYPE_CPU_CHECKER_MAX_COUNT: + value = __cpu_checker.max_count; + break; default: _E("Unknown type"); value = INT_MIN; @@ -208,6 +219,28 @@ static void __memory_monitor_set(dictionary *d) __memory_monitor.interval); } +static void __cpu_checker_init(void) +{ + __cpu_checker.max_count = 10; +} + +static void __cpu_checker_fini(void) +{ + __cpu_checker.max_count = 0; +} + +static void __cpu_checker_set(dictionary *d) +{ + int ret; + + ret = __get_int_value(d, TAG_CPU_CHECKER, + KEY_CPU_CHECKER_MAX_COUNT); + if (ret != INT_MAX) + __cpu_checker.max_count = ret; + + _W("CPU Checker MaxCount(%d)", __cpu_checker.max_count); +} + int _config_init(void) { dictionary *d; @@ -217,6 +250,7 @@ int _config_init(void) __memory_status_init(); __memory_monitor_init(); + __cpu_checker_init(); ret = access(PATH_LAUNCHPAD_CONF, F_OK); if (ret != 0) { @@ -232,6 +266,7 @@ int _config_init(void) __memory_status_set(d); __memory_monitor_set(d); + __cpu_checker_set(d); iniparser_freedict(d); @@ -242,6 +277,7 @@ void _config_fini(void) { _D("config fini"); + __cpu_checker_fini(); __memory_monitor_fini(); __memory_status_fini(); } -- 2.7.4 From 09cf7a499cc99a0e8065c28fd1338aa44ab58adf Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 18 May 2020 12:09:41 +0900 Subject: [PATCH 09/16] Support plugin module Before dropping capabilities of child process, the plugin module is called to prepare changing the application. Change-Id: I18600b383a3c7a87e8f0df012b7fda219bccbd6f Signed-off-by: Hwankyu Jhun --- src/common/inc/launchpad_plugin.h | 24 +++++++++++++++ src/common/src/launchpad_plugin.c | 61 +++++++++++++++++++++++++++++++++++++++ src/launchpad/CMakeLists.txt | 4 +-- src/launchpad/src/launchpad.c | 7 +++++ src/lib/src/launchpad_lib.c | 7 +++++ 5 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 src/common/inc/launchpad_plugin.h create mode 100644 src/common/src/launchpad_plugin.c diff --git a/src/common/inc/launchpad_plugin.h b/src/common/inc/launchpad_plugin.h new file mode 100644 index 0000000..f2cf987 --- /dev/null +++ b/src/common/inc/launchpad_plugin.h @@ -0,0 +1,24 @@ +/* + * 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_PLUGIN_H__ +#define __LAUNCHPAD_PLUGIN_H__ + +#include + +int _launchpad_plugin_prepare_app(const char *app_id, bundle *kb); + +#endif /* __LAUNCHPAD_PLUGIN_H__ */ diff --git a/src/common/src/launchpad_plugin.c b/src/common/src/launchpad_plugin.c new file mode 100644 index 0000000..d54d4ec --- /dev/null +++ b/src/common/src/launchpad_plugin.c @@ -0,0 +1,61 @@ +/* + * 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 "launchpad_plugin.h" +#include "log_private.h" + +#define PATH_LAUNCHPAD_PLUGIN "/usr/share/aul/plugin/liblaunchpad-plugin.so" +#define TAG_LAUNCHPAD_PLUGIN_PREPARE_APP "LAUNCHPAD_PLUGIN_PREPARE_APP" + +int _launchpad_plugin_prepare_app(const char *app_id, bundle *kb) +{ + void *handle; + int (*prepare_app)(const char *, bundle *); + int ret; + + ret = access(PATH_LAUNCHPAD_PLUGIN, F_OK); + if (ret != 0) { + _D("plugin module does not exist. errno(%d)", errno); + return 0; + } + + handle = dlopen(PATH_LAUNCHPAD_PLUGIN, RTLD_LAZY | RTLD_LOCAL); + if (!handle) { + _W("Failed to open plugin so. error(%s)", dlerror()); + return 0; + } + + prepare_app = dlsym(handle, TAG_LAUNCHPAD_PLUGIN_PREPARE_APP); + if (!prepare_app) { + _W("Failed to load %s", TAG_LAUNCHPAD_PLUGIN_PREPARE_APP); + return 0; + } + + _W("LAUNCHPAD_PLUGIN_PREPARE_APP ++"); + ret = prepare_app(app_id, kb); + _W("LAUNCHPAD_PLUGIN_PREPARE_APP --"); + if (ret != 0) + return -1; + + return 0; +} diff --git a/src/launchpad/CMakeLists.txt b/src/launchpad/CMakeLists.txt index a51f395..39ce5c8 100644 --- a/src/launchpad/CMakeLists.txt +++ b/src/launchpad/CMakeLists.txt @@ -53,9 +53,9 @@ SET(LAUNCHPAD_PROCESS_POOL_SOURCE_FILES ADD_EXECUTABLE(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_SOURCE_FILES}) IF(_TIZEN_FEATURE_PRELINK) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_PKGS_LDFLAGS} "-lm") +TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_PKGS_LDFLAGS} "-lm -ldl") ELSE(_TIZEN_FEATURE_PRELINK) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_PKGS_LDFLAGS} "-pie -lm") +TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_PKGS_LDFLAGS} "-pie -lm -ldl") ENDIF(_TIZEN_FEATURE_PRELINK) SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_pool}) diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c index de35efb..9c7239d 100644 --- a/src/launchpad/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -47,6 +47,7 @@ #include "launchpad_inotify.h" #include "launchpad_io_channel.h" #include "launchpad_memory_monitor.h" +#include "launchpad_plugin.h" #include "launchpad_proc.h" #include "launchpad_signal.h" #include "launchpad_types.h" @@ -1211,6 +1212,12 @@ static int __prepare_exec(const char *appid, const char *app_path, /* TODO : should be add to check permission in the kernel*/ setsid(); + ret = _launchpad_plugin_prepare_app(appid, kb); + if (ret < 0) { + _E("_launchpad_plugin_prepare_app() is failed. error(%d)", ret); + return PAD_ERR_FAILED; + } + ret = _enable_external_pkg(kb, menu_info->pkgid, menu_info->global ? GLOBAL_USER : getuid()); if (ret < 0) diff --git a/src/lib/src/launchpad_lib.c b/src/lib/src/launchpad_lib.c index 45a59f9..d9d4434 100644 --- a/src/lib/src/launchpad_lib.c +++ b/src/lib/src/launchpad_lib.c @@ -35,6 +35,7 @@ #include "launchpad.h" #include "launchpad_common.h" +#include "launchpad_plugin.h" #include "launchpad_types.h" #include "preexec.h" @@ -71,6 +72,12 @@ 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 71d30b08e6e735d3135173ea3ee69a96592b484c Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 19 May 2020 09:39:37 +0900 Subject: [PATCH 10/16] Fix resource leak Change-Id: If9de9ee89410b7cf27162be3d878d9035a30653b Signed-off-by: Hwankyu Jhun --- src/common/src/launchpad_plugin.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/src/launchpad_plugin.c b/src/common/src/launchpad_plugin.c index d54d4ec..912c19d 100644 --- a/src/common/src/launchpad_plugin.c +++ b/src/common/src/launchpad_plugin.c @@ -48,6 +48,7 @@ int _launchpad_plugin_prepare_app(const char *app_id, bundle *kb) prepare_app = dlsym(handle, TAG_LAUNCHPAD_PLUGIN_PREPARE_APP); if (!prepare_app) { _W("Failed to load %s", TAG_LAUNCHPAD_PLUGIN_PREPARE_APP); + dlclose(handle); return 0; } -- 2.7.4 From d1488f6d5ec4f7e86d6512323be1702dc3db7e66 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 19 May 2020 09:16:34 +0900 Subject: [PATCH 11/16] Release version 0.15.0 Changes: - Change project name of launchpad library - Fix loader management - Support plugin module - Fix resource leak Change-Id: I3245c3b75c6bc090c790809c5fd0f58826ffc0fb 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 e39fa09..9218b71 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.14.5 +Version: 0.15.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From e7a00d8d7119068198bf46b366ff9bd39ffd92b0 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 27 May 2020 20:13:15 +0900 Subject: [PATCH 12/16] Support ASAN debug mode Change-Id: I5ff27faf3ea93c478ff5fcb22845455787300dba Signed-off-by: Hwankyu Jhun --- packaging/default.debugger.in | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packaging/default.debugger.in b/packaging/default.debugger.in index b8e1651..90edf57 100644 --- a/packaging/default.debugger.in +++ b/packaging/default.debugger.in @@ -33,3 +33,10 @@ NAME GDB EXE /usr/bin/gdb APP_TYPE capp|c++app EXTRA_KEY __DLP_GDB_ARG__ + +[DEBUGGER] +NAME ASAN +APP_TYPE capp|c++app +EXTRA_ENV LD_PRELOAD +EXTRA_ENV ASAN_OPTIONS + -- 2.7.4 From e18746776e8bc13528057004218a457ee83b6e7e Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 29 May 2020 11:07:02 +0900 Subject: [PATCH 13/16] Set environment variables before executing the application To avoid thread-safe issue of setenv() / getenv(), the child process adds the environment variables to increase buffer size of __environ. Change-Id: Ia656b8c4cbc2fb5014a1fe399e78dfc9475dbf6d Signed-off-by: Hwankyu Jhun --- src/common/src/launchpad_common.c | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/common/src/launchpad_common.c b/src/common/src/launchpad_common.c index 26fce8b..8d2f943 100644 --- a/src/common/src/launchpad_common.c +++ b/src/common/src/launchpad_common.c @@ -40,6 +40,7 @@ #include #include #include +#include #include "launchpad_common.h" #include "launchpad_types.h" @@ -726,6 +727,44 @@ static void __set_execution_domain(void) } #endif /* TIZEN_FEATURE_SET_PERSONALITY_32 */ +static void __set_lang_env(void) +{ + char *lang; + + lang = vconf_get_str(VCONFKEY_LANGSET); + if (!lang) + lang = strdup("en_US.UTF-8"); + + setenv("LANGUAGE", lang, 1); + setenv("LANG", lang, 1); + setenv("LC_MESSAGES", lang, 1); + + free(lang); +} + +static void __set_region_env(void) +{ + char *region; + + region = vconf_get_str(VCONFKEY_REGIONFORMAT); + if (!region) + region = strdup("en_US.UTF-8"); + + setenv("LC_CTYPE", region, 1); + setenv("LC_NUMERIC", region, 1); + setenv("LC_TIME", region, 1); + setenv("LC_COLLATE", region, 1); + setenv("LC_MONETARY", region, 1); + setenv("LC_PAPER", region, 1); + setenv("LC_NAME", region, 1); + setenv("LC_ADDRESS", region, 1); + setenv("LC_TELEPHONE", region, 1); + setenv("LC_MEASUREMENT", region, 1); + setenv("LC_IDENTIFICATION", region, 1); + + free(region); +} + void _set_env(appinfo_t *menu_info, bundle *kb) { const char *str; @@ -763,6 +802,9 @@ void _set_env(appinfo_t *menu_info, bundle *kb) snprintf(buf, sizeof(buf), "%d", getpid()); setenv("AUL_PID", buf, 1); + __set_lang_env(); + __set_region_env(); + setenv("LC_ALL", "C", 1); #ifdef TIZEN_FEATURE_SET_PERSONALITY_32 __set_execution_domain(); #endif /* TIZEN_FEATURE_SET_PERSONALITY_32 */ -- 2.7.4 From 526cd30c05737e583a70cf4a66c3a8016245c297 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 29 May 2020 11:27:37 +0900 Subject: [PATCH 14/16] Release version 0.15.1 Changes: - Support ASAN debug mode - Set environment variables before executing the application Change-Id: Id6beb8ce372038a015e040cf5f0319bf7e71c4b3 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 9218b71..2d66809 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.0 +Version: 0.15.1 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 676c0c7a274270012a17a5ecf4bc073b50e3f697 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 1 Jun 2020 09:15:28 +0900 Subject: [PATCH 15/16] Remove getting vconf values This patch removes getting vconf values while launching an application. Sometimes, calling vconf API in the child process is failed by timed out error. If the environment variable is already set, the child process uses it to set. If it's not, the child process uses "en_US.UTF-8". Change-Id: I8b630a3c3874d00bd3120fb0f2c7e689d3574818 Signed-off-by: Hwankyu Jhun --- src/common/src/launchpad_common.c | 26 ++++++++++++-------------- src/launchpad/src/launchpad.c | 38 +++++++++++++++++++++++++++++++++++--- src/lib/src/launchpad_lib.c | 37 ++++++++++++++++++++++++++++++++----- 3 files changed, 79 insertions(+), 22 deletions(-) diff --git a/src/common/src/launchpad_common.c b/src/common/src/launchpad_common.c index 8d2f943..281a6fc 100644 --- a/src/common/src/launchpad_common.c +++ b/src/common/src/launchpad_common.c @@ -729,28 +729,28 @@ static void __set_execution_domain(void) static void __set_lang_env(void) { - char *lang; + const char *lang; - lang = vconf_get_str(VCONFKEY_LANGSET); - if (!lang) - lang = strdup("en_US.UTF-8"); + lang = getenv("LANG"); + if (!lang) { + lang = "en_US.UTF-8"; + setenv("LANG", lang, 1); + } setenv("LANGUAGE", lang, 1); - setenv("LANG", lang, 1); setenv("LC_MESSAGES", lang, 1); - - free(lang); } static void __set_region_env(void) { - char *region; + const char *region; - region = vconf_get_str(VCONFKEY_REGIONFORMAT); - if (!region) - region = strdup("en_US.UTF-8"); + region = getenv("LC_CTYPE"); + if (!region) { + region = "en_US.UTF-8"; + setenv("LC_CTYPE", region, 1); + } - setenv("LC_CTYPE", region, 1); setenv("LC_NUMERIC", region, 1); setenv("LC_TIME", region, 1); setenv("LC_COLLATE", region, 1); @@ -761,8 +761,6 @@ static void __set_region_env(void) setenv("LC_TELEPHONE", region, 1); setenv("LC_MEASUREMENT", region, 1); setenv("LC_IDENTIFICATION", region, 1); - - free(region); } void _set_env(appinfo_t *menu_info, bundle *kb) diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c index 9c7239d..217be80 100644 --- a/src/launchpad/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -2727,10 +2727,28 @@ static void __hw_acceleration_changed_cb(keynode_t *key, void *data) static void __update_lang(keynode_t *node, void *user_data) { - char *lang = vconf_keynode_get_str(node); + char *lang; - if (lang) - setenv("LANG", lang, 1); + lang = vconf_keynode_get_str(node); + if (!lang) { + _E("Failed to get language"); + return; + } + + setenv("LANG", lang, 1); +} + +static void __region_format_changed_cb(keynode_t *node, void *data) +{ + char *region; + + region = vconf_keynode_get_str(node); + if (!region) { + _E("Failed to get value"); + return; + } + + setenv("LC_CTYPE", region, 1); } static void __memory_status_low_changed_cb(keynode_t *node, void *data) @@ -2780,6 +2798,8 @@ static void __unregister_vconf_events(void) key = _config_get_string_value(type); vconf_ignore_key_changed(key, __memory_status_low_changed_cb); + vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, + __region_format_changed_cb); vconf_ignore_key_changed(VCONFKEY_LANGSET, __update_lang); vconf_ignore_key_changed(VCONFKEY_SETAPPL_APP_HW_ACCELERATION, @@ -2790,6 +2810,7 @@ static int __register_vconf_events(void) { int r; char *lang; + char *region; const char *key; config_type_e type; @@ -2814,6 +2835,17 @@ static int __register_vconf_events(void) if (r != VCONF_OK) _E("Failed to register callback for langset. err = %d", r); + region = vconf_get_str(VCONFKEY_REGIONFORMAT); + if (region) { + setenv("LC_CTYPE", region, 1); + free(region); + } + + r = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, + __region_format_changed_cb, NULL); + if (r != VCONF_OK) + _E("Failed to register callback for regionformat. err = %d", r); + type = CONFIG_TYPE_MEMORY_STATUS_LOW_KEY; key = _config_get_string_value(type); type = CONFIG_TYPE_MEMORY_STATUS_LOW_VALUE; diff --git a/src/lib/src/launchpad_lib.c b/src/lib/src/launchpad_lib.c index d9d4434..9852ecd 100644 --- a/src/lib/src/launchpad_lib.c +++ b/src/lib/src/launchpad_lib.c @@ -321,10 +321,28 @@ static void __receiver_cb(int fd) static void __update_lang(keynode_t *node, void *user_data) { - char *lang = vconf_keynode_get_str(node); + char *lang; - if (lang) - setenv("LANG", lang, 1); + lang = vconf_keynode_get_str(node); + if (!lang) { + _E("Failed to get language"); + return; + } + + setenv("LANG", lang, 1); +} + +static void __region_format_changed_cb(keynode_t *node, void *user_data) +{ + char *region; + + region = vconf_keynode_get_str(node); + if (!region) { + _E("Failed to get regionformat"); + return; + } + + setenv("LC_CTYPE", region, 1); } static int __before_loop(int argc, char **argv) @@ -332,6 +350,7 @@ static int __before_loop(int argc, char **argv) int client_fd; int ret = -1; bundle *extra = NULL; + int r; if (_verify_proc_caps() < 0) return -1; @@ -371,14 +390,22 @@ static int __before_loop(int argc, char **argv) __loader_adapter->add_fd(__loader_user_data, client_fd, __receiver_cb); - if (vconf_notify_key_changed(VCONFKEY_LANGSET, __update_lang, NULL) != 0) - _E("vconf_notify_key_changed failed"); + r = vconf_notify_key_changed(VCONFKEY_LANGSET, __update_lang, NULL); + if (r != VCONF_OK) + _E("Failed to register callback for langset. error(%d)", r); + + r = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, + __region_format_changed_cb, NULL); + if (r != VCONF_OK) + _E("Failed to register callback for regionformat. error(%d)", r); return ret; } static int __after_loop(void) { + vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, + __region_format_changed_cb); vconf_ignore_key_changed(VCONFKEY_LANGSET, __update_lang); if (__loader_callbacks->terminate) { -- 2.7.4 From 509943299ba695c03146473997d818f6c05c0fdd Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 1 Jun 2020 09:34:13 +0900 Subject: [PATCH 16/16] Release version 0.15.2 Changes: - Remove getting vconf values Change-Id: Ia5f07f8b63337fbecd989461d57649b85982ef3e 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 2d66809..7f2693a 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.1 +Version: 0.15.2 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4