From fc51042078803d64afa940b8c953307a5468882f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 24 Apr 2017 08:45:32 +0900 Subject: [PATCH 01/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 02/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 03/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 04/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 05/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 06/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 07/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 08/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 From 49171d8ab6b314703ac7695792574469aa2b1228 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 12 Jun 2017 14:09:09 +0900 Subject: [PATCH 09/16] Add RUNTIME_TYPE to the environment Change-Id: I09b6dd1e1fe640190068d7dc3a090808d32b2796 Signed-off-by: Hwankyu Jhun --- src/launchpad_common.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/launchpad_common.c b/src/launchpad_common.c index 7f15619..e92e053 100644 --- a/src/launchpad_common.c +++ b/src/launchpad_common.c @@ -669,6 +669,8 @@ void _set_env(appinfo_t *menu_info, bundle *kb) setenv("AUL_APPID", menu_info->appid, 1); if (menu_info->pkgid != NULL) setenv("AUL_PKGID", menu_info->pkgid, 1); + if (menu_info->app_type != NULL) + setenv("RUNTIME_TYPE", menu_info->app_type, 1); str = bundle_get_val(kb, AUL_K_WAYLAND_DISPLAY); if (str != NULL) -- 2.7.4 From 1e968e27a00fa2deb014bbc70f1f873fee4e8780 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 13 Jun 2017 14:08:36 +0900 Subject: [PATCH 10/16] Release version 0.2.14 Changes: - Add RUNTIME_TYPE to the environment - Prevent buffer overflow - Fix log message about buxton error handling Change-Id: I4221e9a5b6a4d3574d57cbc38fdec879742bda79 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 fbae388..94750df 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.2.13 +Version: 0.2.14 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From df067d768d696beb856dc15798fda0e2d8263ec9 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 19 Jun 2017 14:19:25 +0900 Subject: [PATCH 11/16] Fix invalid format about dlog Change-Id: Ic74c58d5ef3e0b298c40f9619b933d91e312299a Signed-off-by: Hwankyu Jhun --- inc/preexec.h | 2 +- src/launchpad.c | 2 +- src/launchpad_debug.c | 2 +- src/launchpad_loader.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/preexec.h b/inc/preexec.h index 4b5b7cd..2cf7e86 100755 --- a/inc/preexec.h +++ b/inc/preexec.h @@ -97,7 +97,7 @@ static inline void __preexec_init(int argc, char **argv) free(type_t); continue; } - _D("preexec %s %s# - handle : %x\n", type, sopath, handle); + _D("preexec %s %s# - handle : %p\n", type, sopath, handle); func = dlsym(handle, symbol); if (func == NULL) { diff --git a/src/launchpad.c b/src/launchpad.c index a9a55b4..7dbf9d5 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -1421,7 +1421,7 @@ static gboolean __handle_launch_event(gpointer data) PERF("get package information & modify bundle done"); if (loader_id == PAD_LOADER_ID_DIRECT || cpc == NULL) { - _W("Launch directly %d %d", loader_id, cpc); + _W("Launch directly %d %p", loader_id, cpc); pid = __launch_directly(menu_info->appid, app_path, clifd, kb, menu_info, NULL); } else { diff --git a/src/launchpad_debug.c b/src/launchpad_debug.c index 5eacf14..aab6408 100644 --- a/src/launchpad_debug.c +++ b/src/launchpad_debug.c @@ -75,7 +75,7 @@ int _debug_create_extra_argv(int *argc, char ***argv) *argc = new_argc; *argv = new_argv; - _D("[DEBUG] argc: %d, i: %d", argc, i); + _D("[DEBUG] argc: %d, i: %d", *argc, i); return 0; } diff --git a/src/launchpad_loader.c b/src/launchpad_loader.c index 01487de..9a18f2e 100644 --- a/src/launchpad_loader.c +++ b/src/launchpad_loader.c @@ -158,7 +158,7 @@ static void __preload_lib(bundle *b) for (i = 0; i < len; i++) { handle = dlopen(so_array[i], RTLD_NOW | RTLD_NODELETE); - _D("preload %s# - handle : %x\n", so_array[i], handle); + _D("preload %s# - handle : %p\n", so_array[i], handle); } } -- 2.7.4 From 21b08bcf6999fd042281439f156f308df2bd27f7 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Mon, 19 Jun 2017 14:56:05 +0900 Subject: [PATCH 12/16] Separate threshold value for each slot - A threshold value should not affect other slots Change-Id: I3ed88b7866009515b7c5afb7110649bd7b4017f6 Signed-off-by: Junghoon Park --- src/launchpad.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/launchpad.c b/src/launchpad.c index 7dbf9d5..fde83a9 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -81,6 +81,7 @@ typedef struct { unsigned long long cpu_total_time; unsigned long long cpu_idle_time; guint idle_checker; + int threshold; } candidate_process_context_t; typedef struct { @@ -107,7 +108,6 @@ 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, @@ -1103,7 +1103,7 @@ static float __interpolator(float input) return ret; } -static void __update_threshold(float delta) +static void __update_threshold(candidate_process_context_t *cpc, float delta) { static float pos = 0.0f; @@ -1114,8 +1114,9 @@ static void __update_threshold(float delta) if (pos > 1.0f) pos = 1.0f; - __threshold = (int)(__interpolator(pos) * 100); - _D("[CPU] delta:%f / input cursor : %f / threshold : %d", delta, pos, __threshold); + cpc->threshold = (int)(__interpolator(pos) * 100); + _D("[CPU] type:%d / delta:%f / input cursor : %f / threshold : %d", + cpc->type, delta, pos, cpc->threshold); } static gboolean __handle_idle_checker(gpointer data) @@ -1132,8 +1133,8 @@ static gboolean __handle_idle_checker(gpointer data) per = (idle - cpc->cpu_idle_time) * 100 / (total - cpc->cpu_total_time); _D("[CPU] Idle : %d / type : %d", per, cpc->type); - if (per >= __threshold) { - __update_threshold(-0.02f * (per - __threshold)); + if (per >= cpc->threshold) { + __update_threshold(cpc, -0.02f * (per - cpc->threshold)); __prepare_candidate_process(cpc->type, cpc->loader_id); cpc->idle_checker = 0; return G_SOURCE_REMOVE; @@ -1141,7 +1142,7 @@ static gboolean __handle_idle_checker(gpointer data) cpc->cpu_idle_time = idle; cpc->cpu_total_time = total; - __update_threshold(0.05f); + __update_threshold(cpc, 0.05f); return G_SOURCE_CONTINUE; } @@ -1484,6 +1485,7 @@ static candidate_process_context_t *__add_slot(int type, int loader_id, cpc->cpu_total_time = 0; cpc->cpu_idle_time = 0; cpc->idle_checker = 0; + cpc->threshold = DEFAULT_THRESHOLD; fd = __listen_candidate_process(cpc->type, cpc->loader_id); if (fd == -1) { -- 2.7.4 From d1ba5db854d564f8b0a1b47aadc79e7c634c1e40 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 20 Jun 2017 14:05:25 +0900 Subject: [PATCH 13/16] Fix multiple delimiter - Add carriage return on delimiter Change-Id: Ib1cf6b6759ed53f3834ca5a616ed61a67326b0ac Signed-off-by: Hwankyu Jhun --- src/debugger_info.c | 4 ++-- src/launcher_info.c | 4 ++-- src/loader_info.c | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/debugger_info.c b/src/debugger_info.c index a7cdffc..e043e58 100644 --- a/src/debugger_info.c +++ b/src/debugger_info.c @@ -94,10 +94,10 @@ static void __parse_app_types(struct debugger_info_s *info, char *line) char *token; char *saveptr = NULL; - token = strtok_r(line, "\t |\n", &saveptr); + token = strtok_r(line, " |\t\r\n", &saveptr); while (token) { info->app_types = g_list_append(info->app_types, strdup(token)); - token = strtok_r(NULL, "\t |\n", &saveptr); + token = strtok_r(NULL, " |\t\r\n", &saveptr); } } diff --git a/src/launcher_info.c b/src/launcher_info.c index d8d9cc2..89a7ccd 100644 --- a/src/launcher_info.c +++ b/src/launcher_info.c @@ -74,10 +74,10 @@ static void __parse_app_types(struct launcher_info_s *info, char *line) char *token; char *saveptr = NULL; - token = strtok_r(line, "\t |\n", &saveptr); + token = strtok_r(line, " |\t\r\n", &saveptr); while (token) { info->app_types = g_list_append(info->app_types, strdup(token)); - token = strtok_r(NULL, "\t |\n", &saveptr); + token = strtok_r(NULL, " |\t\r\n", &saveptr); } } diff --git a/src/loader_info.c b/src/loader_info.c index b8ffb9a..889ab1d 100644 --- a/src/loader_info.c +++ b/src/loader_info.c @@ -64,7 +64,7 @@ static void __parse_detection_method(loader_info_t *info, char *line) char *token; char *savedptr; - token = strtok_r(line, "\t |\n", &savedptr); + token = strtok_r(line, " |\t\r\n", &savedptr); info->detection_method = 0; while (token) { if (!strcmp(token, VAL_METHOD_TIMEOUT)) @@ -74,7 +74,7 @@ static void __parse_detection_method(loader_info_t *info, char *line) else if (!strcmp(token, VAL_METHOD_DEMAND)) info->detection_method |= METHOD_DEMAND; - token = strtok_r(NULL, "\t |\n", &savedptr); + token = strtok_r(NULL, " |\t\r\n", &savedptr); } _D("detection_method:%d", info->detection_method); @@ -85,10 +85,10 @@ static void __parse_app_types(loader_info_t *info, char *line) char *token; char *savedptr; - token = strtok_r(line, "\t |\n", &savedptr); + token = strtok_r(line, " |\t\r\n", &savedptr); while (token) { info->app_types = g_list_append(info->app_types, strdup(token)); - token = strtok_r(NULL, "\t |\n", &savedptr); + token = strtok_r(NULL, " |\t\r\n", &savedptr); } } -- 2.7.4 From c456df895dc05cb2136ae2d24de564b3d4c455ec Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 20 Jun 2017 18:24:46 +0900 Subject: [PATCH 14/16] Fix exception handling about label monitor Even though label monitor initialization is failed, the launchpad doesn't stop initializing. And, if the loader has cap_mac_admin cap, the launchpad will prepare the loader process to execute an application for improving launch performance. When the label_monitor variable is null, the launchpad checks wheather the loader has cap_mac_admin cap or NOT. Change-Id: Ic8103e1897e38e4e7ded96e9c78551bd64776b8a Signed-off-by: Hwankyu Jhun --- CMakeLists.txt | 1 + inc/launchpad_common.h | 2 ++ packaging/launchpad.spec | 1 + src/launchpad.c | 87 ++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 77 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a03d54..a742c61 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ PKG_CHECK_MODULES(${this_target_pool} REQUIRED ttrace vconf libtzplatform-config + libcap ) FOREACH(flag ${${this_target_pool}_CFLAGS}) diff --git a/inc/launchpad_common.h b/inc/launchpad_common.h index c7c1012..5bc4142 100644 --- a/inc/launchpad_common.h +++ b/inc/launchpad_common.h @@ -65,6 +65,8 @@ } \ } while (0) +#define ARRAY_SIZE(x) ((sizeof(x)) / sizeof(x[0])) + enum loader_arg { LOADER_ARG_PATH, LOADER_ARG_TYPE, diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 94750df..9d3f09f 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -22,6 +22,7 @@ BuildRequires: pkgconfig(security-manager) BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(ttrace) BuildRequires: pkgconfig(libtzplatform-config) +BuildRequires: pkgconfig(libcap) Requires(post): /sbin/ldconfig Requires(post): /usr/bin/systemctl diff --git a/src/launchpad.c b/src/launchpad.c index fde83a9..a415891 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -1586,29 +1587,86 @@ static int __init_sigchild_fd(void) static int __init_label_monitor_fd(void) { + int r; int fd = -1; guint pollfd; - if (security_manager_app_labels_monitor_init(&label_monitor) - != SECURITY_MANAGER_SUCCESS) - return -1; - if (security_manager_app_labels_monitor_process(label_monitor) - != SECURITY_MANAGER_SUCCESS) + r = security_manager_app_labels_monitor_init(&label_monitor); + if (r != SECURITY_MANAGER_SUCCESS) return -1; - security_manager_app_labels_monitor_get_fd(label_monitor, &fd); + r = security_manager_app_labels_monitor_process(label_monitor); + if (r != SECURITY_MANAGER_SUCCESS) + goto err; + + security_manager_app_labels_monitor_get_fd(label_monitor, &fd); if (fd < 0) { _E("failed to get fd"); - return -1; + goto err; } pollfd = __poll_fd(fd, G_IO_IN, (GSourceFunc)__handle_label_monitor, 0, 0); - if (pollfd == 0) { + if (pollfd == 0) + goto err; + + return 0; + +err: + if (fd > 0) close(fd); + + if (label_monitor) { + security_manager_app_labels_monitor_finish(label_monitor); + label_monitor = NULL; + } + + return -1; +} + +static int __verify_loader_caps(const char *loader) +{ + cap_t cap_d; + cap_flag_value_t eff_state; + cap_flag_value_t inh_state; + cap_value_t values[] = {CAP_SETGID, CAP_MAC_ADMIN}; + int r; + int i; + int size = ARRAY_SIZE(values); + + /* If Dytransition feature is enabled, CAP_MAC_ADMIN is unnecessary */ + if (label_monitor) + size--; + + cap_d = cap_get_file(loader); + if (!cap_d) { + _E("Failed to get cap from file(%s)", loader); return -1; } + for (i = 0; i < size; i++) { + r = cap_get_flag(cap_d, values[i], CAP_INHERITABLE, &inh_state); + if (r != 0) { + _E("Failed to get cap inh - errno(%d)", errno); + cap_free(cap_d); + return -1; + } + + r = cap_get_flag(cap_d, values[i], CAP_EFFECTIVE, &eff_state); + if (r != 0) { + _E("Failed to get cap eff - errno(%d)", errno); + cap_free(cap_d); + return -1; + } + + if ((inh_state != CAP_SET) || (eff_state != CAP_SET)) { + _E("The %s doesn't have %d cap", loader, values[i]); + cap_free(cap_d); + return -1; + } + } + cap_free(cap_d); + return 0; } @@ -1634,6 +1692,9 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) } if (access(info->exe, F_OK | X_OK) == 0) { + if (__verify_loader_caps(info->exe) < 0) + return; + if (info->extra) bundle_encode(info->extra, &extra, &len); @@ -1697,12 +1758,6 @@ static int __before_loop(int argc, char **argv) return -1; } - ret = __init_label_monitor_fd(); - if (ret != 0) { - _E("__init_launchpad_fd() failed"); - return -1; - } - ret = vconf_get_int(VCONFKEY_SETAPPL_APP_HW_ACCELERATION, &__sys_hwacc); if (ret != VCONF_OK) { _E("Failed to get vconf int: %s", @@ -1716,6 +1771,10 @@ static int __before_loop(int argc, char **argv) VCONFKEY_SETAPPL_APP_HW_ACCELERATION); } + ret = __init_label_monitor_fd(); + if (ret != 0) + _W("Failed to initialize label monitor"); + __add_default_slots(); launcher_info_list = _launcher_info_load(LAUNCHER_INFO_PATH); -- 2.7.4 From 472687ed23e09743a0b82e394fa1b2d6836f61c6 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 21 Jun 2017 15:21:58 +0900 Subject: [PATCH 15/16] Remove unnecessary exception Currently AUL_K_PRIVACY_APPID key is not used. Change-Id: If78a9729d3d5878e34ab89e8ae3d4c814e1d0188 Signed-off-by: Hwankyu Jhun --- inc/key.h | 1 - src/launchpad.c | 8 +++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/inc/key.h b/inc/key.h index 98647e0..ce8457c 100644 --- a/inc/key.h +++ b/inc/key.h @@ -32,7 +32,6 @@ extern "C" { #define AUL_K_INTERNAL_POOL "__AUL_INTERNAL_POOL__" #define AUL_K_PKGID "__AUL_PKGID_" #define AUL_K_DEBUG "__AUL_DEBUG__" -#define AUL_K_PRIVACY_APPID "__AUL_PRIVACY_APPID__" #define AUL_K_COMP_TYPE "__AUL_COMP_TYPE__" #define AUL_K_CALLER_PID "__AUL_CALLER_PID__" #define AUL_K_LOADER_ID "__AUL_LOADER_ID__" diff --git a/src/launchpad.c b/src/launchpad.c index a415891..3b06c24 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -714,11 +714,9 @@ static int __prepare_exec(const char *appid, const char *app_path, setsid(); /* SET PRIVILEGES*/ - if (bundle_get_val(kb, AUL_K_PRIVACY_APPID) == NULL) { - ret = security_manager_prepare_app(appid); - if (ret != SECURITY_MANAGER_SUCCESS) - return PAD_ERR_REJECTED; - } + ret = security_manager_prepare_app(appid); + if (ret != SECURITY_MANAGER_SUCCESS) + return PAD_ERR_REJECTED; _send_cmd_to_amd(APP_STARTUP_SIGNAL); if (bundle_get_type(kb, AUL_K_SDK) == BUNDLE_TYPE_NONE) -- 2.7.4 From 4f66235f8764fafa835c66fa96f4abf76ce8ee0a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 23 Jun 2017 13:33:06 +0900 Subject: [PATCH 16/16] Release version 0.2.15 Changes: - Remove unnecessary exception - Fix exception handling about label monitor - Fix multiple delimiter - Separate threshold value for each slot - Fix invalid format about dlog Change-Id: I1b91cdb72c5654ad11320dd6c7cc823a067294c9 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 9d3f09f..4bc6b04 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.2.14 +Version: 0.2.15 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4