From fd8e1ee299d5a115e7362a659e8a147eed9c3df5 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 23 Mar 2017 17:39:02 +0900 Subject: [PATCH 01/16] Send app startup signal After calling security_manager_prepare_app(), the child process sends the app startup signal to the amd. This signal is for handling privacy popup. Change-Id: I46c51bb3ffc42c8f0271815fc8bf5e0f69f011ad Signed-off-by: Hwankyu Jhun --- inc/launchpad_common.h | 1 + src/launchpad.c | 1 + src/launchpad_lib.c | 1 + 3 files changed, 3 insertions(+) diff --git a/inc/launchpad_common.h b/inc/launchpad_common.h index 0d4ef6e..68b1e93 100644 --- a/inc/launchpad_common.h +++ b/inc/launchpad_common.h @@ -48,6 +48,7 @@ #define LAUNCHPAD_LAUNCH_SIGNAL 85 #define LAUNCHPAD_DEAD_SIGNAL 61 +#define APP_STARTUP_SIGNAL 91 #define PAD_LOADER_ID_STATIC 0 #define PAD_LOADER_ID_DIRECT 1 diff --git a/src/launchpad.c b/src/launchpad.c index 4087450..5cf71de 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -714,6 +714,7 @@ static int __prepare_exec(const char *appid, const char *app_path, return PAD_ERR_REJECTED; } + _send_cmd_to_amd(APP_STARTUP_SIGNAL); if (bundle_get_type(kb, AUL_K_SDK) == BUNDLE_TYPE_NONE) _setup_stdio(basename(app_path)); diff --git a/src/launchpad_lib.c b/src/launchpad_lib.c index 70a600e..927046e 100644 --- a/src/launchpad_lib.c +++ b/src/launchpad_lib.c @@ -77,6 +77,7 @@ static int __prepare_exec(const char *appid, const char *app_path, return -1; } + _send_cmd_to_amd(APP_STARTUP_SIGNAL); _setup_stdio(basename(app_path)); ret = buxton_open(&bxt_cli, NULL, NULL); -- 2.7.4 From a0819d0af100d7f615895e4c45871929a10800e6 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 30 Mar 2017 18:49:11 +0900 Subject: [PATCH 02/16] Release version 0.2.10 Changes: - Send app startup signal Change-Id: I28818cfc56ff95173665d5a07fe829b5d2efc17f 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 8b2b347..e088168 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.2.9 +Version: 0.2.10 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 1df7e4efa7bf09a3633f440f3eecb17512cf3d51 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 31 Mar 2017 17:32:30 +0900 Subject: [PATCH 03/16] Change dbspace file mode The file mode of /run/aul/dbspace/%U is changed to 701. Change-Id: Ifb5ffe4bcba9b71c5e5b93335f34082227a69cf1 Signed-off-by: Hwankyu Jhun --- packaging/launchpad-process-pool.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad-process-pool.service b/packaging/launchpad-process-pool.service index c890e2d..5c80f02 100644 --- a/packaging/launchpad-process-pool.service +++ b/packaging/launchpad-process-pool.service @@ -14,6 +14,6 @@ ExecStartPre=-/usr/bin/chmod 0777 /run/aul/daemons/%U ExecStartPre=-/usr/bin/mkdir -p /run/aul/apps/%U ExecStartPre=-/usr/bin/chmod 0700 /run/aul/apps/%U ExecStartPre=-/usr/bin/mkdir -p /run/aul/dbspace/%U -ExecStartPre=-/usr/bin/chmod 0700 /run/aul/dbspace/%U +ExecStartPre=-/usr/bin/chmod 0701 /run/aul/dbspace/%U ExecStart=/bin/sh -l -c "/usr/bin/launchpad-process-pool" Sockets=launchpad-process-pool.socket -- 2.7.4 From df9de27ba498a618168795317e93f849a386691a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 4 Apr 2017 17:51:57 +0900 Subject: [PATCH 04/16] Release version 0.2.11 Changes: - Change dbspace file mode Change-Id: I27f422fd069bee3d60d5025f7716a2a1140b3d28 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 e088168..34490b2 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.2.10 +Version: 0.2.11 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From ec97ec0b1970a40bf1afa08c7efc3b3e52ab99a8 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 5 Apr 2017 09:01:27 +0900 Subject: [PATCH 05/16] Check privacy before executing an application If the security_manager_prepare_app_privacy() returns an error, the launch request will be rejected. Change-Id: Iaa4f1341ff684cef33cfeea35921fa3c017bce80 Signed-off-by: Hwankyu Jhun --- src/launchpad.c | 9 ++++++++- src/launchpad_lib.c | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/launchpad.c b/src/launchpad.c index 5cf71de..fef9868 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -707,8 +707,15 @@ static int __prepare_exec(const char *appid, const char *app_path, /* TODO : should be add to check permission in the kernel*/ setsid(); - /* SET PRIVILEGES*/ if (bundle_get_val(kb, AUL_K_PRIVACY_APPID) == NULL) { + /* CHECK PRIVACY */ + ret = security_manager_prepare_app_privacy(appid); + if (ret != SECURITY_MANAGER_SUCCESS) { + _W("Launching %s has been prohibited", appid); + return PAD_ERR_REJECTED; + } + + /* SET PRIVILEGES*/ ret = security_manager_prepare_app(appid); if (ret != SECURITY_MANAGER_SUCCESS) return PAD_ERR_REJECTED; diff --git a/src/launchpad_lib.c b/src/launchpad_lib.c index 927046e..c73c4fd 100644 --- a/src/launchpad_lib.c +++ b/src/launchpad_lib.c @@ -67,9 +67,17 @@ static int __prepare_exec(const char *appid, const char *app_path, __preexec_run(pkg_type, appid, app_path); - /* SET PRIVILEGES*/ SECURE_LOGD("[candidata] appid : %s / pkg_type : %s / app_path : %s", appid, pkg_type, app_path); + + /* CHECK PRIVACY */ + ret = security_manager_prepare_app_privacy(appid); + if (ret != SECURITY_MANAGER_SUCCESS) { + _W("Launching %s has been prohibited", appid); + return -1; + } + + /* SET PRIVILEGES*/ ret = security_manager_prepare_app(appid); if (ret != SECURITY_MANAGER_SUCCESS) { _D("fail to set privileges - " \ -- 2.7.4 From bdeb0fd445c6fc5ce88eb7c37ae82d93befef3cf Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 5 Apr 2017 15:54:22 +0900 Subject: [PATCH 06/16] Fix log messages Change-Id: I0a51bd9e10e6dd5e2c4c1b50746c07606b275fd2 Signed-off-by: Hwankyu Jhun --- src/launchpad.c | 2 +- src/launchpad_lib.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/launchpad.c b/src/launchpad.c index fef9868..e316954 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -711,7 +711,7 @@ static int __prepare_exec(const char *appid, const char *app_path, /* CHECK PRIVACY */ ret = security_manager_prepare_app_privacy(appid); if (ret != SECURITY_MANAGER_SUCCESS) { - _W("Launching %s has been prohibited", appid); + _W("Launching %s has been denied.", appid); return PAD_ERR_REJECTED; } diff --git a/src/launchpad_lib.c b/src/launchpad_lib.c index c73c4fd..ce13216 100644 --- a/src/launchpad_lib.c +++ b/src/launchpad_lib.c @@ -73,7 +73,7 @@ static int __prepare_exec(const char *appid, const char *app_path, /* CHECK PRIVACY */ ret = security_manager_prepare_app_privacy(appid); if (ret != SECURITY_MANAGER_SUCCESS) { - _W("Launching %s has been prohibited", appid); + _W("Launching %s has been denied.", appid); return -1; } -- 2.7.4 From f27961e3e8e6fc83a2bb70f178c7f67d6fc09458 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 14 Apr 2017 13:17:05 +0900 Subject: [PATCH 07/16] Revert "Fix log messages" This reverts commit bdeb0fd445c6fc5ce88eb7c37ae82d93befef3cf. Change-Id: I1a176c1d26409ecc5a0b2e58b6d8622a2c70e595 --- src/launchpad.c | 2 +- src/launchpad_lib.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/launchpad.c b/src/launchpad.c index e316954..fef9868 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -711,7 +711,7 @@ static int __prepare_exec(const char *appid, const char *app_path, /* CHECK PRIVACY */ ret = security_manager_prepare_app_privacy(appid); if (ret != SECURITY_MANAGER_SUCCESS) { - _W("Launching %s has been denied.", appid); + _W("Launching %s has been prohibited", appid); return PAD_ERR_REJECTED; } diff --git a/src/launchpad_lib.c b/src/launchpad_lib.c index ce13216..c73c4fd 100644 --- a/src/launchpad_lib.c +++ b/src/launchpad_lib.c @@ -73,7 +73,7 @@ static int __prepare_exec(const char *appid, const char *app_path, /* CHECK PRIVACY */ ret = security_manager_prepare_app_privacy(appid); if (ret != SECURITY_MANAGER_SUCCESS) { - _W("Launching %s has been denied.", appid); + _W("Launching %s has been prohibited", appid); return -1; } -- 2.7.4 From fed82415b9ecd63417a9e80aa9d443e0cc4c158b Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 14 Apr 2017 13:17:21 +0900 Subject: [PATCH 08/16] Revert "Check privacy before executing an application" This reverts commit ec97ec0b1970a40bf1afa08c7efc3b3e52ab99a8. Change-Id: I0568a14bbf665abfea8a8e0bae85feb58cf2de1e --- src/launchpad.c | 9 +-------- src/launchpad_lib.c | 10 +--------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/launchpad.c b/src/launchpad.c index fef9868..5cf71de 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -707,15 +707,8 @@ static int __prepare_exec(const char *appid, const char *app_path, /* TODO : should be add to check permission in the kernel*/ setsid(); + /* SET PRIVILEGES*/ if (bundle_get_val(kb, AUL_K_PRIVACY_APPID) == NULL) { - /* CHECK PRIVACY */ - ret = security_manager_prepare_app_privacy(appid); - if (ret != SECURITY_MANAGER_SUCCESS) { - _W("Launching %s has been prohibited", appid); - return PAD_ERR_REJECTED; - } - - /* SET PRIVILEGES*/ ret = security_manager_prepare_app(appid); if (ret != SECURITY_MANAGER_SUCCESS) return PAD_ERR_REJECTED; diff --git a/src/launchpad_lib.c b/src/launchpad_lib.c index c73c4fd..927046e 100644 --- a/src/launchpad_lib.c +++ b/src/launchpad_lib.c @@ -67,17 +67,9 @@ static int __prepare_exec(const char *appid, const char *app_path, __preexec_run(pkg_type, appid, app_path); + /* SET PRIVILEGES*/ SECURE_LOGD("[candidata] appid : %s / pkg_type : %s / app_path : %s", appid, pkg_type, app_path); - - /* CHECK PRIVACY */ - ret = security_manager_prepare_app_privacy(appid); - if (ret != SECURITY_MANAGER_SUCCESS) { - _W("Launching %s has been prohibited", appid); - return -1; - } - - /* SET PRIVILEGES*/ ret = security_manager_prepare_app(appid); if (ret != SECURITY_MANAGER_SUCCESS) { _D("fail to set privileges - " \ -- 2.7.4 From fc51042078803d64afa940b8c953307a5468882f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 24 Apr 2017 08:45:32 +0900 Subject: [PATCH 09/16] Fix APP_STARTUP_SIGNAL number The APP_STARTUP_SIGNAL number is changed. Change-Id: I72cc6584b3c1d924a73b4013d271d77deea8fa91 Signed-off-by: Hwankyu Jhun --- inc/launchpad_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/launchpad_common.h b/inc/launchpad_common.h index 68b1e93..a2a95ad 100644 --- a/inc/launchpad_common.h +++ b/inc/launchpad_common.h @@ -48,7 +48,7 @@ #define LAUNCHPAD_LAUNCH_SIGNAL 85 #define LAUNCHPAD_DEAD_SIGNAL 61 -#define APP_STARTUP_SIGNAL 91 +#define APP_STARTUP_SIGNAL 89 #define PAD_LOADER_ID_STATIC 0 #define PAD_LOADER_ID_DIRECT 1 -- 2.7.4 From 6aaaea3d418b9e7d67ade6aa93b5060a6c8f74b1 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 25 Apr 2017 12:47:45 +0900 Subject: [PATCH 10/16] Release version 0.2.12 Changes: - Fix APP_STARTUP_SIGNAL number Change-Id: I40a34edba5d8c458d626851449b9885fbfe71519 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 34490b2..b1180f6 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.2.11 +Version: 0.2.12 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From aea366cd4027d6a085d5c52cf143f596bb19dfc5 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 26 May 2017 16:20:52 +0900 Subject: [PATCH 11/16] Fix build dependency - Use libsystemd instead of libsystemd-daemon Change-Id: Ia61fb5e7e3322e8bd28e3ae97c0ebbe05c2cbc8a Signed-off-by: Hwankyu Jhun --- CMakeLists.txt | 4 ++-- packaging/launchpad.spec | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e0c208f..9c1c049 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ SET (this_target_lib launchpad) INCLUDE(FindPkgConfig) PKG_CHECK_MODULES(${this_target_pool} REQUIRED dlog - libsystemd-daemon + libsystemd security-manager bundle gio-2.0 @@ -28,7 +28,7 @@ PKG_CHECK_MODULES(${this_target_loader} REQUIRED aul vconf buxton2 - libsystemd-daemon + libsystemd ) FOREACH(flag ${${this_target_loader}_CFLAGS}) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index b1180f6..9c0baf2 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -14,7 +14,7 @@ BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(ecore) BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(libsystemd-daemon) +BuildRequires: pkgconfig(libsystemd) BuildRequires: pkgconfig(elementary) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(buxton2) -- 2.7.4 From aa42502cc5036e85227f59f5d5974b2cb46e96ad Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 29 May 2017 19:02:54 +0900 Subject: [PATCH 12/16] Fix priority change feature - Change prefix to "TIZEN_FEATURE". - Change lowest priority value to 19. (range: -20 ~ 19) - Set CAP_SYS_NICE if the feature is enabled - Add a new API to adjust scheduling priority Note: - To enable the feature, the user session systemd should have the cap_sys_nice capability(inheritable). Change-Id: I86e3d30a26ecde5bf8a70ef1cb2660fa33cc5aef Signed-off-by: Hwankyu Jhun --- CMakeLists.txt | 9 ++++++--- inc/key.h | 1 + inc/launchpad.h | 15 +++++++++++++++ inc/launchpad_common.h | 1 + packaging/launchpad.spec | 21 +++++++++++++++++---- src/launchpad.c | 19 ++----------------- src/launchpad_common.c | 15 +++++++++++++++ src/launchpad_lib.c | 43 +++++-------------------------------------- src/launchpad_loader.c | 20 +++++++++++++++++++- 9 files changed, 81 insertions(+), 63 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c1c049..23a351c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,9 +62,12 @@ SET(CMAKE_C_FLAGS_RELEASE "-O2") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") ADD_DEFINITIONS("-DSHARE_PREFIX=\"/usr/share/aul\"") -IF(_APPFW_FEATURE_PRIORITY_CHANGE) - ADD_DEFINITIONS("-D_APPFW_FEATURE_PRIORITY_CHANGE") -ENDIF(_APPFW_FEATURE_PRIORITY_CHANGE) +IF(_TIZEN_FEATURE_PRIORITY_CHANGE) + ADD_DEFINITIONS("-DTIZEN_FEATURE_PRIORITY_CHANGE") +ENDIF(_TIZEN_FEATURE_PRIORITY_CHANGE) +IF(_TIZEN_FEATURE_LOADER_PRIORITY) + ADD_DEFINITIONS("-DTIZEN_FEATURE_LOADER_PRIORITY") +ENDIF(_TIZEN_FEATURE_LOADER_PRIORITY) ADD_DEFINITIONS("-DLAUNCHPAD_LOG") ADD_DEFINITIONS("-DPRELOAD_ACTIVATE") diff --git a/inc/key.h b/inc/key.h index e83bb14..98647e0 100644 --- a/inc/key.h +++ b/inc/key.h @@ -45,6 +45,7 @@ extern "C" { #define AUL_K_LOADER_NAME "__AUL_LOADER_NAME__" #define AUL_K_SDK "__AUL_SDK__" #define AUL_K_ORG_CALLER_PID "__AUL_ORG_CALLER_PID__" +#define AUL_K_HIGHPRIORITY "__AUL_HIGHPRIORITY__" #ifdef __cplusplus } diff --git a/inc/launchpad.h b/inc/launchpad.h index fb2cabf..7c2cae8 100644 --- a/inc/launchpad.h +++ b/inc/launchpad.h @@ -60,6 +60,21 @@ int launchpad_loader_main(int argc, char **argv, loader_lifecycle_callback_s *callbacks, loader_adapter_s *adapter, void *user_data); +/* + * @par Description + * Set program scheduling priority. + * + * @param[in] prio The priority + * @return @c 0 on success, + * otherwise a negative error value + * + * @remarks + * The prio is a value in the range -20 to 19. + * If the prio is higher than current value, the process MUST have + * CAP_SYS_NICE capability. + */ +int launchpad_loader_set_priority(int prio); + #ifdef __cplusplus } #endif diff --git a/inc/launchpad_common.h b/inc/launchpad_common.h index a2a95ad..7a8e323 100644 --- a/inc/launchpad_common.h +++ b/inc/launchpad_common.h @@ -109,6 +109,7 @@ int _proc_get_attr_by_pid(int pid, char *buf, int size); int _close_all_fds(void); void _get_cpu_idle(unsigned long long *total, unsigned long long *idle); int _setup_stdio(const char *ident); +int _set_priority(int prio); #endif /* __LAUNCHPAD_COMMON_H__ */ diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 9c0baf2..e0f0e84 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -29,7 +29,8 @@ Requires(postun): /sbin/ldconfig Requires(postun): /usr/bin/systemctl Requires(preun): /usr/bin/systemctl -%define appfw_feature_priority_change 0 +%define tizen_feature_priority_change 0 +%define tizen_feature_loader_priority 0 %description Launchpad for launching applications @@ -58,14 +59,18 @@ export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE" export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" %endif -%if 0%{?appfw_feature_priority_change} -_APPFW_FEATURE_PRIORITY_CHANGE=ON +%if 0%{?tizen_feature_priority_change} +_TIZEN_FEATURE_PRIORITY_CHANGE=ON +%endif +%if 0%{?tizen_feature_loader_priority} +_TIZEN_FEATURE_LOADER_PRIORITY=ON %endif MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %cmake -DVERSION=%{version} \ -DMAJORVER=${MAJORVER} \ - -D_APPFW_FEATURE_PRIORITY_CHANGE:BOOL=${_APPFW_FEATURE_PRIORITY_CHANGE} \ + -D_TIZEN_FEATURE_PRIORITY_CHANGE:BOOL=${_TIZEN_FEATURE_PRIORITY_CHANGE} \ + -D_TIZEN_FEATURE_LOADER_PRIORITY:BOOL=${_TIZEN_FEATURE_LOADER_PRIORITY} \ . %__make %{?_smp_mflags} @@ -90,7 +95,11 @@ ln -sf ../launchpad-process-pool.service %{buildroot}%{_unitdir_user}/basic.targ %{_unitdir_user}/launchpad-process-pool.socket %{_unitdir_user}/sockets.target.wants/launchpad-process-pool.socket %{_unitdir_user}/basic.target.wants/launchpad-process-pool.service +%if 0%{?tizen_feature_priority_change} || 0%{?tizen_feature_loader_priority} +%caps(cap_mac_admin,cap_dac_override,cap_setgid,cap_sys_nice=ei) %{_bindir}/launchpad-process-pool +%else %caps(cap_mac_admin,cap_dac_override,cap_setgid=ei) %{_bindir}/launchpad-process-pool +%endif %attr(0644,root,root) %{_libdir}/liblaunchpad.so.* %files devel @@ -102,4 +111,8 @@ ln -sf ../launchpad-process-pool.service %{buildroot}%{_unitdir_user}/basic.targ %manifest %{name}.manifest %license LICENSE %{_prefix}/share/aul/default.loader +%if 0%{?tizen_feature_priority_change} || 0%{?tizen_feature_loader_priority} +%caps(cap_setgid,cap_sys_nice=ei) %{_bindir}/launchpad-loader +%else %caps(cap_setgid=ei) %{_bindir}/launchpad-loader +%endif diff --git a/src/launchpad.c b/src/launchpad.c index 5cf71de..ce1a77f 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -1695,21 +1695,6 @@ static void __after_loop(void) security_manager_app_labels_monitor_finish(label_monitor); } -#ifdef _APPFW_FEATURE_PRIORITY_CHANGE -static void __set_priority(void) -{ - char err_str[MAX_LOCAL_BUFSZ] = { 0, }; - int res; - - res = setpriority(PRIO_PROCESS, 0, -12); - if (res == -1) { - SECURE_LOGE("Setting process (%d) priority to -12 failed, " \ - "errno: %d (%s)", getpid(), errno, - strerror_r(errno, err_str, sizeof(err_str))); - } -} -#endif - int main(int argc, char **argv) { GMainLoop *mainloop = NULL; @@ -1725,8 +1710,8 @@ int main(int argc, char **argv) return -1; } -#ifdef _APPFW_FEATURE_PRIORITY_CHANGE - __set_priority(); +#ifdef TIZEN_FEATURE_PRIORITY_CHANGE + _set_priority(-12); #endif g_main_loop_run(mainloop); diff --git a/src/launchpad_common.c b/src/launchpad_common.c index e3d727e..7f15619 100644 --- a/src/launchpad_common.c +++ b/src/launchpad_common.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include "launchpad_common.h" #include "key.h" @@ -868,3 +870,16 @@ int _setup_stdio(const char *ident) return 0; } + +int _set_priority(int prio) +{ + int r; + + r = setpriority(PRIO_PGRP, 0, prio); + if (r < 0) { + SECURE_LOGE("Failed to set process(%d) priority(%d) - err(%d)", + getpid(), prio, errno); + } + + return r; +} diff --git a/src/launchpad_lib.c b/src/launchpad_lib.c index 927046e..da0a357 100644 --- a/src/launchpad_lib.c +++ b/src/launchpad_lib.c @@ -22,10 +22,6 @@ #include #include #include -#ifdef _APPFW_FEATURE_LOADER_PRIORITY -#include -#include -#endif #include #include #include @@ -40,7 +36,6 @@ #endif #define AUL_PR_NAME 16 -#define LOWEST_PRIO 20 static loader_lifecycle_callback_s *__loader_callbacks; static loader_adapter_s *__loader_adapter; @@ -130,22 +125,6 @@ static int __default_launch_cb(bundle *kb, const char *appid, const char *pkgid, const char *pkg_type, int loader_type) { char err_str[MAX_LOCAL_BUFSZ] = { 0, }; -#ifdef _APPFW_FEATURE_PRIORITY_CHANGE - int res; - const char *high_priority = bundle_get_val(kb, AUL_K_HIGHPRIORITY); - - _D("high_priority: %s", high_priority); - if (strncmp(high_priority, "true", 4) == 0) { - res = setpriority(PRIO_PROCESS, 0, -10); - if (res == -1) { - SECURE_LOGE("Setting process (%d) priority " \ - "to -10 failed, errno: %d (%s)", - getpid(), errno, - strerror_r(errno, err_str, sizeof(err_str))); - } - } - bundle_del(kb, AUL_K_HIGHPRIORITY); -#endif if (__prepare_exec(appid, app_path, pkg_type, loader_type) < 0) { _E("__candidate_process_prepare_exec() failed"); @@ -296,16 +275,7 @@ static int __before_loop(int argc, char **argv) int client_fd; int ret = -1; bundle *extra = NULL; -#ifdef _APPFW_FEATURE_LOADER_PRIORITY - char err_str[MAX_LOCAL_BUFSZ] = { 0, }; - int res = setpriority(PRIO_PROCESS, 0, LOWEST_PRIO); - if (res == -1) { - SECURE_LOGE("Setting process (%d) priority to %d failed, " \ - "errno: %d (%s)", getpid(), LOWEST_PRIO, errno, - strerror_r(errno, err_str, sizeof(err_str))); - } -#endif __preexec_init(argc, argv); /* Set new session ID & new process group ID*/ @@ -332,14 +302,7 @@ static int __before_loop(int argc, char **argv) bundle_free(extra); malloc_trim(0); -#ifdef _APPFW_FEATURE_LOADER_PRIORITY - res = setpriority(PRIO_PGRP, 0, 0); - if (res == -1) { - SECURE_LOGE("Setting process (%d) priority to 0 failed, " \ - "errno: %d (%s)", getpid(), errno, - strerror_r(errno, err_str, sizeof(err_str))); - } -#endif + client_fd = _connect_to_launchpad(__loader_type, __loader_id); if (client_fd == -1) { _D("Connecting to candidate process was failed."); @@ -414,3 +377,7 @@ API int launchpad_loader_main(int argc, char **argv, return __after_loop(); } +API int launchpad_loader_set_priority(int prio) +{ + return _set_priority(prio); +} diff --git a/src/launchpad_loader.c b/src/launchpad_loader.c index fdc60a5..01487de 100644 --- a/src/launchpad_loader.c +++ b/src/launchpad_loader.c @@ -36,7 +36,6 @@ #define LOADER_TYPE_HW "hw-loader" #define LOADER_TYPE_SW "sw-loader" - extern bundle *launchpad_loader_get_bundle(void); static Ecore_Fd_Handler *__fd_handler; @@ -181,6 +180,10 @@ static void __loader_create_cb(bundle *extra, int type, void *user_data) return; } +#ifdef TIZEN_FEATURE_LOADER_PRIORITY + launchpad_loader_set_priority(19); +#endif + if (!strcmp(LOADER_TYPE_COMMON, ltype)) __type = TYPE_COMMON; else if (!strcmp(LOADER_TYPE_SW, ltype)) @@ -224,6 +227,9 @@ static void __loader_create_cb(bundle *extra, int type, void *user_data) _E("Failed to register callback for %s", VCONFKEY_SETAPPL_APP_HW_ACCELERATION); } +#ifdef TIZEN_FEATURE_LOADER_PRIORITY + launchpad_loader_set_priority(0); +#endif } static loader_convertible __converter_table[MAX_LOADER_TYPE][MAX_ACC_TYPE] = { @@ -243,12 +249,24 @@ static int __loader_launch_cb(int argc, char **argv, const char *app_path, bundle *kb = launchpad_loader_get_bundle(); int acc = SW_ACC; loader_convertible convert; +#ifdef TIZEN_FEATURE_PRIORITY_CHANGE + const char *high_priority; +#endif vconf_ignore_key_changed(VCONFKEY_SETAPPL_APP_HW_ACCELERATION, __vconf_cb); if (kb == NULL) return 0; +#ifdef TIZEN_FEATURE_PRIORITY_CHANGE + high_priority = bundle_get_val(kb, AUL_K_HIGHPRIORITY); + if (high_priority) { + if (!strcmp(high_priority, "true")) + launchpad_loader_set_priority(-12); + bundle_del(kb, AUL_K_HIGHPRIORITY); + } +#endif + hwacc = bundle_get_val(kb, AUL_K_HWACC); if (!hwacc) -- 2.7.4 From 824d0a6aca7298f096b30c893cea55c54cf4ab93 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Thu, 25 May 2017 16:52:45 +0900 Subject: [PATCH 13/16] Change threshold to detect idle time dynamically - Some devices may have not enough cpu power to reach maximum threshold. - To cover this issue, the threshold should be changed properly Change-Id: I28dcfc5e1e2353b9eef47a83e68b834412560cd5 Signed-off-by: Junghoon Park --- CMakeLists.txt | 2 +- src/launchpad.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23a351c..6a03d54 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,7 +109,7 @@ SET(${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES ) ADD_EXECUTABLE(${LAUNCHPAD_PROCESS_POOL} ${${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES}) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${${this_target_pool}_LDFLAGS} "-pie") +TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${${this_target_pool}_LDFLAGS} "-pie -lm") SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_pool}) SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL} PROPERTIES SKIP_BUILD_RPATH TRUE diff --git a/src/launchpad.c b/src/launchpad.c index ce1a77f..a9a55b4 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "perf.h" #include "launchpad_common.h" @@ -59,6 +60,9 @@ #define PAD_ERR_INVALID_ARGUMENT -3 #define PAD_ERR_INVALID_PATH -4 #define CPU_CHECKER_TIMEOUT 1000 +#define DEFAULT_THRESHOLD 90 +#define MIN_THRESHOLD 40 +#define PI 3.14159265 typedef struct { int type; @@ -103,6 +107,7 @@ static int user_slot_offset; static GList *candidate_slot_list; static app_labels_monitor *label_monitor; static GList *launcher_info_list; +static int __threshold = DEFAULT_THRESHOLD; static candidate_process_context_t *__add_slot(int type, int loader_id, int caller_pid, const char *loader_path, const char *extra, @@ -1080,6 +1085,39 @@ static gboolean __handle_label_monitor(gpointer data) return G_SOURCE_CONTINUE; } +static float __interpolator(float input) +{ + float ret; + float min = MIN_THRESHOLD / 100.0f; + float max = DEFAULT_THRESHOLD / 100.0f; + + if (input > 1.0f) + input = 1.0f; + if (input < 0.0f) + input = 0.0f; + + ret = cos(input * PI) / 2.0f + 0.5f; + ret *= max - min; + ret += min; + + return ret; +} + +static void __update_threshold(float delta) +{ + static float pos = 0.0f; + + pos += delta; + if (pos < 0.0f) + pos = 0.0f; + + if (pos > 1.0f) + pos = 1.0f; + + __threshold = (int)(__interpolator(pos) * 100); + _D("[CPU] delta:%f / input cursor : %f / threshold : %d", delta, pos, __threshold); +} + static gboolean __handle_idle_checker(gpointer data) { unsigned long long total = 0; @@ -1092,9 +1130,10 @@ static gboolean __handle_idle_checker(gpointer data) total++; per = (idle - cpc->cpu_idle_time) * 100 / (total - cpc->cpu_total_time); - _D("CPU Idle : %d %d", per, cpc->type); + _D("[CPU] Idle : %d / type : %d", per, cpc->type); - if (per >= 90) { + if (per >= __threshold) { + __update_threshold(-0.02f * (per - __threshold)); __prepare_candidate_process(cpc->type, cpc->loader_id); cpc->idle_checker = 0; return G_SOURCE_REMOVE; @@ -1102,6 +1141,8 @@ static gboolean __handle_idle_checker(gpointer data) cpc->cpu_idle_time = idle; cpc->cpu_total_time = total; + __update_threshold(0.05f); + return G_SOURCE_CONTINUE; } -- 2.7.4 From 5515b496a07827eafa2cfaa962695ad60bf3a3eb Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 1 Jun 2017 08:54:14 +0900 Subject: [PATCH 14/16] Release version 0.2.13 Changes: - Change threshold to detect idle time dynamically - Fix priority change feature - Fix build dependency Change-Id: I4570d357e401010f37eb726b9fa47342e6424dea 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 e0f0e84..fbae388 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.2.12 +Version: 0.2.13 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 59def0ee42ed1ea7aa0328a817725d57885e5ddc Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 7 Jun 2017 08:17:08 +0900 Subject: [PATCH 15/16] Fix log message about buxton error handling This patch adds log messages about errno value. Change-Id: Ida32efcea628f86e0122dec19569b1c9dcb16a8e Signed-off-by: Hwankyu Jhun --- src/launchpad_lib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/launchpad_lib.c b/src/launchpad_lib.c index da0a357..748f6af 100644 --- a/src/launchpad_lib.c +++ b/src/launchpad_lib.c @@ -77,12 +77,12 @@ static int __prepare_exec(const char *appid, const char *app_path, ret = buxton_open(&bxt_cli, NULL, NULL); if (ret != 0) { - _E("buxton_open() failed"); + _E("buxton_open() failed, errno(%d)", errno); return -1; } ret = buxton_update_client_label_sync(bxt_cli); if (ret != 0) { - _E("buxton_update_client_label() failed"); + _E("buxton_update_client_label() failed, errno(%d)", errno); buxton_close(bxt_cli); return -1; } -- 2.7.4 From 9ac2e32ca697d14bb49e33dd7993f1017c3c4178 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 7 Jun 2017 12:14:32 +0900 Subject: [PATCH 16/16] Prevent buffer overflow Change-Id: I80053a8fd20b7554b2ffeeede9dbcc561469e922 Signed-off-by: Hwankyu Jhun --- inc/launchpad_common.h | 7 ++++++ src/debugger_info.c | 32 ++++++++++++------------ src/launcher_info.c | 32 ++++++++++++------------ src/loader_info.c | 66 ++++++++++++++++++++++++++++---------------------- 4 files changed, 76 insertions(+), 61 deletions(-) diff --git a/inc/launchpad_common.h b/inc/launchpad_common.h index 7a8e323..c7c1012 100644 --- a/inc/launchpad_common.h +++ b/inc/launchpad_common.h @@ -58,6 +58,13 @@ #define _D(fmt, arg...) LOGD(fmt, ##arg) #define _W(fmt, arg...) LOGW(fmt, ##arg) +#define FREE_AND_NULL(x) do { \ + if (x) { \ + free(x); \ + x = NULL; \ + } \ +} while (0) + enum loader_arg { LOADER_ARG_PATH, LOADER_ARG_TYPE, diff --git a/src/debugger_info.c b/src/debugger_info.c index 44bd1e9..a7cdffc 100644 --- a/src/debugger_info.c +++ b/src/debugger_info.c @@ -93,17 +93,11 @@ static void __parse_app_types(struct debugger_info_s *info, char *line) { char *token; char *saveptr = NULL; - char tok[LINE_MAX]; - token = strtok_r(line, "|", &saveptr); + token = strtok_r(line, "\t |\n", &saveptr); while (token) { - tok[0] = '\0'; - sscanf(token, "%s", tok); - if (tok[0] != '\0' && strcasecmp(tok, "null") != 0) { - info->app_types = g_list_append(info->app_types, - strdup(tok)); - } - token = strtok_r(NULL, "|", &saveptr); + info->app_types = g_list_append(info->app_types, strdup(token)); + token = strtok_r(NULL, "\t |\n", &saveptr); } } @@ -111,8 +105,8 @@ static GList *__parse_file(GList *list, const char *path) { FILE *fp; char buf[LINE_MAX]; - char tok1[LINE_MAX]; - char tok2[LINE_MAX]; + char *tok1 = NULL; + char *tok2 = NULL; struct debugger_info_s *info = NULL; fp = fopen(path, "rt"); @@ -120,11 +114,10 @@ static GList *__parse_file(GList *list, const char *path) return list; while (fgets(buf, sizeof(buf), fp) != NULL) { - tok1[0] = '\0'; - tok2[0] = '\0'; - sscanf(buf, "%s %s", tok1, tok2); - - if (strcasecmp(TAG_DEBUGGER, tok1) == 0) { + FREE_AND_NULL(tok1); + FREE_AND_NULL(tok2); + sscanf(buf, "%ms %ms", &tok1, &tok2); + if (tok1 && strcasecmp(TAG_DEBUGGER, tok1) == 0) { if (info) { _D("name: %s, exe: %s", info->name, info->exe); list = g_list_append(list, info); @@ -137,6 +130,8 @@ static GList *__parse_file(GList *list, const char *path) continue; } + if (!tok1 || !tok2) + continue; if (tok1[0] == '\0' || tok2[0] == '\0' || tok1[0] == '#') continue; if (info == NULL) @@ -200,6 +195,11 @@ static GList *__parse_file(GList *list, const char *path) list = g_list_append(list, info); } + if (tok1) + free(tok1); + if (tok2) + free(tok2); + return list; } diff --git a/src/launcher_info.c b/src/launcher_info.c index bff7a12..d8d9cc2 100644 --- a/src/launcher_info.c +++ b/src/launcher_info.c @@ -73,17 +73,11 @@ static void __parse_app_types(struct launcher_info_s *info, char *line) { char *token; char *saveptr = NULL; - char tok[LINE_MAX]; - token = strtok_r(line, "|", &saveptr); + token = strtok_r(line, "\t |\n", &saveptr); while (token) { - tok[0] = '\0'; - sscanf(token, "%s", tok); - if (tok[0] != '\0' && strcasecmp(tok, "null") != 0) { - info->app_types = g_list_append(info->app_types, - strdup(tok)); - } - token = strtok_r(NULL, "|", &saveptr); + info->app_types = g_list_append(info->app_types, strdup(token)); + token = strtok_r(NULL, "\t |\n", &saveptr); } } @@ -91,8 +85,8 @@ static GList *__parse_file(GList *list, const char *path) { FILE *fp; char buf[LINE_MAX]; - char tok1[LINE_MAX]; - char tok2[LINE_MAX]; + char *tok1 = NULL; + char *tok2 = NULL; struct launcher_info_s *info = NULL; fp = fopen(path, "rt"); @@ -100,11 +94,10 @@ static GList *__parse_file(GList *list, const char *path) return list; while (fgets(buf, sizeof(buf), fp) != NULL) { - tok1[0] = '\0'; - tok2[0] = '\0'; - sscanf(buf, "%s %s", tok1, tok2); - - if (strcasecmp(TAG_LAUNCHER, tok1) == 0) { + FREE_AND_NULL(tok1); + FREE_AND_NULL(tok2); + sscanf(buf, "%ms %ms", &tok1, &tok2); + if (tok1 && strcasecmp(TAG_LAUNCHER, tok1) == 0) { if (info) { _D("name: %s, exe: %s", info->name, info->exe); list = g_list_append(list, info); @@ -117,6 +110,8 @@ static GList *__parse_file(GList *list, const char *path) continue; } + if (!tok1 || !tok2) + continue; if (tok1[0] == '\0' || tok2[0] == '\0' || tok1[0] == '#') continue; if (info == NULL) @@ -163,6 +158,11 @@ static GList *__parse_file(GList *list, const char *path) list = g_list_append(list, info); } + if (tok1) + free(tok1); + if (tok2) + free(tok2); + return list; } diff --git a/src/loader_info.c b/src/loader_info.c index c4ac48c..b8ffb9a 100644 --- a/src/loader_info.c +++ b/src/loader_info.c @@ -63,20 +63,18 @@ static void __parse_detection_method(loader_info_t *info, char *line) { char *token; char *savedptr; - char refined_tok[LINE_MAX]; - token = strtok_r(line, "|", &savedptr); + token = strtok_r(line, "\t |\n", &savedptr); info->detection_method = 0; while (token) { - sscanf(token, "%s", refined_tok); - if (!strcmp(refined_tok, VAL_METHOD_TIMEOUT)) + if (!strcmp(token, VAL_METHOD_TIMEOUT)) info->detection_method |= METHOD_TIMEOUT; - if (!strcmp(refined_tok, VAL_METHOD_VISIBILITY)) + else if (!strcmp(token, VAL_METHOD_VISIBILITY)) info->detection_method |= METHOD_VISIBILITY; - if (!strcmp(refined_tok, VAL_METHOD_DEMAND)) + else if (!strcmp(token, VAL_METHOD_DEMAND)) info->detection_method |= METHOD_DEMAND; - token = strtok_r(NULL, "|", &savedptr); + token = strtok_r(NULL, "\t |\n", &savedptr); } _D("detection_method:%d", info->detection_method); @@ -86,36 +84,40 @@ static void __parse_app_types(loader_info_t *info, char *line) { char *token; char *savedptr; - char refined_tok[LINE_MAX]; - token = strtok_r(line, "|", &savedptr); + token = strtok_r(line, "\t |\n", &savedptr); while (token) { - refined_tok[0] = '\0'; - sscanf(token, "%s", refined_tok); - if (refined_tok[0] != '\0' && - strcasecmp("null", refined_tok) != 0) { - info->app_types = g_list_append(info->app_types, - strdup(refined_tok)); - } - token = strtok_r(NULL, "|", &savedptr); + info->app_types = g_list_append(info->app_types, strdup(token)); + token = strtok_r(NULL, "\t |\n", &savedptr); } } static void __parse_extra(loader_info_t *info, char *line) { - char tok1[LINE_MAX] = { 0, }; - char tok2[LINE_MAX] = { 0, }; - char tok3[LINE_MAX] = { 0, }; + char *tok1 = NULL; + char *tok2 = NULL; + char *tok3 = NULL; if (info->extra == NULL) return; - sscanf(line, "%s %s %s", tok1, tok2, tok3); + sscanf(line, "%ms %ms %ms", &tok1, &tok2, &tok3); + + if (!tok1 || !tok2 || !tok3) + goto end; if (strlen(tok2) == 0 || strlen(tok3) == 0) - return; + goto end; bundle_add_str(info->extra, tok2, tok3); + +end: + if (tok1) + free(tok1); + if (tok2) + free(tok2); + if (tok3) + free(tok3); } static void __add_extra_array_from_list(bundle *b, const char *key, GList *list) @@ -155,8 +157,8 @@ static GList *__parse_file(GList *list, const char *path) { FILE *fp; char buf[LINE_MAX]; - char tok1[LINE_MAX]; - char tok2[LINE_MAX]; + char *tok1 = NULL; + char *tok2 = NULL; loader_info_t *cur_info = NULL; char *key = NULL; GList *extra_array = NULL; @@ -166,11 +168,10 @@ static GList *__parse_file(GList *list, const char *path) return list; while (fgets(buf, sizeof(buf), fp) != NULL) { - tok1[0] = '\0'; - tok2[0] = '\0'; - sscanf(buf, "%s %s", tok1, tok2); - - if (strcasecmp(TAG_LOADER, tok1) == 0) { + FREE_AND_NULL(tok1); + FREE_AND_NULL(tok2); + sscanf(buf, "%ms %ms", &tok1, &tok2); + if (tok1 && strcasecmp(TAG_LOADER, tok1) == 0) { if (cur_info != NULL) { __flush_extra_array(cur_info->extra, key, extra_array); @@ -182,6 +183,8 @@ static GList *__parse_file(GList *list, const char *path) continue; } + if (!tok1 || !tok2) + continue; if (tok1[0] == '\0' || tok2[0] == '\0' || tok1[0] == '#') continue; @@ -217,6 +220,11 @@ static GList *__parse_file(GList *list, const char *path) list = g_list_append(list, cur_info); } + if (tok1) + free(tok1); + if (tok2) + free(tok2); + fclose(fp); return list; -- 2.7.4