From 706b9f5112c35fa3acf989b1756d7e6e868f11b9 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 11 Dec 2020 08:17:19 +0900 Subject: [PATCH 01/16] Check return value of vsnprintf() Change-Id: I6609f8bac28ec162e23867d01766a9857153e65b Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/src/launchpad_log.c | 7 ++++++- src/launchpad-process-pool/src/launchpad_logger.c | 7 ++++++- src/lib/common/src/launchpad_common.c | 19 ++++++++++++++----- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/launchpad-process-pool/src/launchpad_log.c b/src/launchpad-process-pool/src/launchpad_log.c index 6c28d01..fc5d698 100644 --- a/src/launchpad-process-pool/src/launchpad_log.c +++ b/src/launchpad-process-pool/src/launchpad_log.c @@ -33,13 +33,18 @@ int _log_print(const char *tag, const char *format, ...) { char formatted_buf[LAUNCHPAD_LOG_MAX_STRING_SIZE]; va_list ap; + int ret; if (!__logger) return 0; va_start(ap, format); - vsnprintf(formatted_buf, sizeof(formatted_buf), format, ap); + ret = vsnprintf(formatted_buf, sizeof(formatted_buf), format, ap); va_end(ap); + if (ret < 0 || ret >= sizeof(formatted_buf)) { + _E("vsnprintf() is failed. result(%d)", ret); + return -1; + } return _logger_print(__logger, tag, formatted_buf); } diff --git a/src/launchpad-process-pool/src/launchpad_logger.c b/src/launchpad-process-pool/src/launchpad_logger.c index 529b00c..3dd37a4 100644 --- a/src/launchpad-process-pool/src/launchpad_logger.c +++ b/src/launchpad-process-pool/src/launchpad_logger.c @@ -178,6 +178,7 @@ int _logger_print(logger_h handle, const char *tag, const char *format, ...) ssize_t ret; va_list ap; off_t offset; + int bytes; if (!handle || !tag || !format) { _E("Invalid parameter"); @@ -196,8 +197,12 @@ int _logger_print(logger_h handle, const char *tag, const char *format, ...) _E("lseek() is failed. errno(%d)", errno); va_start(ap, format); - vsnprintf(format_buf, sizeof(format_buf), format, ap); + bytes = vsnprintf(format_buf, sizeof(format_buf), format, ap); va_end(ap); + if (bytes < 0 || bytes >= sizeof(format_buf)) { + _E("vsnprintf() is failed. result(%d)", bytes); + return -1; + } snprintf(buf, sizeof(buf), "[%6d] %04d-%02d-%02d %02d:%02d:%02d %-16s %-100s\n", diff --git a/src/lib/common/src/launchpad_common.c b/src/lib/common/src/launchpad_common.c index 05d8bef..6e370ef 100644 --- a/src/lib/common/src/launchpad_common.c +++ b/src/lib/common/src/launchpad_common.c @@ -1441,16 +1441,20 @@ int _send_message_to_logger(const char *tag, const char *format, ...) int ret; int fd; + va_start(ap, format); + ret = vsnprintf(fmt, sizeof(fmt), format, ap); + va_end(ap); + if (ret < 0 || ret >= sizeof(fmt)) { + _E("vsnprintf() is failed. result(%d)", ret); + return -1; + } + snprintf(buf, sizeof(buf), "%s/daemons/%u/.launchpad-logger-sock", SOCKET_PATH, getuid()); fd = __create_client_socket(buf); if (fd < 0) return -1; - va_start(ap, format); - vsnprintf(fmt, sizeof(fmt), format, ap); - va_end(ap); - snprintf(buf, sizeof(buf), "%s: %s", tag, fmt); ret = __send_raw(fd, 0, (unsigned char *)buf, strlen(buf) + 1); if (ret < 0) { @@ -1467,10 +1471,15 @@ void _print_hwc_log(const char *format, ...) { char buf[1024]; va_list ap; + int ret; va_start(ap, format); - vsnprintf(buf, sizeof(buf), format, ap); + ret = vsnprintf(buf, sizeof(buf), format, ap); va_end(ap); + if (ret < 0 || ret >= sizeof(buf)) { + _E("vsnprintf() is failed. result(%d)", ret); + return; + } prctl(PR_TASK_PERF_USER_TRACE, buf, strlen(buf)); } -- 2.7.4 From d8ea456423b4927b7908c9a9a7a1f253a628b77a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 15 Dec 2020 16:47:47 +0900 Subject: [PATCH 02/16] Release version 0.15.27 Changes: - Check return value of vsnprintf() Change-Id: If70675a4c30020fca27db06e15f4669f4005a96e 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 f498760..5b4f91e 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.26 +Version: 0.15.27 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 6eef2204df3da2146624ad0856ed02b1edb29928 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 22 Dec 2020 12:49:58 +0900 Subject: [PATCH 03/16] Create port directory for component port Before starting launchpad-process-pool, the service file of systemd creates a user directory for component port API. Requires: - https://review.tizen.org/gerrit/#/c/platform/core/appfw/amd/+/250187/ Change-Id: I0b835b6b006e6126158909c5347a5009bdad070b Signed-off-by: Hwankyu Jhun --- packaging/launchpad-process-pool.service | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packaging/launchpad-process-pool.service b/packaging/launchpad-process-pool.service index ba2a747..c3a2ab0 100644 --- a/packaging/launchpad-process-pool.service +++ b/packaging/launchpad-process-pool.service @@ -17,5 +17,7 @@ ExecStartPre=-/usr/bin/mkdir -p /run/aul/dbspace/%U ExecStartPre=-/usr/bin/chmod 0701 /run/aul/dbspace/%U ExecStartPre=-/usr/bin/mkdir -p /run/aul/log/widget/%U ExecStartPre=-/usr/bin/chmod 0777 /run/aul/log/widget/%U +ExecStartPre=-/usr/bin/mkdir -p /run/aul/port/%U +ExecStartPre=-/usr/bin/chmod 0700 /run/aul/port/%U ExecStart=/bin/sh -l -c "/usr/bin/launchpad-process-pool" Sockets=launchpad-process-pool.socket -- 2.7.4 From a59f76b0eb4389b293f75fb45bb5d782d9e845b2 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 31 Dec 2020 09:41:14 +0900 Subject: [PATCH 04/16] Release version 0.16.0 Changes: - Create port directory for component port Change-Id: If65bd2768059a2c3800e453ad9c92729d2218310 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 5b4f91e..7fc9bf9 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.27 +Version: 0.16.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From adc5de7fe45550c641ce9685a168f090ab07bdf0 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 12 Jan 2021 15:05:23 +0900 Subject: [PATCH 05/16] Support logger activation/deactivation After this patch is applied, a default value of the logger is "false". To enable the logger, the platform developer should set "Enable=1" to the launchpad.conf file. Change-Id: I9308964b912f79fa2261f4ac0d83de122e78cd6b Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/conf/launchpad.conf.in | 1 + src/launchpad-process-pool/inc/launchpad_config.h | 1 + src/launchpad-process-pool/src/launchpad_config.c | 13 +++++++++++++ src/launchpad-process-pool/src/launchpad_logger.c | 12 ++++++++++++ 4 files changed, 27 insertions(+) diff --git a/src/launchpad-process-pool/conf/launchpad.conf.in b/src/launchpad-process-pool/conf/launchpad.conf.in index 44acf40..0812a64 100644 --- a/src/launchpad-process-pool/conf/launchpad.conf.in +++ b/src/launchpad-process-pool/conf/launchpad.conf.in @@ -13,3 +13,4 @@ MaxCount=10 [Logger] Path=/run/aul/log +Enable=1 diff --git a/src/launchpad-process-pool/inc/launchpad_config.h b/src/launchpad-process-pool/inc/launchpad_config.h index d38cae3..0f769db 100644 --- a/src/launchpad-process-pool/inc/launchpad_config.h +++ b/src/launchpad-process-pool/inc/launchpad_config.h @@ -26,6 +26,7 @@ typedef enum { CONFIG_TYPE_MEMORY_MONITOR_INTERVAL, CONFIG_TYPE_CPU_CHECKER_MAX_COUNT, CONFIG_TYPE_LOGGER_PATH, + CONFIG_TYPE_LOGGER_ENABLE, } config_type_e; const char *_config_get_string_value(config_type_e type); diff --git a/src/launchpad-process-pool/src/launchpad_config.c b/src/launchpad-process-pool/src/launchpad_config.c index f43bc1a..90e4256 100644 --- a/src/launchpad-process-pool/src/launchpad_config.c +++ b/src/launchpad-process-pool/src/launchpad_config.c @@ -45,6 +45,7 @@ #define TAG_LOGGER "Logger" #define KEY_LOGGER_PATH "Path" +#define KEY_LOGGER_ENABLE "Enable" struct memory_status_s { char *low_key; @@ -64,6 +65,7 @@ struct cpu_checker_s { struct logger_s { char *path; + int enable; }; static struct memory_status_s __memory_status; @@ -114,6 +116,9 @@ int _config_get_int_value(config_type_e type) case CONFIG_TYPE_CPU_CHECKER_MAX_COUNT: value = __cpu_checker.max_count; break; + case CONFIG_TYPE_LOGGER_ENABLE: + value = __logger.enable; + break; default: _E("Unknown type"); value = INT_MIN; @@ -255,6 +260,7 @@ static void __cpu_checker_set(dictionary *d) static void __logger_init(void) { __logger.path = strdup("/var/log/appfw"); + __logger.enable = false; } static void __logger_fini(void) @@ -265,6 +271,7 @@ static void __logger_fini(void) static void __logger_set(dictionary *d) { const char *str; + int val; str = __get_string_value(d, TAG_LOGGER, KEY_LOGGER_PATH); @@ -273,6 +280,12 @@ static void __logger_set(dictionary *d) __logger.path = strdup(str); } _W("Logger path(%s)", __logger.path); + + val = __get_int_value(d, TAG_LOGGER, + KEY_LOGGER_ENABLE); + if (val >= 0) + __logger.enable = val; + _W("Logger enable(%d)", __logger.enable); } int _config_init(void) diff --git a/src/launchpad-process-pool/src/launchpad_logger.c b/src/launchpad-process-pool/src/launchpad_logger.c index 3dd37a4..d6b99d8 100644 --- a/src/launchpad-process-pool/src/launchpad_logger.c +++ b/src/launchpad-process-pool/src/launchpad_logger.c @@ -111,6 +111,9 @@ int _logger_create(const char *path, logger_h *handle) off_t offset; int ret; + if (!_config_get_int_value(CONFIG_TYPE_LOGGER_ENABLE)) + return 0; + if (!path || !handle) { _E("Invalid parameter"); return -EINVAL; @@ -156,6 +159,9 @@ int _logger_create(const char *path, logger_h *handle) int _logger_destroy(logger_h handle) { + if (!_config_get_int_value(CONFIG_TYPE_LOGGER_ENABLE)) + return 0; + if (!handle) { _E("Invalid parameter"); return -EINVAL; @@ -180,6 +186,9 @@ int _logger_print(logger_h handle, const char *tag, const char *format, ...) off_t offset; int bytes; + if (!_config_get_int_value(CONFIG_TYPE_LOGGER_ENABLE)) + return 0; + if (!handle || !tag || !format) { _E("Invalid parameter"); return -EINVAL; @@ -225,6 +234,9 @@ int _logger_print(logger_h handle, const char *tag, const char *format, ...) int _logger_get_fd(logger_h handle, int *fd) { + if (!_config_get_int_value(CONFIG_TYPE_LOGGER_ENABLE)) + return 0; + if (!handle || !fd) { _E("Invalid parameter"); return -EINVAL; -- 2.7.4 From 747287c1bd1e6496b7ea805144f6a96287109826 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 13 Jan 2021 08:32:10 +0900 Subject: [PATCH 06/16] Release version 0.16.1 Changes: - Support logger activation/deactivation Change-Id: I69f4bbc6ef2dc889f4b2b8d90e0768b16adce004 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 7fc9bf9..35a7b76 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.16.0 +Version: 0.16.1 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 55222aa020e669a37d25eda84dc4620c75f738ba Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 8 Feb 2021 16:59:21 +0900 Subject: [PATCH 07/16] Check installed storage before executable file check If the installed storage is "external", launchpad doesn't check an executable file. Change-Id: Iae735ee816978006321ec376e52465fd89e4c647 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/src/launchpad.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/launchpad-process-pool/src/launchpad.c b/src/launchpad-process-pool/src/launchpad.c index 78399c9..c2db5ec 100644 --- a/src/launchpad-process-pool/src/launchpad.c +++ b/src/launchpad-process-pool/src/launchpad.c @@ -2116,6 +2116,7 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) appinfo_t *menu_info = NULL; candidate_process_context_t *cpc = NULL; candidate_process_context_t *org_cpc = NULL; + const char *installed_storage; const char *app_path = NULL; int pid = -1; int clifd = -1; @@ -2224,12 +2225,15 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) goto end; } - if (access(app_path, X_OK) != 0) { - ret = -errno; - _E("%s is not executable. errno(%d)", app_path, errno); - __send_result_to_caller(clifd, ret); - clifd = -1; - goto end; + installed_storage = bundle_get_val(kb, AUL_K_INSTALLED_STORAGE); + if (!installed_storage || strcmp(installed_storage, "external") != 0) { + if (access(app_path, X_OK) != 0) { + ret = -errno; + _E("%s is not executable. errno(%d)", app_path, errno); + __send_result_to_caller(clifd, ret); + clifd = -1; + goto end; + } } if (menu_info->hwacc == NULL) { -- 2.7.4 From 201fefa12fecc71fdf8493e83ef9d6659747a1e6 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 9 Feb 2021 08:10:08 +0900 Subject: [PATCH 08/16] Release version 0.16.2 Changes: - Check installed storage before executable file check Change-Id: I22866e4171856e4961ebc27172632108f60a8aba 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 35a7b76..62d82d4 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.16.1 +Version: 0.16.2 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From c34ea6b5c4ac777706691aa96c2c28654dbe401a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 15 Feb 2021 07:56:18 +0900 Subject: [PATCH 09/16] Check EOF exception When a socket peer has performed an orderly shutdown, recv() returns 0. Change-Id: Ie93b44f2e4682403def921e68de371aba25075a6 Signed-off-by: Hwankyu Jhun --- src/lib/common/src/launchpad_common.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib/common/src/launchpad_common.c b/src/lib/common/src/launchpad_common.c index 6e370ef..d4e0622 100644 --- a/src/lib/common/src/launchpad_common.c +++ b/src/lib/common/src/launchpad_common.c @@ -359,9 +359,10 @@ app_pkt_t *_recv_pkt_raw(int fd) retry_recv: /* receive header(cmd, datalen) */ len = recv(fd, buf, AUL_PKT_HEADER_SIZE, 0); - if (len < 0) + if (len < 0) { if (errno == EINTR) goto retry_recv; + } if (len < AUL_PKT_HEADER_SIZE) { _E("recv error"); @@ -389,8 +390,16 @@ retry_recv: len = 0; while (len != pkt->len) { ret = recv(fd, pkt->data + len, pkt->len - len, 0); + if (ret == 0) { + _E("EOF. fd(%d), len(%d), pkt->len(%d)", + fd, len, pkt->len); + free(pkt); + return NULL; + } + if (ret < 0) { - _E("recv error %d %d", len, pkt->len); + _E("recv() is failed. fd(%d), len(%d), pkt->len(%d)", + fd, len, pkt->len); free(pkt); return NULL; } -- 2.7.4 From 034267f1e75859f344d9a8ff6daf992a3b38e9f7 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 15 Feb 2021 09:53:50 +0900 Subject: [PATCH 10/16] Release version 0.16.3 Changes: - Check EOF exception Change-Id: I4584b07bb3c242f1f47c381b058e5fd9d6159801 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 62d82d4..b342780 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.16.2 +Version: 0.16.3 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 13e9b2f0ef1174a154e0c2d2820ff74f7558ac36 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Wed, 13 Jan 2021 16:30:40 +0900 Subject: [PATCH 11/16] Implement res control feature Change-Id: Ieaa09ca6b547430a3bad33a007e90ae600c9480a Signed-off-by: Sangyoon Jang --- src/launchpad-process-pool/src/launchpad.c | 4 ++ src/lib/common/inc/key.h | 3 +- src/lib/common/inc/launchpad_common.h | 1 + src/lib/common/src/launchpad_common.c | 83 ++++++++++++++++++++++++++++++ src/lib/launchpad/src/launchpad_lib.c | 8 ++- 5 files changed, 96 insertions(+), 3 deletions(-) diff --git a/src/launchpad-process-pool/src/launchpad.c b/src/launchpad-process-pool/src/launchpad.c index c2db5ec..72f114f 100644 --- a/src/launchpad-process-pool/src/launchpad.c +++ b/src/launchpad-process-pool/src/launchpad.c @@ -1258,6 +1258,10 @@ static int __prepare_exec(const char *appid, const char *app_path, return PAD_ERR_REJECTED; } + ret = _mount_res_dir(menu_info->root_path, kb); + if (ret < 0) + return PAD_ERR_FAILED; + /* SET PRIVILEGES*/ _W("security_manager_prepare_app ++"); ret = security_manager_prepare_app(appid); diff --git a/src/lib/common/inc/key.h b/src/lib/common/inc/key.h index d3d2973..19493c6 100644 --- a/src/lib/common/inc/key.h +++ b/src/lib/common/inc/key.h @@ -49,10 +49,11 @@ extern "C" { #define AUL_K_TEP_PATH "__AUL_TEP_PATH__" #define AUL_K_IS_INSTALLED "__AUL_IS_INSTALLED__" #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__" #ifdef __cplusplus } #endif #endif /* __KEY_H__ */ - diff --git a/src/lib/common/inc/launchpad_common.h b/src/lib/common/inc/launchpad_common.h index 2b1d41c..ff257a1 100644 --- a/src/lib/common/inc/launchpad_common.h +++ b/src/lib/common/inc/launchpad_common.h @@ -133,6 +133,7 @@ int _enable_external_pkg(bundle *b, const char *pkgid, uid_t pkg_uid); int _verify_proc_caps(void); int _prepare_id_file(void); void _print_hwc_log(const char *format, ...); +int _mount_res_dir(const char *menu_info, bundle *kb); #ifdef __cplusplus } diff --git a/src/lib/common/src/launchpad_common.c b/src/lib/common/src/launchpad_common.c index d4e0622..7c4ab6f 100644 --- a/src/lib/common/src/launchpad_common.c +++ b/src/lib/common/src/launchpad_common.c @@ -1492,3 +1492,86 @@ void _print_hwc_log(const char *format, ...) prctl(PR_TASK_PERF_USER_TRACE, buf, strlen(buf)); } + +static int __get_mount_opt(const char *srcs[], size_t srcs_len, + const char *dest, const char *workdir, char *opt, size_t opt_len) +{ + int i; + char buf[PATH_MAX]; + int ret; + + snprintf(buf, sizeof(buf), "%s", "lowerdir="); + snprintf(opt, opt_len, "%s", buf); + for (i = 0; i < srcs_len; i++) { + snprintf(buf, sizeof(buf), "%s%s", opt, srcs[i]); + ret = snprintf(opt, opt_len, "%s:", buf); + if (ret < 0) { + _E("source directory string size is too large"); + return -1; + } + } + ret = snprintf(opt, opt_len, "%s,upperdir=%s,workdir=%s", buf, dest, + workdir); + if (ret < 0) { + _E("source directory string size is too large"); + return -1; + } + + _D("mount opt: %s", opt); + + return 0; +} + +static int __mount_dir(const char *srcs[], size_t srcs_len, const char *dest, + const char *workdir) +{ + int ret; + char opt[PATH_MAX]; + + ret = __get_mount_opt(srcs, srcs_len, dest, workdir, opt, sizeof(opt)); + if (ret < 0) { + _E("Failed to get mount option"); + return -1; + } + + ret = mount(NULL, dest, "overlay", MS_RDONLY, opt); + if (ret < 0) { + _E("Failed to mount dir %s. errno(%d)", dest, errno); + return -1; + } + + return 0; +} + +int _mount_res_dir(const char *root_path, bundle *kb) +{ + const char **val; + int len; + char dest[PATH_MAX]; + char workdir[PATH_MAX]; + + val = bundle_get_str_array(kb, AUL_K_MOUNT_GLOBAL_RES_DIR, &len); + if (val) { + snprintf(dest, sizeof(dest), "%s/res/mount/global", root_path); + snprintf(workdir, sizeof(workdir), "%s/res/mount/work", + root_path); + __mount_dir(val, len, dest, workdir); + } else if (get_last_result() != BUNDLE_ERROR_KEY_NOT_AVAILABLE) { + _E("invalid mount info"); + return -1; + } + + val = bundle_get_str_array(kb, AUL_K_MOUNT_ALLOWED_RES_DIR, &len); + if (val) { + snprintf(dest, sizeof(dest), "%s/res/mount/allowed", root_path); + snprintf(workdir, sizeof(workdir), "%s/res/mount/work", + root_path); + __mount_dir(val, len, dest, workdir); + } else if (get_last_result() != BUNDLE_ERROR_KEY_NOT_AVAILABLE) { + _E("invalid mount info"); + return -1; + } + + + return 0; +} diff --git a/src/lib/launchpad/src/launchpad_lib.c b/src/lib/launchpad/src/launchpad_lib.c index 68c2ac4..05fa2c3 100644 --- a/src/lib/launchpad/src/launchpad_lib.c +++ b/src/lib/launchpad/src/launchpad_lib.c @@ -62,7 +62,7 @@ static void __at_exit_to_release_bundle(void) static int __prepare_exec(const char *appid, const char *app_path, const char *pkg_type, int type, const char* pkgid, - bool global, bundle *kb) + const char *root_path, bool global, bundle *kb) { const char *file_name = NULL; char process_name[AUL_PR_NAME] = { 0, }; @@ -90,6 +90,10 @@ static int __prepare_exec(const char *appid, const char *app_path, return -1; } + ret = _mount_res_dir(root_path, kb); + if (ret < 0) + return -1; + _W("security_manager_prepare_app ++"); ret = security_manager_prepare_app(appid); _W("security_manager_prepare_app --"); @@ -166,7 +170,7 @@ static int __default_launch_cb(bundle *kb, const char *appid, int r; r = __prepare_exec(appid, app_path, pkg_type, loader_type, pkgid, - global, kb); + root_path, global, kb); if (r < 0) { _E("__candidate_process_prepare_exec() failed"); if (access(app_path, F_OK | R_OK)) { -- 2.7.4 From 3df1f613961c4a42d0bda6b20cb2e0255a4e8b40 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 10 Mar 2021 12:57:31 +0900 Subject: [PATCH 12/16] Fix logs - Changes log level to warning - Adds logs for debugging Change-Id: I81f2252c475a4d50f632397e032122abd436c84e Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/src/launchpad.c | 5 ++++- src/launchpad-process-pool/src/launchpad_memory_monitor.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/launchpad-process-pool/src/launchpad.c b/src/launchpad-process-pool/src/launchpad.c index 72f114f..d035eb2 100644 --- a/src/launchpad-process-pool/src/launchpad.c +++ b/src/launchpad-process-pool/src/launchpad.c @@ -250,7 +250,7 @@ static gboolean __handle_queuing_slots(gpointer data) __handle_idle_checker, cpc); __sequencer.running_cpc = cpc; - _D("[__SEQUENCER__] Add idle checker. Type(%d)", cpc->type); + _W("[__SEQUENCER__] Add idle checker. Type(%d)", cpc->type); return G_SOURCE_CONTINUE; } @@ -2143,6 +2143,7 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) goto end; } + _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"); @@ -2569,6 +2570,7 @@ static bool __on_directory_create(const char *event_name, uint32_t mask, } if (!strcmp(event_name, LOADERS_PATH)) { + _W("%s is created", LOADERS_PATH); __init_app_defined_loader_monitor(); return false; } @@ -2593,6 +2595,7 @@ static bool __on_file_change(const char *event_name, uint32_t mask, if (ext == NULL || strcmp(ext, ".loader") != 0) return true; + _W("event_name(%s), mask(%u)", event_name, mask); if (mask & IN_CREATE) { snprintf(buf, sizeof(buf), "%s/%s", APP_DEFINED_LOADER_INFO_PATH, event_name); diff --git a/src/launchpad-process-pool/src/launchpad_memory_monitor.c b/src/launchpad-process-pool/src/launchpad_memory_monitor.c index bc99ec1..5bd52ab 100644 --- a/src/launchpad-process-pool/src/launchpad_memory_monitor.c +++ b/src/launchpad-process-pool/src/launchpad_memory_monitor.c @@ -95,7 +95,7 @@ bool _memory_monitor_is_low_memory(void) _proc_get_mem_used_ratio(&mem_used_ratio); - _D("previous used ratio(%u), current used ratio(%u)", + _W("previous used ratio(%u), current used ratio(%u)", __monitor.prev_used_ratio, mem_used_ratio); __monitor.prev_used_ratio = mem_used_ratio; -- 2.7.4 From fc56cf98b0757f132574535d6017b14f808bd807 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 30 Mar 2021 14:19:24 +0900 Subject: [PATCH 13/16] Redirect stdout to dlog Before executing an application, the child process redirects stdout & stderr to dlog fd using connect_dlog() function. If stdout redirection is failed, the child process tries to redirect stdout to journal stream. Change-Id: I356a9fbb18504933e41ab1dddf67b65ddacc47db Signed-off-by: Hwankyu Jhun --- CMakeLists.txt | 3 ++- packaging/launchpad.spec | 1 + src/app-defined-loader/CMakeLists.txt | 1 + src/launchpad-loader/CMakeLists.txt | 1 + src/launchpad-process-pool/CMakeLists.txt | 1 + src/lib/common/src/launchpad_common.c | 20 +++++++++++++++++++- src/lib/launchpad/CMakeLists.txt | 1 + 7 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a8e0f5..063cd75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,8 +54,9 @@ PKG_CHECK_MODULES(BUNDLE_DEPS REQUIRED bundle) PKG_CHECK_MODULES(BUXTON2_DEPS REQUIRED buxton2) PKG_CHECK_MODULES(DBUS_DEPS REQUIRED dbus-1) PKG_CHECK_MODULES(DLOG_DEPS REQUIRED dlog) -PKG_CHECK_MODULES(ECORE_DEPS REQUIRED ecore) +PKG_CHECK_MODULES(DLOG_REDIRECT_STDOUT_DEPS REQUIRED dlog-redirect-stdout) PKG_CHECK_MODULES(ECORE_CORE_DEPS REQUIRED ecore-core) +PKG_CHECK_MODULES(ECORE_DEPS REQUIRED ecore) PKG_CHECK_MODULES(ELEMENTARY_DEPS REQUIRED elementary) PKG_CHECK_MODULES(GIO_DEPS REQUIRED gio-2.0) PKG_CHECK_MODULES(INIPARSER_DEPS REQUIRED iniparser) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index b342780..e69df09 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -17,6 +17,7 @@ BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(ecore) BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(dlog-redirect-stdout) BuildRequires: pkgconfig(libsystemd) BuildRequires: pkgconfig(elementary) BuildRequires: pkgconfig(vconf) diff --git a/src/app-defined-loader/CMakeLists.txt b/src/app-defined-loader/CMakeLists.txt index a7fa8bb..d588f4d 100644 --- a/src/app-defined-loader/CMakeLists.txt +++ b/src/app-defined-loader/CMakeLists.txt @@ -29,6 +29,7 @@ APPLY_PKG_CONFIG(${TARGET_APP_DEFINED_LOADER} PUBLIC BUNDLE_DEPS DBUS_DEPS DLOG_DEPS + DLOG_REDIRECT_STDOUT_DEPS ECORE_DEPS ECORE_CORE_DEPS GIO_DEPS diff --git a/src/launchpad-loader/CMakeLists.txt b/src/launchpad-loader/CMakeLists.txt index 091bba7..b768262 100644 --- a/src/launchpad-loader/CMakeLists.txt +++ b/src/launchpad-loader/CMakeLists.txt @@ -24,6 +24,7 @@ ENDIF(_TIZEN_FEATURE_PRELINK) APPLY_PKG_CONFIG(${TARGET_LAUNCHPAD_LOADER} PUBLIC DLOG_DEPS + DLOG_REDIRECT_STDOUT_DEPS ECORE_DEPS ELEMENTARY_DEPS SECURITY_MANAGER_DEPS diff --git a/src/launchpad-process-pool/CMakeLists.txt b/src/launchpad-process-pool/CMakeLists.txt index 70732ff..b0af4fe 100644 --- a/src/launchpad-process-pool/CMakeLists.txt +++ b/src/launchpad-process-pool/CMakeLists.txt @@ -28,6 +28,7 @@ APPLY_PKG_CONFIG(${TARGET_LAUNCHPAD_PROCESS_POOL} PUBLIC BUNDLE_DEPS DBUS_DEPS DLOG_DEPS + DLOG_REDIRECT_STDOUT_DEPS GIO_DEPS INIPARSER_DEPS LIBCAP_DEPS diff --git a/src/lib/common/src/launchpad_common.c b/src/lib/common/src/launchpad_common.c index 7c4ab6f..47f5857 100644 --- a/src/lib/common/src/launchpad_common.c +++ b/src/lib/common/src/launchpad_common.c @@ -41,6 +41,7 @@ #include #include #include +#include #include "launchpad_common.h" #include "launchpad_types.h" @@ -954,9 +955,18 @@ static int __redirect_stdin(void) static int __redirect_stdout(const char *ident) { + char buf[512]; int ret; int fd; + setbuf(stdout, NULL); + snprintf(buf, sizeof(buf), "STDOUT_%s", ident); + ret = connect_dlog(LOG_ID_MAIN, STDOUT_FILENO, buf, DLOG_INFO); + if (ret != 0) + _W("connect_dlog() is failed. error(%d)", ret); + else + return 0; + fd = sd_journal_stream_fd(ident, LOG_INFO, 0); if (fd < 0) { if (fd != -ENOENT) @@ -984,9 +994,18 @@ static int __redirect_stdout(const char *ident) static int __redirect_stderr(const char *ident) { + char buf[512]; int ret; int fd; + setbuf(stderr, NULL); + snprintf(buf, sizeof(buf), "STDERR_%s", ident); + ret = connect_dlog(LOG_ID_MAIN, STDERR_FILENO, buf, DLOG_WARN); + if (ret != 0) + _W("connect_dlog() is failed. error(%d)", ret); + else + return 0; + fd = sd_journal_stream_fd(ident, LOG_WARNING, 0); if (fd < 0) { if (fd != -ENOENT) @@ -1010,7 +1029,6 @@ static int __redirect_stderr(const char *ident) close(fd); return ret; - } int _setup_stdio(const char *ident) diff --git a/src/lib/launchpad/CMakeLists.txt b/src/lib/launchpad/CMakeLists.txt index d43ea34..053920b 100644 --- a/src/lib/launchpad/CMakeLists.txt +++ b/src/lib/launchpad/CMakeLists.txt @@ -18,6 +18,7 @@ APPLY_PKG_CONFIG(${TARGET_LAUNCHPAD} PUBLIC BUXTON2_DEPS DBUS_DEPS DLOG_DEPS + DLOG_REDIRECT_STDOUT_DEPS LIBCAP_DEPS LIBSYSTEMD_DEPS LIBTZPLATFORM_CONFIG_DEPS -- 2.7.4 From d4b82657260ae2ea9b14d7f2c553d670b9935bdc Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 1 Apr 2021 11:58:10 +0900 Subject: [PATCH 14/16] Release version 0.17.0 Changes: - Implement res control feature - Fix logs - Redirect stdout to dlog Change-Id: Icf5441a1661f05296df2edcb60c76e64c75bd0bc 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 e69df09..fc1cafb 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.16.3 +Version: 0.17.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 76bde3a4a9e76bfe8a6f5f33548b16d203787bc4 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 1 Apr 2021 13:26:53 +0900 Subject: [PATCH 15/16] Remove unnecessary function call After calling execve(), the previous unbuffered setting of stdout is disabled. Change-Id: If53d87d1aeb1c600ea1605e003160c870f201710 Signed-off-by: Hwankyu Jhun --- src/lib/common/src/launchpad_common.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib/common/src/launchpad_common.c b/src/lib/common/src/launchpad_common.c index 47f5857..2f881b4 100644 --- a/src/lib/common/src/launchpad_common.c +++ b/src/lib/common/src/launchpad_common.c @@ -959,7 +959,6 @@ static int __redirect_stdout(const char *ident) int ret; int fd; - setbuf(stdout, NULL); snprintf(buf, sizeof(buf), "STDOUT_%s", ident); ret = connect_dlog(LOG_ID_MAIN, STDOUT_FILENO, buf, DLOG_INFO); if (ret != 0) @@ -998,7 +997,6 @@ static int __redirect_stderr(const char *ident) int ret; int fd; - setbuf(stderr, NULL); snprintf(buf, sizeof(buf), "STDERR_%s", ident); ret = connect_dlog(LOG_ID_MAIN, STDERR_FILENO, buf, DLOG_WARN); if (ret != 0) -- 2.7.4 From 53391c29f7647abaab94965a8f733534d88def80 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Fri, 2 Apr 2021 10:38:27 +0900 Subject: [PATCH 16/16] Revert "Redirect stdout to dlog" This reverts commit fc56cf98b0757f132574535d6017b14f808bd807. Change-Id: I0f144d1f16b05b43994b4e30b3adf3e7848cade7 Signed-off-by: Changgyu Choi --- CMakeLists.txt | 3 +-- packaging/launchpad.spec | 1 - src/app-defined-loader/CMakeLists.txt | 1 - src/launchpad-loader/CMakeLists.txt | 1 - src/launchpad-process-pool/CMakeLists.txt | 1 - src/lib/common/src/launchpad_common.c | 18 +----------------- src/lib/launchpad/CMakeLists.txt | 1 - 7 files changed, 2 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 063cd75..5a8e0f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,9 +54,8 @@ PKG_CHECK_MODULES(BUNDLE_DEPS REQUIRED bundle) PKG_CHECK_MODULES(BUXTON2_DEPS REQUIRED buxton2) PKG_CHECK_MODULES(DBUS_DEPS REQUIRED dbus-1) PKG_CHECK_MODULES(DLOG_DEPS REQUIRED dlog) -PKG_CHECK_MODULES(DLOG_REDIRECT_STDOUT_DEPS REQUIRED dlog-redirect-stdout) -PKG_CHECK_MODULES(ECORE_CORE_DEPS REQUIRED ecore-core) PKG_CHECK_MODULES(ECORE_DEPS REQUIRED ecore) +PKG_CHECK_MODULES(ECORE_CORE_DEPS REQUIRED ecore-core) PKG_CHECK_MODULES(ELEMENTARY_DEPS REQUIRED elementary) PKG_CHECK_MODULES(GIO_DEPS REQUIRED gio-2.0) PKG_CHECK_MODULES(INIPARSER_DEPS REQUIRED iniparser) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index fc1cafb..53747e3 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -17,7 +17,6 @@ BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(ecore) BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(dlog-redirect-stdout) BuildRequires: pkgconfig(libsystemd) BuildRequires: pkgconfig(elementary) BuildRequires: pkgconfig(vconf) diff --git a/src/app-defined-loader/CMakeLists.txt b/src/app-defined-loader/CMakeLists.txt index d588f4d..a7fa8bb 100644 --- a/src/app-defined-loader/CMakeLists.txt +++ b/src/app-defined-loader/CMakeLists.txt @@ -29,7 +29,6 @@ APPLY_PKG_CONFIG(${TARGET_APP_DEFINED_LOADER} PUBLIC BUNDLE_DEPS DBUS_DEPS DLOG_DEPS - DLOG_REDIRECT_STDOUT_DEPS ECORE_DEPS ECORE_CORE_DEPS GIO_DEPS diff --git a/src/launchpad-loader/CMakeLists.txt b/src/launchpad-loader/CMakeLists.txt index b768262..091bba7 100644 --- a/src/launchpad-loader/CMakeLists.txt +++ b/src/launchpad-loader/CMakeLists.txt @@ -24,7 +24,6 @@ ENDIF(_TIZEN_FEATURE_PRELINK) APPLY_PKG_CONFIG(${TARGET_LAUNCHPAD_LOADER} PUBLIC DLOG_DEPS - DLOG_REDIRECT_STDOUT_DEPS ECORE_DEPS ELEMENTARY_DEPS SECURITY_MANAGER_DEPS diff --git a/src/launchpad-process-pool/CMakeLists.txt b/src/launchpad-process-pool/CMakeLists.txt index b0af4fe..70732ff 100644 --- a/src/launchpad-process-pool/CMakeLists.txt +++ b/src/launchpad-process-pool/CMakeLists.txt @@ -28,7 +28,6 @@ APPLY_PKG_CONFIG(${TARGET_LAUNCHPAD_PROCESS_POOL} PUBLIC BUNDLE_DEPS DBUS_DEPS DLOG_DEPS - DLOG_REDIRECT_STDOUT_DEPS GIO_DEPS INIPARSER_DEPS LIBCAP_DEPS diff --git a/src/lib/common/src/launchpad_common.c b/src/lib/common/src/launchpad_common.c index 2f881b4..7c4ab6f 100644 --- a/src/lib/common/src/launchpad_common.c +++ b/src/lib/common/src/launchpad_common.c @@ -41,7 +41,6 @@ #include #include #include -#include #include "launchpad_common.h" #include "launchpad_types.h" @@ -955,17 +954,9 @@ static int __redirect_stdin(void) static int __redirect_stdout(const char *ident) { - char buf[512]; int ret; int fd; - snprintf(buf, sizeof(buf), "STDOUT_%s", ident); - ret = connect_dlog(LOG_ID_MAIN, STDOUT_FILENO, buf, DLOG_INFO); - if (ret != 0) - _W("connect_dlog() is failed. error(%d)", ret); - else - return 0; - fd = sd_journal_stream_fd(ident, LOG_INFO, 0); if (fd < 0) { if (fd != -ENOENT) @@ -993,17 +984,9 @@ static int __redirect_stdout(const char *ident) static int __redirect_stderr(const char *ident) { - char buf[512]; int ret; int fd; - snprintf(buf, sizeof(buf), "STDERR_%s", ident); - ret = connect_dlog(LOG_ID_MAIN, STDERR_FILENO, buf, DLOG_WARN); - if (ret != 0) - _W("connect_dlog() is failed. error(%d)", ret); - else - return 0; - fd = sd_journal_stream_fd(ident, LOG_WARNING, 0); if (fd < 0) { if (fd != -ENOENT) @@ -1027,6 +1010,7 @@ static int __redirect_stderr(const char *ident) close(fd); return ret; + } int _setup_stdio(const char *ident) diff --git a/src/lib/launchpad/CMakeLists.txt b/src/lib/launchpad/CMakeLists.txt index 053920b..d43ea34 100644 --- a/src/lib/launchpad/CMakeLists.txt +++ b/src/lib/launchpad/CMakeLists.txt @@ -18,7 +18,6 @@ APPLY_PKG_CONFIG(${TARGET_LAUNCHPAD} PUBLIC BUXTON2_DEPS DBUS_DEPS DLOG_DEPS - DLOG_REDIRECT_STDOUT_DEPS LIBCAP_DEPS LIBSYSTEMD_DEPS LIBTZPLATFORM_CONFIG_DEPS -- 2.7.4