From 68ca0f7d8074e8b54dd3dbd44f0e15aae948d1a0 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Fri, 3 Jun 2016 21:30:09 +0900 Subject: [PATCH 01/16] Use script file for making launchpad-loader Change-Id: I1794da64cb448381c404c89acbd618d93fd93ac6 Signed-off-by: Junghoon Park --- CMakeLists.txt | 5 +- inc/launchpad.h | 1 - inc/loader_info.h | 10 +- inc/preload.h | 162 --------------- inc/process_pool_preload.h | 115 ----------- packaging/default.loader | 19 -- packaging/default.loader.in | 55 ++++++ packaging/launchpad-process-pool-preload-list.txt | 0 packaging/launchpad.spec | 2 - packaging/preload_list.txt.in | 4 - src/launchpad.c | 144 ++++++++------ src/launchpad_lib.c | 2 + src/launchpad_loader.c | 129 ++++++++++-- src/loader_info.c | 231 ++++++++++++++++++++-- 14 files changed, 482 insertions(+), 397 deletions(-) delete mode 100644 inc/preload.h delete mode 100644 inc/process_pool_preload.h delete mode 100644 packaging/default.loader create mode 100644 packaging/default.loader.in delete mode 100644 packaging/launchpad-process-pool-preload-list.txt delete mode 100644 packaging/preload_list.txt.in diff --git a/CMakeLists.txt b/CMakeLists.txt index ac63d95..d5f0cbe 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ PKG_CHECK_MODULES(${this_target_pool} REQUIRED bundle gio-2.0 ttrace + vconf ) FOREACH(flag ${${this_target_pool}_CFLAGS}) @@ -107,9 +108,7 @@ SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL} INSTALL(TARGETS ${LAUNCHPAD_PROCESS_POOL} DESTINATION bin) -CONFIGURE_FILE(packaging/preload_list.txt.in packaging/preload_list.txt @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/preload_list.txt DESTINATION share/aul) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/launchpad-process-pool-preload-list.txt DESTINATION share/aul) +CONFIGURE_FILE(packaging/default.loader.in packaging/default.loader @ONLY) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/default.loader DESTINATION share/aul) # liblaunchpad diff --git a/inc/launchpad.h b/inc/launchpad.h index 5f8364a..fb2cabf 100644 --- a/inc/launchpad.h +++ b/inc/launchpad.h @@ -51,7 +51,6 @@ typedef struct { enum LAUNCHPAD_TYPE { LAUNCHPAD_TYPE_UNSUPPORTED = -1, - LAUNCHPAD_TYPE_HW, LAUNCHPAD_TYPE_USER, LAUNCHPAD_TYPE_DYNAMIC = 100, LAUNCHPAD_TYPE_MAX diff --git a/inc/loader_info.h b/inc/loader_info.h index 4ee7c80..950aa3c 100644 --- a/inc/loader_info.h +++ b/inc/loader_info.h @@ -18,6 +18,7 @@ #include #include +#include #define METHOD_TIMEOUT 0x1 #define METHOD_VISIBILITY 0x2 @@ -27,14 +28,17 @@ typedef struct _loader_info { int type; char *name; char *exe; - char *app_type; + GList *app_types; int detection_method; int timeout_val; + char *hw_acc; + GList *alternative_loaders; + bundle *extra; } loader_info_t; GList *_loader_info_load(const char *path); void _loader_info_dispose(GList *info); -int _loader_info_find_type_by_app_type(GList *info, const char *app_type); - +int _loader_info_find_type(GList *info, const char *app_type, bool hwacc); +int *_loader_get_alternative_types(GList *info, int type, int *len); diff --git a/inc/preload.h b/inc/preload.h deleted file mode 100644 index c4dac2a..0000000 --- a/inc/preload.h +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifdef PRELOAD_ACTIVATE - -#include -#define PRELOAD_FILE SHARE_PREFIX"/preload_list.txt" - -#define EFL_PREINIT_FUNC "elm_quicklaunch_init" -#define EFL_SHUTDOWN_FUNC "elm_quicklaunch_shutdown" - -static int preload_initialized = 0; -static int g_argc; -static char **g_argv; -static int max_cmdline_size = 0; - -static int (*dl_einit) () = NULL; -static int (*dl_efini) () = NULL; - -static inline void __preload_init(int argc, char **argv) -{ - void *handle = NULL; - char soname[MAX_LOCAL_BUFSZ]; - FILE *preload_list; - int (*func)() = NULL; - int i; - - g_argc = argc; - g_argv = argv; - for (i = 0; i < argc; i++) { - max_cmdline_size += (strlen(argv[i]) + 1); - } - _D("max_cmdline_size = %d", max_cmdline_size); - - preload_list = fopen(PRELOAD_FILE, "rt"); - if (preload_list == NULL) { - _E("no preload\n"); - return; - } - - while (fgets(soname, MAX_LOCAL_BUFSZ, preload_list) > 0) { - soname[strlen(soname) - 1] = 0; - handle = dlopen((const char *) soname, RTLD_NOW); - if (handle == NULL) - continue; - _D("preload %s# - handle : %x\n", soname, handle); - - func = dlsym(handle, EFL_PREINIT_FUNC); - if (func != NULL) { - _D("get pre-initialization function\n"); - dl_einit = func; - func = dlsym(handle, EFL_SHUTDOWN_FUNC); - if (func != NULL) { - _D("get shutdown function\n"); - dl_efini = func; - } - } - } - - fclose(preload_list); - preload_initialized = 1; -} - -static inline int preinit_init() -{ - if (dl_einit != NULL) - dl_einit(0, NULL); - _D("pre-initialzation on"); - return 0; -} - -static inline int preinit_fini() -{ - if (dl_efini != NULL) - dl_efini(); - _D("pre-initialization off"); - return 0; -} - -/* TODO : how to set cmdline gracefully ?? */ -static inline int __change_cmdline(char *cmdline) -{ - if (strlen(cmdline) > max_cmdline_size + 1) { - _E("cmdline exceed max size : %d", max_cmdline_size); - return -1; - } - - memset(g_argv[0], '\0', max_cmdline_size); - snprintf(g_argv[0], max_cmdline_size, "%s", cmdline); - - return 0; -} - -static inline void __preload_exec(int argc, char **argv) -{ - void *handle = NULL; - int (*dl_main)(int, char **); - char *error = NULL; - - if (!preload_initialized) - return; - - handle = dlopen(argv[0], RTLD_LAZY | RTLD_GLOBAL); - if (handle == NULL) { - _E("dlopen(\"%s\") failed", argv[0]); - if ((error = dlerror()) != NULL) { - _E("dlopen error: %s", error); - } - return; - } - - dlerror(); - - dl_main = dlsym(handle, "main"); - if (dl_main != NULL) { - if (__change_cmdline(argv[0]) < 0) { - _E("change cmdline fail"); - dlclose(handle); - return; - } - -#ifdef _APPFW_FEATURE_PRIORITY_CHANGE - if (setpriority(PRIO_PROCESS, 0, 0) == -1) { - SECURE_LOGE("Setting process (%d) priority to 0 failed," - " errno: %d (%s)", - getpid(), errno, strerror(errno)); - } -#endif - dl_main(argc, argv); - } else { - _E("dlsym not founded. bad preloaded app - check fpie pie"); - if ((error = dlerror()) != NULL) { - _E("dlsym error: %s", error); - } - dlclose(handle); - return; - } - - exit(0); -} - -#else - -static inline void __preload_init(); -static inline void __preload_exec(int argc, char **argv); - -#endif - diff --git a/inc/process_pool_preload.h b/inc/process_pool_preload.h deleted file mode 100644 index aa84e51..0000000 --- a/inc/process_pool_preload.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __PROCESS_POOL_PRELOAD_H__ -#define __PROCESS_POOL_PRELOAD_H__ - -#include -#include -#include -#include - -#define PROCESS_POOL_PRELOAD_FILE \ - SHARE_PREFIX"/launchpad-process-pool-preload-list.txt" - -static int g_dlopen_size = 5; -static int g_dlopen_count = 0; -static void **g_dlopen_handle_list = NULL; - -static inline int __preload_save_dlopen_handle(void *handle) -{ - void **tmp; - - if (!handle) - return 1; - - if (g_dlopen_count == g_dlopen_size || !g_dlopen_handle_list) { - tmp = realloc(g_dlopen_handle_list, - 2 * g_dlopen_size * sizeof(void *)); - if (tmp == NULL) { - _E("out of memory\n"); - dlclose(handle); - return 1; - } - g_dlopen_size *= 2; - g_dlopen_handle_list = tmp; - } - g_dlopen_handle_list[g_dlopen_count++] = handle; - return 0; -} - -static inline void __preload_fini_for_process_pool(void) -{ - int i = 0; - void *handle; - - if (!g_dlopen_handle_list) - return; - - for (i = 0; i < g_dlopen_count; ++i) { - handle = g_dlopen_handle_list[i]; - if (handle) { - if (0 != dlclose(handle)) - _E("dlclose failed\n"); - } - } - free(g_dlopen_handle_list); - g_dlopen_handle_list = NULL; - g_dlopen_size = 5; - g_dlopen_count = 0; -} - -static inline void __preload_init_for_process_pool(void) -{ - void *handle = NULL; - char soname[MAX_LOCAL_BUFSZ] = { 0, }; - FILE *preload_list = NULL; - size_t len; - - if (atexit(__preload_fini_for_process_pool) != 0) { - _E("Cannot register atexit callback. " - "Libraries will not be unloaded"); - } - - preload_list = fopen(PROCESS_POOL_PRELOAD_FILE, "rt"); - if (preload_list == NULL) { - _E("no preload\n"); - return; - } - - while (fgets(soname, MAX_LOCAL_BUFSZ, preload_list) > 0) { - len = strnlen(soname, MAX_LOCAL_BUFSZ); - if (len > 0) - soname[len - 1] = '\0'; - - handle = dlopen((const char *) soname, RTLD_NOW); - if (handle == NULL) { - _E("dlopen(\"%s\") was failed!", soname); - continue; - } - - if (__preload_save_dlopen_handle(handle) != 0) { - _E("Cannot save handle, no more preloads"); - break; - } - _D("preload %s# - handle : %x\n", soname, handle); - } - - fclose(preload_list); -} - -#endif /* __PROCESS_POOL_PRELOAD_H__ */ - diff --git a/packaging/default.loader b/packaging/default.loader deleted file mode 100644 index 042973e..0000000 --- a/packaging/default.loader +++ /dev/null @@ -1,19 +0,0 @@ -[LOADER] -NAME wrt-loader -EXE /usr/bin/wrt-loader -APP_TYPE webapp -DETECTION_METHOD TIMEOUT|DEMAND -TIMEOUT 5000 - -[LOADER] -NAME jsnative-loader -EXE /usr/bin/jsnative-loader -APP_TYPE jsapp -DETECTION_METHOD TIMEOUT|VISIBILITY -TIMEOUT 5000 - -[LOADER] -NAME cs-loader -EXE null -APP_TYPE csapp - diff --git a/packaging/default.loader.in b/packaging/default.loader.in new file mode 100644 index 0000000..1c90a68 --- /dev/null +++ b/packaging/default.loader.in @@ -0,0 +1,55 @@ +[LOADER] +NAME wrt-loader +EXE /usr/bin/wrt-loader +APP_TYPE webapp +DETECTION_METHOD TIMEOUT|DEMAND +TIMEOUT 5000 + +[LOADER] +NAME jsnative-loader +EXE /usr/bin/jsnative-loader +APP_TYPE jsapp +DETECTION_METHOD TIMEOUT|VISIBILITY +TIMEOUT 5000 + +[LOADER] +NAME cs-loader +EXE null +APP_TYPE csapp + +[LOADER] +NAME hw-loader1 +EXE /usr/bin/launchpad-loader +APP_TYPE capp|c++app +HW_ACC ON +DETECTION_METHOD TIMEOUT|VISIBILITY +TIMEOUT 5000 +EXTRA loader_type hw-loader +EXTRA_ARRAY preload +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libappcore-efl.so.1 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libappcore-common.so.1 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libcapi-appfw-application.so.0 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/ecore_imf/modules/wayland/v-1.16/libwltextinputmodule.so +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libdali-toolkit.so +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libcairo.so.2 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libefl-assist.so.0 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libcapi-media-player.so.0 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libcapi-media-camera.so.0 +ALTERNATIVE_LOADER common-loader1 + +[LOADER] +NAME common-loader1 +EXE /usr/bin/launchpad-loader +APP_TYPE capp|c++app +DETECTION_METHOD TIMEOUT|VISIBILITY +TIMEOUT 5000 +EXTRA loader_type common-loader +EXTRA_ARRAY preload +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libappcore-efl.so.1 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libappcore-common.so.1 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libcapi-appfw-application.so.0 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/ecore_imf/modules/wayland/v-1.16/libwltextinputmodule.so +ALTERNATIVE_LOADER hw-loader1 + + + diff --git a/packaging/launchpad-process-pool-preload-list.txt b/packaging/launchpad-process-pool-preload-list.txt deleted file mode 100644 index e69de29..0000000 diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index f5db9b8..53613dd 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -77,8 +77,6 @@ cp %{_builddir}/%{name}-%{version}/LICENSE %{buildroot}/usr/share/license/%{nam %files %manifest launchpad.manifest %{_prefix}/share/license/%{name} -%{_prefix}/share/aul/preload_list.txt -%{_prefix}/share/aul/launchpad-process-pool-preload-list.txt %{_prefix}/share/aul/default.loader %{_unitdir_user}/launchpad-process-pool.service %{_unitdir_user}/launchpad-process-pool.socket diff --git a/packaging/preload_list.txt.in b/packaging/preload_list.txt.in deleted file mode 100644 index fa29fb6..0000000 --- a/packaging/preload_list.txt.in +++ /dev/null @@ -1,4 +0,0 @@ -@LIB_INSTALL_DIR@/libappcore-efl.so.1 -@LIB_INSTALL_DIR@/libappcore-common.so.1 -@LIB_INSTALL_DIR@/libcapi-appfw-application.so.0 -@LIB_INSTALL_DIR@/ecore_imf/modules/wayland/v-1.16/libwltextinputmodule.so diff --git a/src/launchpad.c b/src/launchpad.c index fad964a..54c4554 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "perf.h" #include "launchpad_common.h" @@ -71,6 +72,7 @@ typedef struct { int loader_id; } loader_context_t; +static int __sys_hwacc; static GList *loader_info_list; static int user_slot_offset; static GList *candidate_slot_list; @@ -283,18 +285,6 @@ static int __set_access(const char *appid) return security_manager_prepare_app(appid); } -static int __get_launchpad_type(const char *internal_pool, const char *hwacc, - const char *app_type) -{ - int type; - - type = _loader_info_find_type_by_app_type(loader_info_list, app_type); - if (type >= LAUNCHPAD_TYPE_USER) - return type; - - return LAUNCHPAD_TYPE_HW; -} - static int __get_loader_id(bundle *kb) { const char *val; @@ -911,6 +901,51 @@ static int __check_caller_by_pid(int pid) return -1; } +static bool __is_hw_acc(const char *hwacc) +{ + if (strcmp(hwacc, "USE") == 0 || + (strcmp(hwacc, "SYS") == 0 && + __sys_hwacc == SETTING_HW_ACCELERATION_ON)) + return true; + + return false; +} + +static candidate_process_context_t *__find_available_slot(const char *hwacc, + const char *app_type) +{ + int type; + candidate_process_context_t *cpc; + int *a_types; + int len = 0; + int i; + + type = _loader_info_find_type(loader_info_list, app_type, __is_hw_acc(hwacc)); + cpc = __find_slot(type, PAD_LOADER_ID_STATIC); + if (!cpc) + return NULL; + + if (cpc->prepared) + return cpc; + + a_types = _loader_get_alternative_types(loader_info_list, type, &len); + if (!a_types) + return NULL; + + for (i = 0; i < len; i++) { + cpc = __find_slot(a_types[i], PAD_LOADER_ID_STATIC); + if (!cpc) + continue; + if (cpc->prepared) { + free(a_types); + return cpc; + } + } + + free(a_types); + return NULL; +} + static gboolean __handle_launch_event(gpointer data) { loader_context_t *lc = (loader_context_t *) data; @@ -918,7 +953,7 @@ static gboolean __handle_launch_event(gpointer data) bundle *kb = NULL; app_pkt_t *pkt = NULL; appinfo_t *menu_info = NULL; - candidate_process_context_t *cpc; + candidate_process_context_t *cpc = NULL; const char *app_path = NULL; int pid = -1; int clifd = -1; @@ -1006,21 +1041,15 @@ static gboolean __handle_launch_event(gpointer data) SECURE_LOGD("app_type : %s\n", menu_info->app_type); SECURE_LOGD("pkg_type : %s\n", menu_info->pkg_type); - if ((loader_id = __get_loader_id(kb)) <= PAD_LOADER_ID_STATIC) { - type = __get_launchpad_type(menu_info->internal_pool, - menu_info->hwacc, menu_info->app_type); - if (type < 0) { - _E("failed to get launchpad type"); - goto end; - } - if (menu_info->comp_type && - strcmp(menu_info->comp_type, "svcapp") == 0) - loader_id = PAD_LOADER_ID_DIRECT; - else - loader_id = PAD_LOADER_ID_STATIC; + if (menu_info->comp_type && + strcmp(menu_info->comp_type, "svcapp") == 0) { + loader_id = PAD_LOADER_ID_DIRECT; + } else if ((loader_id = __get_loader_id(kb)) <= PAD_LOADER_ID_STATIC) { + cpc = __find_available_slot(menu_info->hwacc, menu_info->app_type); } else { type = LAUNCHPAD_TYPE_DYNAMIC; + cpc = __find_slot(type, loader_id); } _modify_bundle(kb, cr.pid, menu_info, pkt->cmd); @@ -1031,21 +1060,13 @@ static gboolean __handle_launch_event(gpointer data) PERF("get package information & modify bundle done"); - if (loader_id == PAD_LOADER_ID_DIRECT || - (cpc = __find_slot(type, loader_id)) == NULL) { - _W("Launch directly"); + if (loader_id == PAD_LOADER_ID_DIRECT || cpc == NULL) { + _W("Launch directly %d %d", loader_id, cpc); pid = __launch_directly(menu_info->appid, app_path, clifd, kb, menu_info, NULL); } else { - if (cpc->prepared) { - _W("Launch %d type process", type); - pid = __send_launchpad_loader(cpc, pkt, app_path, - clifd); - } else { - _W("Launch directly"); - pid = __launch_directly(menu_info->appid, app_path, - clifd, kb, menu_info, cpc); - } + _W("Launch %d type process", cpc->type); + pid = __send_launchpad_loader(cpc, pkt, app_path, clifd); } __send_result_to_caller(clifd, pid, app_path); @@ -1200,6 +1221,8 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) { loader_info_t *info = (loader_info_t *)data; candidate_process_context_t *cpc; + bundle_raw *extra = NULL; + int len; if (!strcmp(info->exe, "null")) { cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset, PAD_LOADER_ID_DIRECT, @@ -1213,8 +1236,11 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) } if (access(info->exe, F_OK | X_OK) == 0) { + if (info->extra) + bundle_encode(info->extra, &extra, &len); + cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset, PAD_LOADER_ID_STATIC, - 0, info->exe, NULL, info->detection_method, info->timeout_val); + 0, info->exe, (char *)extra, info->detection_method, info->timeout_val); if (cpc == NULL) return; @@ -1227,7 +1253,7 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) } } -static void __add_default_slots_from_file(void) +static int __add_default_slots(void) { if (loader_info_list) _loader_info_dispose(loader_info_list); @@ -1235,30 +1261,23 @@ static void __add_default_slots_from_file(void) loader_info_list = _loader_info_load(LOADER_INFO_PATH); if (loader_info_list == NULL) - return; + return -1; user_slot_offset = 0; g_list_foreach(loader_info_list, __add_slot_from_info, NULL); + + return 0; } -static int __add_default_slots(void) +static void __vconf_cb(keynode_t *key, void *data) { - candidate_process_context_t *cpc; - int ret; - - cpc = __add_slot(LAUNCHPAD_TYPE_HW, PAD_LOADER_ID_STATIC, 0, - LOADER_PATH_DEFAULT, NULL, - METHOD_TIMEOUT | METHOD_VISIBILITY, 5000); - if (cpc == NULL) - return -1; - - ret = __prepare_candidate_process(LAUNCHPAD_TYPE_HW, - PAD_LOADER_ID_STATIC); - if (ret != 0) - return -1; + const char *name; - __add_default_slots_from_file(); - return 0; + name = vconf_keynode_get_name(key); + if (name && strcmp(name, VCONFKEY_SETAPPL_APP_HW_ACCELERATION) == 0) { + __sys_hwacc = vconf_keynode_get_int(key); + _D("sys hwacc: %d", __sys_hwacc); + } } static int __before_loop(int argc, char **argv) @@ -1277,6 +1296,19 @@ static int __before_loop(int argc, char **argv) return -1; } + ret = vconf_get_int(VCONFKEY_SETAPPL_APP_HW_ACCELERATION, &__sys_hwacc); + if (ret != VCONF_OK) { + _E("Failed to get vconf int: %s", + VCONFKEY_SETAPPL_APP_HW_ACCELERATION); + } + + ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_APP_HW_ACCELERATION, + __vconf_cb, NULL); + if (ret != 0) { + _E("Failed to register callback for %s", + VCONFKEY_SETAPPL_APP_HW_ACCELERATION); + } + return 0; } diff --git a/src/launchpad_lib.c b/src/launchpad_lib.c index 7ca5aab..f655ed6 100644 --- a/src/launchpad_lib.c +++ b/src/launchpad_lib.c @@ -21,6 +21,7 @@ #include #include #include +#include #ifdef _APPFW_FEATURE_LOADER_PRIORITY #include #include @@ -351,6 +352,7 @@ static int __before_loop(int argc, char **argv) if (extra) bundle_free(extra); + malloc_trim(0); #ifdef _APPFW_FEATURE_LOADER_PRIORITY res = setpriority(PRIO_PGRP, 0, 0); if (res == -1) { diff --git a/src/launchpad_loader.c b/src/launchpad_loader.c index 0c19f91..fbde22a 100644 --- a/src/launchpad_loader.c +++ b/src/launchpad_loader.c @@ -29,10 +29,14 @@ #include #include "launchpad_common.h" -#include "preload.h" -#include "process_pool_preload.h" #include "launchpad.h" +#define KEY_LOADER_TYPE "loader_type" +#define LOADER_TYPE_COMMON "common-loader" +#define LOADER_TYPE_HW "hw-loader" +#define LOADER_TYPE_SW "sw-loader" + + extern bundle *launchpad_loader_get_bundle(); static Ecore_Fd_Handler *__fd_handler; @@ -44,6 +48,22 @@ static int __sys_hwacc; static Evas_Object *__win; static Evas_Object *__bg; static Evas_Object *__conform; +static int __type; + +enum loader_type { + TYPE_COMMON, + TYPE_SW, + TYPE_HW, + MAX_LOADER_TYPE +}; + +enum acc_type { + SW_ACC, + HW_ACC, + MAX_ACC_TYPE +}; + +typedef void (*loader_convertible)(void); static void __vconf_cb(keynode_t *key, void *data) { @@ -56,6 +76,18 @@ static void __vconf_cb(keynode_t *key, void *data) } } +static void __init_theme(void) +{ + char *theme = elm_theme_list_item_path_get(eina_list_data_get( + elm_theme_list_get(NULL)), NULL); + Eina_Bool is_exist = edje_file_group_exists(theme, "*"); + if (!is_exist) + _D("theme path: %s", theme); + + if (theme) + free(theme); +} + static void __init_window(void) { __win = elm_win_add(NULL, "package_name", ELM_WIN_BASIC); @@ -89,6 +121,8 @@ static void __init_window(void) static void __fini_window(void) { + _D("Drop window"); + if (__conform) { evas_object_del(__conform); elm_conformant_precreated_object_set(NULL); @@ -108,19 +142,74 @@ static void __fini_window(void) } } +static void __preload_lib(bundle *b) +{ + void *handle = NULL; + int i; + int len = 0; + const char **so_array; + + if (!b) + return; + + so_array = bundle_get_str_array(b, "preload", &len); + + if (!so_array) + return; + + for (i = 0; i < len; i++) { + handle = dlopen(so_array[i], RTLD_NOW); + _D("preload %s# - handle : %x\n", so_array[i], handle); + } +} + static void __loader_create_cb(bundle *extra, int type, void *user_data) { int elm_init_cnt = 0; int ret; + char *ltype = NULL; + + if (extra == NULL) { + _E("No extra data"); + return; + } + + bundle_get_str(extra, KEY_LOADER_TYPE, <ype); + + if (ltype == NULL) { + _E("No loader type"); + return; + } - __preload_init(__argc, __argv); - __preload_init_for_process_pool(); + if (!strcmp(LOADER_TYPE_COMMON, ltype)) + __type = TYPE_COMMON; + else if (!strcmp(LOADER_TYPE_SW, ltype)) + __type = TYPE_SW; + else if (!strcmp(LOADER_TYPE_HW, ltype)) + __type = TYPE_HW; + + _D("Loader type:%d", __type); + + __preload_lib(extra); elm_init_cnt = elm_init(__argc, __argv); _D("[candidate] elm init, returned: %d", elm_init_cnt); - elm_config_accel_preference_set("hw"); - __init_window(); + switch (__type) { + case TYPE_SW: + elm_config_accel_preference_set("none"); + __init_window(); + break; + + case TYPE_HW: + elm_config_accel_preference_set("hw"); + __init_window(); + break; + + default: + __init_theme(); + break; + } ret = vconf_get_int(VCONFKEY_SETAPPL_APP_HW_ACCELERATION, &__sys_hwacc); if (ret != VCONF_OK) { @@ -134,15 +223,24 @@ static void __loader_create_cb(bundle *extra, int type, void *user_data) _E("Failed to register callback for %s", VCONFKEY_SETAPPL_APP_HW_ACCELERATION); } - malloc_trim(0); } +static loader_convertible __converter_table[MAX_LOADER_TYPE][MAX_ACC_TYPE] = { + [TYPE_COMMON][SW_ACC] = NULL, + [TYPE_COMMON][HW_ACC] = NULL, + [TYPE_SW][SW_ACC] = NULL, + [TYPE_SW][HW_ACC] = __fini_window, + [TYPE_HW][SW_ACC] = __fini_window, + [TYPE_HW][HW_ACC] = NULL, +}; + static int __loader_launch_cb(int argc, char **argv, const char *app_path, const char *appid, const char *pkgid, const char *pkg_type, void *user_data) { const char *hwacc; bundle *kb = launchpad_loader_get_bundle(); + int acc = SW_ACC; vconf_ignore_key_changed(VCONFKEY_SETAPPL_APP_HW_ACCELERATION, __vconf_cb); if (kb == NULL) @@ -153,18 +251,15 @@ static int __loader_launch_cb(int argc, char **argv, const char *app_path, if (!hwacc) return 0; - if (strcmp(hwacc, "USE") == 0) { - _D("Use preinitialized window"); - return 0; - } else if (strcmp(hwacc, "SYS") == 0 && - __sys_hwacc == SETTING_HW_ACCELERATION_ON) { - _D("Use preinitialized window"); - return 0; + if (strcmp(hwacc, "USE") == 0 || + (strcmp(hwacc, "SYS") == 0 && + __sys_hwacc == SETTING_HW_ACCELERATION_ON)) { + acc = HW_ACC; } - _D("Dispose window"); - __fini_window(); - elm_config_accel_preference_set("none"); + loader_convertible convert = __converter_table[__type][acc]; + if (convert) + convert(); return 0; } diff --git a/src/loader_info.c b/src/loader_info.c index cfcab66..fc86f29 100644 --- a/src/loader_info.c +++ b/src/loader_info.c @@ -30,10 +30,18 @@ #define TAG_APP_TYPE "APP_TYPE" #define TAG_DETECTION_METHOD "DETECTION_METHOD" #define TAG_TIMEOUT "TIMEOUT" +#define TAG_EXTRA "EXTRA" +#define TAG_EXTRA_ARRAY "EXTRA_ARRAY" +#define TAG_EXTRA_ARRAY_VAL "EXTRA_ARRAY_VAL" +#define TAG_ALTERNATIVE_LOADER "ALTERNATIVE_LOADER" +#define TAG_HW_ACC "HW_ACC" +#define VAL_ON "ON" +#define VAL_OFF "OFF" #define VAL_METHOD_TIMEOUT "TIMEOUT" #define VAL_METHOD_DEMAND "DEMAND" #define VAL_METHOD_VISIBILITY "VISIBILITY" + static loader_info_t *__create_loader_info() { loader_info_t *info = malloc(sizeof(loader_info_t)); @@ -41,9 +49,12 @@ static loader_info_t *__create_loader_info() info->type = 0; info->name = NULL; info->exe = NULL; - info->app_type = NULL; + info->app_types = NULL; + info->hw_acc = NULL; + info->alternative_loaders = NULL; info->detection_method = METHOD_TIMEOUT | METHOD_VISIBILITY; info->timeout_val = 5000; + info->extra = bundle_create(); return info; } @@ -71,6 +82,72 @@ static void __parse_detection_method(loader_info_t *info, char *line) _D("detection_method:%d", info->detection_method); } +static void __parse_app_types(loader_info_t *info, char *line) +{ + char *token; + char *savedptr; + char refined_tok[MAX_LOCAL_BUFSZ]; + + token = strtok_r(line, "|", &savedptr); + while (token) { + refined_tok[0] = '\0'; + sscanf(token, "%s", refined_tok); + if (refined_tok[0] != '\0') + info->app_types = g_list_append(info->app_types, strdup(refined_tok)); + token = strtok_r(NULL, "|", &savedptr); + } +} + +static void __parse_extra(loader_info_t *info, char *line) +{ + char tok1[MAX_LOCAL_BUFSZ] = { 0, }; + char tok2[MAX_LOCAL_BUFSZ] = { 0, }; + char tok3[MAX_LOCAL_BUFSZ] = { 0, }; + + if (info->extra == NULL) + return; + + sscanf(line, "%s %s %s", tok1, tok2, tok3); + + if (strlen(tok2) == 0 || strlen(tok3) == 0) + return; + + bundle_add_str(info->extra, tok2, tok3); +} + +static void __add_extra_array_from_list(bundle *b, const char *key, GList *list) +{ + const char **array; + int len; + int i; + GList *cur; + + if (b == NULL || key == NULL || list == NULL) + return; + + len = g_list_length(list); + array = malloc(sizeof(const char *) * len); + + cur = list; + for (i = 0; i < len; i++) { + array[i] = cur->data; + cur = g_list_next(cur); + } + + bundle_add_str_array(b, key, array, len); + free(array); +} + +static void __flush_extra_array(bundle *b, char *key, GList *list) +{ + if (list) { + __add_extra_array_from_list(b, key, list); + g_list_free_full(list, free); + } + + free(key); +} + static GList *__parse_file(GList *list, const char *path) { FILE *fp; @@ -78,6 +155,8 @@ static GList *__parse_file(GList *list, const char *path) char tok1[MAX_LOCAL_BUFSZ]; char tok2[MAX_LOCAL_BUFSZ]; loader_info_t *cur_info = NULL; + char *key = NULL; + GList *extra_array = NULL; fp = fopen(path, "rt"); @@ -90,8 +169,12 @@ static GList *__parse_file(GList *list, const char *path) sscanf(buf, "%s %s", tok1, tok2); if (strcasecmp(TAG_LOADER, tok1) == 0) { - if (cur_info != NULL) + if (cur_info != NULL) { + __flush_extra_array(cur_info->extra, key, extra_array); + extra_array = NULL; + key = NULL; list = g_list_append(list, cur_info); + } cur_info = __create_loader_info(); continue; } @@ -99,20 +182,35 @@ static GList *__parse_file(GList *list, const char *path) if (tok1[0] == '\0' || tok2[0] == '\0' || tok1[0] == '#') continue; - if (strcasecmp(TAG_NAME, tok1) == 0) + if (strcasecmp(TAG_NAME, tok1) == 0) { cur_info->name = strdup(tok2); - else if (strcasecmp(TAG_EXE, tok1) == 0) + } else if (strcasecmp(TAG_EXE, tok1) == 0) { cur_info->exe = strdup(tok2); - else if (strcasecmp(TAG_APP_TYPE, tok1) == 0) - cur_info->app_type = strdup(tok2); - else if (strcasecmp(TAG_DETECTION_METHOD, tok1) == 0) + } else if (strcasecmp(TAG_APP_TYPE, tok1) == 0) { + __parse_app_types(cur_info, &buf[strlen(tok1)]); + } else if (strcasecmp(TAG_DETECTION_METHOD, tok1) == 0) { __parse_detection_method(cur_info, &buf[strlen(tok1)]); - else if (strcasecmp(TAG_TIMEOUT, tok1) == 0) + } else if (strcasecmp(TAG_TIMEOUT, tok1) == 0) { cur_info->timeout_val = atoi(tok2); + } else if (strcasecmp(TAG_EXTRA, tok1) == 0) { + __parse_extra(cur_info, buf); + } else if (strcasecmp(TAG_EXTRA_ARRAY, tok1) == 0) { + __flush_extra_array(cur_info->extra, key, extra_array); + extra_array = NULL; + key = strdup(tok2); + } else if (strcasecmp(TAG_EXTRA_ARRAY_VAL, tok1) == 0) { + extra_array = g_list_append(extra_array, strdup(tok2)); + } else if (strcasecmp(TAG_HW_ACC, tok1) == 0) { + cur_info->hw_acc = strdup(tok2); + } else if (strcasecmp(TAG_ALTERNATIVE_LOADER, tok1) == 0) { + cur_info->alternative_loaders = g_list_append(cur_info->alternative_loaders, strdup(tok2)); + } } - if (cur_info != NULL) + if (cur_info != NULL) { + __flush_extra_array(cur_info->extra, key, extra_array); list = g_list_append(list, cur_info); + } fclose(fp); @@ -157,7 +255,13 @@ static void __free_info(gpointer data) free(info->name); free(info->exe); - free(info->app_type); + if (info->app_types) + g_list_free_full(info->app_types, free); + free(info->hw_acc); + if (info->extra) + bundle_free(info->extra); + if (info->alternative_loaders) + g_list_free_full(info->alternative_loaders, free); free(info); } @@ -167,19 +271,58 @@ void _loader_info_dispose(GList *info) g_list_free_full(info, __free_info); } -static int __comp_app_type(gconstpointer a, gconstpointer b) +static int __comp_str(gconstpointer a, gconstpointer b) +{ + return strcmp(a, b); +} + +static int __comp_app_type_with_hw_acc(gconstpointer a, gconstpointer b) +{ + loader_info_t *info = (loader_info_t *)a; + + if (info == NULL || info->app_types == NULL || b == NULL) + return -1; + + if (g_list_find_custom(info->app_types, b, __comp_str) && + (info->hw_acc == NULL || !strcasecmp(VAL_ON, info->hw_acc))) + return 0; + + return -1; +} + +static int __comp_app_type_with_sw_acc(gconstpointer a, gconstpointer b) +{ + loader_info_t *info = (loader_info_t *)a; + + if (info == NULL || info->app_types == NULL || b == NULL) + return -1; + + if (g_list_find_custom(info->app_types, b, __comp_str) && + (info->hw_acc == NULL || !strcasecmp(VAL_OFF, info->hw_acc))) + return 0; + + return -1; +} + +static int __comp_name(gconstpointer a, gconstpointer b) { loader_info_t *info = (loader_info_t *)a; - if (info == NULL || info->app_type == NULL || b == NULL) + if (info == NULL || info->name == NULL || b == NULL) return -1; - return strcmp(info->app_type, b); + return strcmp(info->name, b); } -int _loader_info_find_type_by_app_type(GList *info, const char *app_type) +int _loader_info_find_type(GList *info, const char *app_type, bool hwacc) { - GList *cur = g_list_find_custom(info, app_type, __comp_app_type); + GList *cur = NULL; + + + if (hwacc) + cur = g_list_find_custom(info, app_type, __comp_app_type_with_hw_acc); + else + cur = g_list_find_custom(info, app_type, __comp_app_type_with_sw_acc); if (cur == NULL) return -1; @@ -189,6 +332,64 @@ int _loader_info_find_type_by_app_type(GList *info, const char *app_type) return cur_info->type; } +static int *__make_type_array(GList *info, GList *loaders, int *len) +{ + int l; + int *t; + loader_info_t *i; + GList *c; + GList *cur; + int j = 0; + + l = g_list_length(loaders); + + if (l <= 0) + return NULL; + + t = malloc(sizeof(int) * l); + if (!t) + return NULL; + + *len = l; + + cur = loaders; + while (cur) { + c = g_list_find_custom(info, cur->data, __comp_name); + + if (c) { + i = (loader_info_t *)c->data; + t[j] = i->type; + j++; + } + + cur = g_list_next(cur); + } + + return t; +} + +int *_loader_get_alternative_types(GList *info, int type, int *len) +{ + GList *cur; + loader_info_t *i; + + if (!info) + return NULL; + + cur = info; + while (cur) { + i = (loader_info_t *)cur->data; + if (i->type == type) { + if (!i->alternative_loaders) + return NULL; + + return __make_type_array(info, i->alternative_loaders, len); + } + cur = g_list_next(cur); + } + + return NULL; +} -- 2.7.4 From 7cc504d733debba38434b53ad82a4d142d1da844 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Wed, 8 Jun 2016 17:12:39 +0900 Subject: [PATCH 02/16] Remove loader configurable information Change-Id: I3324b47b0af081ecab866901dcf28f3b81ebb0ff Signed-off-by: Junghoon Park --- packaging/default.loader.in | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/packaging/default.loader.in b/packaging/default.loader.in index 1c90a68..fb335b2 100644 --- a/packaging/default.loader.in +++ b/packaging/default.loader.in @@ -1,23 +1,4 @@ [LOADER] -NAME wrt-loader -EXE /usr/bin/wrt-loader -APP_TYPE webapp -DETECTION_METHOD TIMEOUT|DEMAND -TIMEOUT 5000 - -[LOADER] -NAME jsnative-loader -EXE /usr/bin/jsnative-loader -APP_TYPE jsapp -DETECTION_METHOD TIMEOUT|VISIBILITY -TIMEOUT 5000 - -[LOADER] -NAME cs-loader -EXE null -APP_TYPE csapp - -[LOADER] NAME hw-loader1 EXE /usr/bin/launchpad-loader APP_TYPE capp|c++app -- 2.7.4 From addbe2f4a2d0df8c4b3143ae4d6e536ef5419d79 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 8 Jun 2016 08:13:18 +0900 Subject: [PATCH 03/16] Fix checking the caller process The launchpad-process-pool is a user daemon. If the caller process is a system user, the launchpad-process-pool cannot access the proc info of the caller process. Change-Id: Idf60fbaeda8e9a80201b226882287f1aef25001e Signed-off-by: Hwankyu Jhun --- src/launchpad.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/launchpad.c b/src/launchpad.c index 54c4554..1933365 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -49,6 +49,7 @@ #define PROCESS_POOL_LAUNCHPAD_SOCK ".launchpad-process-pool-sock" #define LOADER_PATH_DEFAULT "/usr/bin/launchpad-loader" #define LOADER_INFO_PATH "/usr/share/aul" +#define REGULAR_UID_MIN 5000 typedef struct { int type; @@ -891,11 +892,10 @@ static int __check_caller_by_pid(int pid) char buf[PATH_MAX] = { 0, }; ret = _proc_get_attr_by_pid(pid, buf, sizeof(buf)); - if (ret < 0) return -1; - if (strcmp(buf, "User") == 0 || strcmp(buf, "System") == 0) + if (strcmp(buf, "User") == 0) return 0; return -1; @@ -969,9 +969,11 @@ static gboolean __handle_launch_event(gpointer data) goto end; } - if (__check_caller_by_pid(cr.pid) < 0) { - _E("Invalid caller pid"); - goto end; + if (cr.uid >= REGULAR_UID_MIN) { + if (__check_caller_by_pid(cr.pid) < 0) { + _E("Invalid caller pid"); + goto end; + } } kb = bundle_decode(pkt->data, pkt->len); -- 2.7.4 From 385524bc2aa6c4c717f2ddb9f7506c85e9a82925 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 14 Jun 2016 11:47:36 +0900 Subject: [PATCH 04/16] Add the root path to the environment Change-Id: I08a4bdc9013a25ef447324d920301bd8bc05d8eb 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 0aca7c1..960c53f 100644 --- a/src/launchpad_common.c +++ b/src/launchpad_common.c @@ -597,6 +597,8 @@ void _set_env(appinfo_t *menu_info, bundle *kb) setenv("HWACC", menu_info->hwacc, 1); if (menu_info->taskmanage != NULL) setenv("TASKMANAGE", menu_info->taskmanage, 1); + if (menu_info->root_path != NULL) + setenv("AUL_ROOT_PATH", menu_info->root_path, 1); str = bundle_get_val(kb, AUL_K_WAYLAND_DISPLAY); if (str != NULL) -- 2.7.4 From ff6081f9f71a9fd255991897b66ae09cb1fb1edf Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 15 Jun 2016 11:17:51 +0900 Subject: [PATCH 05/16] Fix line buffer size Change-Id: I8465638c20736ffc60e2980255114b93b3706152 Signed-off-by: Hwankyu Jhun --- inc/loader_info.h | 2 +- src/loader_info.c | 38 ++++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/inc/loader_info.h b/inc/loader_info.h index 950aa3c..6c411ed 100644 --- a/inc/loader_info.h +++ b/inc/loader_info.h @@ -38,7 +38,7 @@ typedef struct _loader_info { GList *_loader_info_load(const char *path); void _loader_info_dispose(GList *info); -int _loader_info_find_type(GList *info, const char *app_type, bool hwacc); +int _loader_info_find_type(GList *info, const char *app_type, bool hwacc); int *_loader_get_alternative_types(GList *info, int type, int *len); diff --git a/src/loader_info.c b/src/loader_info.c index fc86f29..2c02a68 100644 --- a/src/loader_info.c +++ b/src/loader_info.c @@ -63,7 +63,7 @@ static void __parse_detection_method(loader_info_t *info, char *line) { char *token; char *savedptr; - char refined_tok[MAX_LOCAL_BUFSZ]; + char refined_tok[LINE_MAX]; token = strtok_r(line, "|", &savedptr); info->detection_method = 0; @@ -86,7 +86,7 @@ static void __parse_app_types(loader_info_t *info, char *line) { char *token; char *savedptr; - char refined_tok[MAX_LOCAL_BUFSZ]; + char refined_tok[LINE_MAX]; token = strtok_r(line, "|", &savedptr); while (token) { @@ -100,9 +100,9 @@ static void __parse_app_types(loader_info_t *info, char *line) static void __parse_extra(loader_info_t *info, char *line) { - char tok1[MAX_LOCAL_BUFSZ] = { 0, }; - char tok2[MAX_LOCAL_BUFSZ] = { 0, }; - char tok3[MAX_LOCAL_BUFSZ] = { 0, }; + char tok1[LINE_MAX] = { 0, }; + char tok2[LINE_MAX] = { 0, }; + char tok3[LINE_MAX] = { 0, }; if (info->extra == NULL) return; @@ -151,26 +151,26 @@ static void __flush_extra_array(bundle *b, char *key, GList *list) static GList *__parse_file(GList *list, const char *path) { FILE *fp; - char buf[MAX_LOCAL_BUFSZ]; - char tok1[MAX_LOCAL_BUFSZ]; - char tok2[MAX_LOCAL_BUFSZ]; + char buf[LINE_MAX]; + char tok1[LINE_MAX]; + char tok2[LINE_MAX]; loader_info_t *cur_info = NULL; char *key = NULL; GList *extra_array = NULL; fp = fopen(path, "rt"); - if (fp == NULL) return list; - while (fgets(buf, MAX_LOCAL_BUFSZ, fp) != NULL) { + 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) { + if (strcasecmp(TAG_LOADER, tok1) == 0) { if (cur_info != NULL) { - __flush_extra_array(cur_info->extra, key, extra_array); + __flush_extra_array(cur_info->extra, key, + extra_array); extra_array = NULL; key = NULL; list = g_list_append(list, cur_info); @@ -182,7 +182,7 @@ static GList *__parse_file(GList *list, const char *path) if (tok1[0] == '\0' || tok2[0] == '\0' || tok1[0] == '#') continue; - if (strcasecmp(TAG_NAME, tok1) == 0) { + if (strcasecmp(TAG_NAME, tok1) == 0) { cur_info->name = strdup(tok2); } else if (strcasecmp(TAG_EXE, tok1) == 0) { cur_info->exe = strdup(tok2); @@ -190,11 +190,11 @@ static GList *__parse_file(GList *list, const char *path) __parse_app_types(cur_info, &buf[strlen(tok1)]); } else if (strcasecmp(TAG_DETECTION_METHOD, tok1) == 0) { __parse_detection_method(cur_info, &buf[strlen(tok1)]); - } else if (strcasecmp(TAG_TIMEOUT, tok1) == 0) { + } else if (strcasecmp(TAG_TIMEOUT, tok1) == 0) { cur_info->timeout_val = atoi(tok2); - } else if (strcasecmp(TAG_EXTRA, tok1) == 0) { + } else if (strcasecmp(TAG_EXTRA, tok1) == 0) { __parse_extra(cur_info, buf); - } else if (strcasecmp(TAG_EXTRA_ARRAY, tok1) == 0) { + } else if (strcasecmp(TAG_EXTRA_ARRAY,tok1) == 0) { __flush_extra_array(cur_info->extra, key, extra_array); extra_array = NULL; key = strdup(tok2); @@ -203,7 +203,9 @@ static GList *__parse_file(GList *list, const char *path) } else if (strcasecmp(TAG_HW_ACC, tok1) == 0) { cur_info->hw_acc = strdup(tok2); } else if (strcasecmp(TAG_ALTERNATIVE_LOADER, tok1) == 0) { - cur_info->alternative_loaders = g_list_append(cur_info->alternative_loaders, strdup(tok2)); + cur_info->alternative_loaders = + g_list_append(cur_info->alternative_loaders, + strdup(tok2)); } } @@ -223,7 +225,7 @@ GList *_loader_info_load(const char *path) struct dirent entry; struct dirent *result = NULL; GList *list = NULL; - char buf[MAX_LOCAL_BUFSZ]; + char buf[PATH_MAX]; char *ext; dir_info = opendir(path); -- 2.7.4 From 3d99a02f34291d3193b7d550ad17bc8a0fafcd94 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Thu, 16 Jun 2016 10:56:30 +0900 Subject: [PATCH 06/16] Remove alternative-loader in case of common loader Change-Id: I423ae6d6e3243d36172eafad913ccf3032b890dd Signed-off-by: Junghoon Park --- packaging/default.loader.in | 1 - 1 file changed, 1 deletion(-) diff --git a/packaging/default.loader.in b/packaging/default.loader.in index fb335b2..d0d151c 100644 --- a/packaging/default.loader.in +++ b/packaging/default.loader.in @@ -30,7 +30,6 @@ EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libappcore-efl.so.1 EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libappcore-common.so.1 EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libcapi-appfw-application.so.0 EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/ecore_imf/modules/wayland/v-1.16/libwltextinputmodule.so -ALTERNATIVE_LOADER hw-loader1 -- 2.7.4 From aa24d55c9137ea3b2d971d34793c1bd8311bf04f Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Thu, 16 Jun 2016 13:01:40 +0900 Subject: [PATCH 07/16] Select the loader to launch explicitly - Caller may add extra data about loader name to launch an app. - If it exist, the loader will be used with first priority. Change-Id: I195341ab46a6f2610997ff18fada3c3ddc8d2a88 Signed-off-by: Junghoon Park --- inc/key.h | 1 + inc/launchpad_common.h | 1 + inc/loader_info.h | 1 + src/launchpad.c | 12 +++++++----- src/launchpad_common.c | 6 ++++++ src/loader_info.c | 18 ++++++++++++++++-- 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/inc/key.h b/inc/key.h index d2f09f8..7d0201f 100644 --- a/inc/key.h +++ b/inc/key.h @@ -42,6 +42,7 @@ extern "C" { #define AUL_K_WAYLAND_WORKING_DIR "__AUL_WAYLAND_WORKING_DIR__" #define AUL_K_ROOT_PATH "__AUL_ROOT_PATH__" #define AUL_K_API_VERSION "__AUL_API_VERSION__" +#define AUL_K_LOADER_NAME "__AUL_LOADER_NAME__" #ifdef __cplusplus } diff --git a/inc/launchpad_common.h b/inc/launchpad_common.h index 8ae9705..aad42c8 100644 --- a/inc/launchpad_common.h +++ b/inc/launchpad_common.h @@ -95,6 +95,7 @@ typedef struct { char *comp_type; char *internal_pool; char *root_path; + char *loader_name; } appinfo_t; char *_proc_get_cmdline_bypid(int pid); diff --git a/inc/loader_info.h b/inc/loader_info.h index 6c411ed..4bc89ec 100644 --- a/inc/loader_info.h +++ b/inc/loader_info.h @@ -39,6 +39,7 @@ typedef struct _loader_info { GList *_loader_info_load(const char *path); void _loader_info_dispose(GList *info); int _loader_info_find_type(GList *info, const char *app_type, bool hwacc); +int _loader_info_find_type_by_loader_name(GList *info, const char *loader_name); int *_loader_get_alternative_types(GList *info, int type, int *len); diff --git a/src/launchpad.c b/src/launchpad.c index 1933365..9474862 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -912,7 +912,7 @@ static bool __is_hw_acc(const char *hwacc) } static candidate_process_context_t *__find_available_slot(const char *hwacc, - const char *app_type) + const char *app_type, const char *loader_name) { int type; candidate_process_context_t *cpc; @@ -920,7 +920,10 @@ static candidate_process_context_t *__find_available_slot(const char *hwacc, int len = 0; int i; - type = _loader_info_find_type(loader_info_list, app_type, __is_hw_acc(hwacc)); + if (loader_name) + type = _loader_info_find_type_by_loader_name(loader_info_list, loader_name); + else + type = _loader_info_find_type(loader_info_list, app_type, __is_hw_acc(hwacc)); cpc = __find_slot(type, PAD_LOADER_ID_STATIC); if (!cpc) return NULL; @@ -1043,12 +1046,11 @@ static gboolean __handle_launch_event(gpointer data) SECURE_LOGD("app_type : %s\n", menu_info->app_type); SECURE_LOGD("pkg_type : %s\n", menu_info->pkg_type); - if (menu_info->comp_type && - strcmp(menu_info->comp_type, "svcapp") == 0) { + strcmp(menu_info->comp_type, "svcapp") == 0) { loader_id = PAD_LOADER_ID_DIRECT; } else if ((loader_id = __get_loader_id(kb)) <= PAD_LOADER_ID_STATIC) { - cpc = __find_available_slot(menu_info->hwacc, menu_info->app_type); + cpc = __find_available_slot(menu_info->hwacc, menu_info->app_type, menu_info->loader_name); } else { type = LAUNCHPAD_TYPE_DYNAMIC; cpc = __find_slot(type, loader_id); diff --git a/src/launchpad_common.c b/src/launchpad_common.c index 960c53f..ef42c0a 100644 --- a/src/launchpad_common.c +++ b/src/launchpad_common.c @@ -415,6 +415,10 @@ appinfo_t *_appinfo_create(bundle *kb) if (ptr) menu_info->root_path = strdup(ptr); + ptr = bundle_get_val(kb, AUL_K_LOADER_NAME); + if (ptr) + menu_info->loader_name = strdup(ptr); + if (!_appinfo_get_app_path(menu_info)) { _appinfo_free(menu_info); return NULL; @@ -483,6 +487,8 @@ void _appinfo_free(appinfo_t *menu_info) free(menu_info->internal_pool); if (menu_info->root_path != NULL) free(menu_info->root_path); + if (menu_info->loader_name != NULL) + free(menu_info->loader_name); free(menu_info); } diff --git a/src/loader_info.c b/src/loader_info.c index 2c02a68..b683539 100644 --- a/src/loader_info.c +++ b/src/loader_info.c @@ -92,7 +92,7 @@ static void __parse_app_types(loader_info_t *info, char *line) while (token) { refined_tok[0] = '\0'; sscanf(token, "%s", refined_tok); - if (refined_tok[0] != '\0') + 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); } @@ -275,6 +275,8 @@ void _loader_info_dispose(GList *info) static int __comp_str(gconstpointer a, gconstpointer b) { + if (!a || !b) + return -1; return strcmp(a, b); } @@ -320,7 +322,6 @@ int _loader_info_find_type(GList *info, const char *app_type, bool hwacc) { GList *cur = NULL; - if (hwacc) cur = g_list_find_custom(info, app_type, __comp_app_type_with_hw_acc); else @@ -334,6 +335,19 @@ int _loader_info_find_type(GList *info, const char *app_type, bool hwacc) return cur_info->type; } +int _loader_info_find_type_by_loader_name(GList *info, const char *loader_name) +{ + GList *cur = NULL; + + cur = g_list_find_custom(info, loader_name, __comp_name); + if (cur == NULL) + return -1; + + loader_info_t *cur_info = (loader_info_t *)cur->data; + + return cur_info->type; +} + static int *__make_type_array(GList *info, GList *loaders, int *len) { int l; -- 2.7.4 From ac6af2da54aeb3a34dc2a0a2046e05d44c95cf21 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Thu, 16 Jun 2016 18:56:50 +0900 Subject: [PATCH 08/16] apply app-label-monitor to remove CAP_MAC_ADMIN Change-Id: I49d5d19a778fbd7e39ab363cddcd99adf571728f Signed-off-by: Junghoon Park --- packaging/launchpad.spec | 2 +- src/launchpad.c | 83 ++++++++++++++++++++++++++++++++++++++++++++---- src/launchpad_lib.c | 10 ++---- 3 files changed, 79 insertions(+), 16 deletions(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 53613dd..c737c49 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -83,7 +83,7 @@ cp %{_builddir}/%{name}-%{version}/LICENSE %{buildroot}/usr/share/license/%{nam %{_unitdir_user}/sockets.target.wants/launchpad-process-pool.socket %{_unitdir_user}/default.target.wants/launchpad-process-pool.service %caps(cap_mac_admin,cap_mac_override,cap_setgid=ei) %{_bindir}/launchpad-process-pool -%caps(cap_mac_admin,cap_mac_override,cap_setgid=ei) %{_bindir}/launchpad-loader +%caps(cap_mac_override,cap_setgid=ei) %{_bindir}/launchpad-loader %attr(0644,root,root) %{_libdir}/liblaunchpad.so.* %files devel diff --git a/src/launchpad.c b/src/launchpad.c index 9474862..86b7bde 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -77,6 +77,8 @@ static int __sys_hwacc; static GList *loader_info_list; static int user_slot_offset; static GList *candidate_slot_list; +static app_labels_monitor *label_monitor; + static candidate_process_context_t *__add_slot(int type, int loader_id, int caller_pid, const char *loader_path, const char *extra, int detection_method, int timeout_val); @@ -281,11 +283,6 @@ error: return -1; } -static int __set_access(const char *appid) -{ - return security_manager_prepare_app(appid); -} - static int __get_loader_id(bundle *kb) { const char *val; @@ -507,8 +504,8 @@ static int __prepare_exec(const char *appid, const char *app_path, /* SET PRIVILEGES*/ if (bundle_get_val(kb, AUL_K_PRIVACY_APPID) == NULL) { _D("appId: %s / app_path : %s ", appid, app_path); - ret = __set_access(appid); - if (ret != 0) { + ret = security_manager_prepare_app(appid); + if (ret != SECURITY_MANAGER_SUCCESS) { _D("fail to set privileges - check " "your package's credential : %d\n", ret); @@ -823,6 +820,42 @@ static gboolean __handle_sigchild(gpointer data) return G_SOURCE_CONTINUE; } +static gboolean __handle_label_monitor(gpointer data) +{ + candidate_process_context_t *cpc; + GList *iter = candidate_slot_list; + + _D("__handle_label_monitor()"); + security_manager_app_labels_monitor_process(label_monitor); + + while (iter) { + cpc = (candidate_process_context_t *)iter->data; + if (cpc->prepared) { + _D("Dispose candidate process %d", cpc->pid); + __kill_process(cpc->pid); + close(cpc->send_fd); + cpc->prepared = false; + cpc->pid = CANDIDATE_NONE; + cpc->send_fd = -1; + if (cpc->source > 0) { + g_source_remove(cpc->source); + cpc->source = 0; + } + + if (cpc->timer > 0) { + g_source_remove(cpc->timer); + cpc->timer = 0; + } + __set_timer(cpc); + __prepare_candidate_process(cpc->type, cpc->loader_id); + } + + iter = g_list_next(iter); + } + + return G_SOURCE_CONTINUE; +} + static int __dispatch_cmd_hint(bundle *kb, int detection_method) { candidate_process_context_t *cpc; @@ -1221,6 +1254,33 @@ static int __init_sigchild_fd(void) return 0; } +static int __init_label_monitor_fd(void) +{ + 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) + return -1; + security_manager_app_labels_monitor_get_fd(label_monitor, &fd); + + if (fd < 0) { + _E("failed to get fd"); + return -1; + } + + pollfd = __poll_fd(fd, G_IO_IN, (GSourceFunc)__handle_label_monitor, 0, 0); + if (pollfd == 0) { + close(fd); + return -1; + } + + return 0; +} + static void __add_slot_from_info(gpointer data, gpointer user_data) { loader_info_t *info = (loader_info_t *)data; @@ -1300,6 +1360,12 @@ 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", @@ -1351,6 +1417,9 @@ int main(int argc, char **argv) #endif g_main_loop_run(mainloop); + if (label_monitor) + security_manager_app_labels_monitor_finish(label_monitor); + return -1; } diff --git a/src/launchpad_lib.c b/src/launchpad_lib.c index f655ed6..378ccc0 100644 --- a/src/launchpad_lib.c +++ b/src/launchpad_lib.c @@ -71,12 +71,6 @@ static void __release_at_exit(void) free(__root_path); } -static int __set_access(const char *appid, const char *pkg_type, - const char *app_path) -{ - return security_manager_prepare_app(appid); -} - static int __prepare_exec(const char *appid, const char *app_path, const char *pkg_type, int type) { @@ -89,8 +83,8 @@ static int __prepare_exec(const char *appid, const char *app_path, /* SET PRIVILEGES*/ SECURE_LOGD("[candidata] appid : %s / pkg_type : %s / app_path : %s", appid, pkg_type, app_path); - ret = __set_access(appid, pkg_type, app_path); - if (ret < 0) { + ret = security_manager_prepare_app(appid); + if (ret != SECURITY_MANAGER_SUCCESS) { _D("fail to set privileges - check your package's credential: " "%d\n", ret); return -1; -- 2.7.4 From b471207fdecc3f2bf902bbed13fbb044c77d2bc8 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Tue, 21 Jun 2016 14:04:49 +0900 Subject: [PATCH 09/16] Add null checkers Change-Id: I6efa4c92f7467484ca8ea95a3625985773145eaa Signed-off-by: Junghoon Park --- src/launchpad_common.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/launchpad_common.c b/src/launchpad_common.c index ef42c0a..19ad650 100644 --- a/src/launchpad_common.c +++ b/src/launchpad_common.c @@ -636,8 +636,15 @@ char *_get_libdir(const char *path) char buf[PATH_MAX]; char *ptr; + if (path == NULL) + return NULL; path_dup = strdup(path); + if (path_dup == NULL) + return NULL; ptr = strrchr(path_dup, '/'); + if (ptr == NULL) + return NULL; + *ptr = '\0'; snprintf(buf, sizeof(buf), "%s/../lib/", path_dup); -- 2.7.4 From d1fa59bb255a323ad993dc9e01abe342aaf6291b Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Tue, 21 Jun 2016 14:55:56 +0900 Subject: [PATCH 10/16] Fix issue about making duplicated loaders Change-Id: I8550b50c6fed43e8aa704fcf3b895d09ad82b43d Signed-off-by: Junghoon Park --- src/launchpad.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/launchpad.c b/src/launchpad.c index 86b7bde..cf7514b 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -831,12 +831,6 @@ static gboolean __handle_label_monitor(gpointer data) while (iter) { cpc = (candidate_process_context_t *)iter->data; if (cpc->prepared) { - _D("Dispose candidate process %d", cpc->pid); - __kill_process(cpc->pid); - close(cpc->send_fd); - cpc->prepared = false; - cpc->pid = CANDIDATE_NONE; - cpc->send_fd = -1; if (cpc->source > 0) { g_source_remove(cpc->source); cpc->source = 0; @@ -846,7 +840,13 @@ static gboolean __handle_label_monitor(gpointer data) g_source_remove(cpc->timer); cpc->timer = 0; } - __set_timer(cpc); + + _D("Dispose candidate process %d", cpc->pid); + __kill_process(cpc->pid); + close(cpc->send_fd); + cpc->prepared = false; + cpc->pid = CANDIDATE_NONE; + cpc->send_fd = -1; __prepare_candidate_process(cpc->type, cpc->loader_id); } -- 2.7.4 From 689b26cd7c77473c9a62e2ae1405d9d35664ae06 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 8 Jun 2016 20:22:30 +0900 Subject: [PATCH 11/16] Prepare a server socket of an application - The launchpad socket path are changed to "/run/aul/daemons//". - Before executing an application, the child process creates an aul socket of the application for communication. And then, the application uses the socket. - Requires [aul] https://review.tizen.org/gerrit/#/c/73534/ [amd] https://review.tizen.org/gerrit/#/c/73537/ Change-Id: I872b5faf1681725e51a3c5647ff1195ebeaabba9 Signed-off-by: Hwankyu Jhun --- inc/launchpad_common.h | 3 ++- inc/sigchild.h | 7 ++++--- packaging/launchpad-process-pool.service | 4 ++++ packaging/launchpad-process-pool.socket | 4 ++-- src/launchpad.c | 12 ++++++++---- src/launchpad_common.c | 32 ++++++++++++++++++++++++++++---- src/launchpad_lib.c | 3 +++ src/launchpad_loader.c | 14 +++++++++++--- 8 files changed, 62 insertions(+), 17 deletions(-) diff --git a/inc/launchpad_common.h b/inc/launchpad_common.h index aad42c8..dce37ed 100644 --- a/inc/launchpad_common.h +++ b/inc/launchpad_common.h @@ -31,7 +31,7 @@ #define LOG_TAG "LAUNCHPAD" #endif -#define SOCKET_PATH "/run/user" +#define SOCKET_PATH "/run/aul" #define LAUNCHPAD_LOADER_SOCKET_NAME ".launchpad-type" #define MAX_PENDING_CONNECTIONS 10 #define MAX_LOCAL_BUFSZ 128 @@ -109,6 +109,7 @@ void _set_sock_option(int fd, int cli); void _set_env(appinfo_t *menu_info, bundle *kb); char **_create_argc_argv(bundle *kb, int *margc); char *_get_libdir(const char *path); +void _prepare_listen_sock(void); appinfo_t *_appinfo_create(bundle *kb); void _appinfo_free(appinfo_t *menu_info); diff --git a/inc/sigchild.h b/inc/sigchild.h index c982fba..2ed7c62 100644 --- a/inc/sigchild.h +++ b/inc/sigchild.h @@ -34,7 +34,7 @@ static inline void __socket_garbage_collector(void) struct dirent *dentry; char tmp[MAX_LOCAL_BUFSZ]; - snprintf(tmp, sizeof(tmp), "/run/user/%d", getuid()); + snprintf(tmp, sizeof(tmp), "/run/aul/apps/%d", getuid()); dp = opendir(tmp); if (dp == NULL) return; @@ -45,7 +45,7 @@ static inline void __socket_garbage_collector(void) snprintf(tmp, MAX_LOCAL_BUFSZ, "/proc/%s", dentry->d_name); if (access(tmp, F_OK) < 0) { /* Flawfinder: ignore */ - snprintf(tmp, MAX_LOCAL_BUFSZ, "/run/user/%d/%s", + snprintf(tmp, MAX_LOCAL_BUFSZ, "/run/aul/apps/%d/%s", getuid(), dentry->d_name); unlink(tmp); continue; @@ -145,7 +145,8 @@ static int __sigchild_action(pid_t dead_pid) __send_app_dead_signal_dbus(dead_pid); - snprintf(buf, MAX_LOCAL_BUFSZ, "/run/user/%d/%d", getuid(), dead_pid); + snprintf(buf, sizeof(buf), "/run/aul/apps/%d/%d", + getuid(), dead_pid); unlink(buf); __socket_garbage_collector(); diff --git a/packaging/launchpad-process-pool.service b/packaging/launchpad-process-pool.service index 0667cd5..6128e1e 100644 --- a/packaging/launchpad-process-pool.service +++ b/packaging/launchpad-process-pool.service @@ -6,5 +6,9 @@ Description=Start the USER Access Control Agent [Service] +ExecStartPre=-/usr/bin/mkdir -p /run/aul/daemons/%U +ExecStartPre=-/usr/bin/chmod 0777 /run/aul/daemons/%U +ExecStartPre=-/usr/bin/mkdir -p /run/aul/apps/%U +ExecStartPre=-/usr/bin/chmod 0777 /run/aul/apps/%U ExecStart=/bin/sh -l -c "/usr/bin/launchpad-process-pool" Sockets=launchpad-process-pool.socket diff --git a/packaging/launchpad-process-pool.socket b/packaging/launchpad-process-pool.socket index 6d68ff5..2306963 100644 --- a/packaging/launchpad-process-pool.socket +++ b/packaging/launchpad-process-pool.socket @@ -1,6 +1,6 @@ [Socket] -ListenStream=/run/user/%U/.launchpad-process-pool-sock - +ListenStream=/run/aul/daemons/%U/.launchpad-process-pool-sock +DirectoryMode=0777 Service=launchpad-process-pool.service [Install] diff --git a/src/launchpad.c b/src/launchpad.c index cf7514b..a11c9b6 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -249,7 +249,7 @@ static int __listen_candidate_process(int type, int loader_id) memset(&addr, 0x00, sizeof(struct sockaddr_un)); addr.sun_family = AF_UNIX; - snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%d/%s%d-%d", + snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/daemons/%d/%s%d-%d", SOCKET_PATH, getuid(), LAUNCHPAD_LOADER_SOCKET_NAME, type, loader_id); @@ -414,8 +414,8 @@ static int __send_launchpad_loader(candidate_process_context_t *cpc, char sock_path[PATH_MAX]; int pid = -1; - snprintf(sock_path, sizeof(sock_path), "/run/user/%d/%d", getuid(), - cpc->pid); + snprintf(sock_path, sizeof(sock_path), "/run/aul/apps/%d/%d", + getuid(), cpc->pid); unlink(sock_path); __candidate_process_real_launch(cpc->send_fd, pkt); @@ -512,6 +512,7 @@ static int __prepare_exec(const char *appid, const char *app_path, return -1; } } + /* SET DUMPABLE - for coredump*/ prctl(PR_SET_DUMPABLE, 1); @@ -525,6 +526,9 @@ static int __prepare_exec(const char *appid, const char *app_path, _D("can't locate file name to execute"); return -1; } + + _prepare_listen_sock(); + memset(process_name, '\0', AUL_PR_NAME); snprintf(process_name, AUL_PR_NAME, "%s", file_name); prctl(PR_SET_NAME, process_name); @@ -555,7 +559,7 @@ static int __launch_directly(const char *appid, const char *app_path, int clifd, for (iter_fd = 3; iter_fd <= max_fd; iter_fd++) close(iter_fd); - snprintf(sock_path, sizeof(sock_path), "/run/user/%d/%d", + snprintf(sock_path, sizeof(sock_path), "/run/aul/apps/%d/%d", getuid(), getpid()); unlink(sock_path); diff --git a/src/launchpad_common.c b/src/launchpad_common.c index 19ad650..32a70dd 100644 --- a/src/launchpad_common.c +++ b/src/launchpad_common.c @@ -184,7 +184,10 @@ int _create_server_sock(const char *name) struct sockaddr_un saddr; int fd; - fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); + if (name) + fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); + else + fd = socket(AF_UNIX, SOCK_STREAM, 0); /* support above version 2.6.27*/ if (fd < 0) { if (errno == EINVAL) { @@ -201,8 +204,16 @@ int _create_server_sock(const char *name) memset(&saddr, 0, sizeof(saddr)); saddr.sun_family = AF_UNIX; - snprintf(saddr.sun_path, sizeof(saddr.sun_path), "/run/user/%d/%s", - getuid(), name); + + if (name) { + snprintf(saddr.sun_path, sizeof(saddr.sun_path), + "%s/daemons/%d/%s", + SOCKET_PATH, getuid(), name); + } else { + snprintf(saddr.sun_path, sizeof(saddr.sun_path), + "%s/apps/%d/%d", + SOCKET_PATH, getuid(), getpid()); + } unlink(saddr.sun_path); if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) { @@ -557,7 +568,7 @@ int _connect_to_launchpad(int type, int id) memset(&addr, 0x00, sizeof(struct sockaddr_un)); addr.sun_family = AF_UNIX; - snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%d/%s%d-%d", + snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/daemons/%d/%s%d-%d", SOCKET_PATH, getuid(), LAUNCHPAD_LOADER_SOCKET_NAME, type, id); @@ -669,3 +680,16 @@ int _proc_get_attr_by_pid(int pid, char *buf, int size) return 0; } +void _prepare_listen_sock(void) +{ + int fd; + char buf[12]; + + fd = _create_server_sock(NULL); + if (fd < 0) + return; + + snprintf(buf, sizeof(buf), "%d", fd); + setenv("AUL_LISTEN_SOCK", buf, 1); +} + diff --git a/src/launchpad_lib.c b/src/launchpad_lib.c index 378ccc0..ec2b1d2 100644 --- a/src/launchpad_lib.c +++ b/src/launchpad_lib.c @@ -108,6 +108,9 @@ static int __prepare_exec(const char *appid, const char *app_path, _D("can't locate file name to execute"); return -1; } + + _prepare_listen_sock(); + memset(process_name, '\0', AUL_PR_NAME); snprintf(process_name, AUL_PR_NAME, "%s", file_name); prctl(PR_SET_NAME, process_name); diff --git a/src/launchpad_loader.c b/src/launchpad_loader.c index fbde22a..2e9d18b 100644 --- a/src/launchpad_loader.c +++ b/src/launchpad_loader.c @@ -25,11 +25,11 @@ #include #include #include -#include #include #include "launchpad_common.h" #include "launchpad.h" +#include "key.h" #define KEY_LOADER_TYPE "loader_type" #define LOADER_TYPE_COMMON "common-loader" @@ -268,9 +268,17 @@ static void __close_fds(void) { int iter_fd; int max_fd = sysconf(_SC_OPEN_MAX); + int fd = -1; + const char *sockfd; - for (iter_fd = 3; iter_fd <= max_fd; iter_fd++) - close(iter_fd); + sockfd = getenv("AUL_LISTEN_SOCK"); + if (sockfd) + fd = atoi(sockfd); + + for (iter_fd = 3; iter_fd <= max_fd; iter_fd++) { + if (iter_fd != fd) + close(iter_fd); + } } static int __loader_terminate_cb(int argc, char **argv, void *user_data) -- 2.7.4 From 6e99bfc21c07496687fb93d5afdba1f9d5bcd9a9 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 23 Jun 2016 14:54:10 +0900 Subject: [PATCH 12/16] Remove others permission about the user's directory Change-Id: I48f782f8dcfde1f7bed9639771339344a692289c 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 6128e1e..a627161 100644 --- a/packaging/launchpad-process-pool.service +++ b/packaging/launchpad-process-pool.service @@ -9,6 +9,6 @@ Description=Start the USER Access Control Agent ExecStartPre=-/usr/bin/mkdir -p /run/aul/daemons/%U ExecStartPre=-/usr/bin/chmod 0777 /run/aul/daemons/%U ExecStartPre=-/usr/bin/mkdir -p /run/aul/apps/%U -ExecStartPre=-/usr/bin/chmod 0777 /run/aul/apps/%U +ExecStartPre=-/usr/bin/chmod 0700 /run/aul/apps/%U ExecStart=/bin/sh -l -c "/usr/bin/launchpad-process-pool" Sockets=launchpad-process-pool.socket -- 2.7.4 From 7adac4ecd68167ca9bc5d84b18403abd5eb33254 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 23 Jun 2016 15:59:20 +0900 Subject: [PATCH 13/16] Prevent app sockets from being deleted by attacker - Requires: https://review.tizen.org/gerrit/#/c/76214/ Change-Id: Ibb967aea776c58f491352cace203a2f7ae5fb872 Signed-off-by: Hwankyu Jhun --- inc/launchpad_common.h | 1 + inc/sigchild.h | 12 +++------ src/launchpad.c | 13 ++++----- src/launchpad_common.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 16 deletions(-) diff --git a/inc/launchpad_common.h b/inc/launchpad_common.h index dce37ed..4f13aaa 100644 --- a/inc/launchpad_common.h +++ b/inc/launchpad_common.h @@ -110,6 +110,7 @@ void _set_env(appinfo_t *menu_info, bundle *kb); char **_create_argc_argv(bundle *kb, int *margc); char *_get_libdir(const char *path); void _prepare_listen_sock(void); +int _delete_sock_path(int pid, uid_t uid); appinfo_t *_appinfo_create(bundle *kb); void _appinfo_free(appinfo_t *menu_info); diff --git a/inc/sigchild.h b/inc/sigchild.h index 2ed7c62..9ea5b0f 100644 --- a/inc/sigchild.h +++ b/inc/sigchild.h @@ -20,6 +20,8 @@ #include #include +#include "launchpad_common.h" + #define AUL_DBUS_PATH "/aul/dbus_handler" #define AUL_DBUS_SIGNAL_INTERFACE "org.tizen.aul.signal" #define AUL_DBUS_APPDEAD_SIGNAL "app_dead" @@ -45,9 +47,7 @@ static inline void __socket_garbage_collector(void) snprintf(tmp, MAX_LOCAL_BUFSZ, "/proc/%s", dentry->d_name); if (access(tmp, F_OK) < 0) { /* Flawfinder: ignore */ - snprintf(tmp, MAX_LOCAL_BUFSZ, "/run/aul/apps/%d/%s", - getuid(), dentry->d_name); - unlink(tmp); + _delete_sock_path(atoi(dentry->d_name), getuid()); continue; } } @@ -138,16 +138,12 @@ static inline int __send_app_launch_signal_dbus(int launch_pid, static int __sigchild_action(pid_t dead_pid) { - char buf[MAX_LOCAL_BUFSZ]; - if (dead_pid <= 0) goto end; __send_app_dead_signal_dbus(dead_pid); - snprintf(buf, sizeof(buf), "/run/aul/apps/%d/%d", - getuid(), dead_pid); - unlink(buf); + _delete_sock_path(dead_pid, getuid()); __socket_garbage_collector(); end: diff --git a/src/launchpad.c b/src/launchpad.c index a11c9b6..c12abc6 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -411,12 +411,12 @@ static void __set_timer(candidate_process_context_t *cpc) static int __send_launchpad_loader(candidate_process_context_t *cpc, app_pkt_t *pkt, const char *app_path, int clifd) { - char sock_path[PATH_MAX]; int pid = -1; + int ret; - snprintf(sock_path, sizeof(sock_path), "/run/aul/apps/%d/%d", - getuid(), cpc->pid); - unlink(sock_path); + ret = _delete_sock_path(cpc->pid, getuid()); + if (ret != 0) + return -1; __candidate_process_real_launch(cpc->send_fd, pkt); SECURE_LOGD("Request to candidate process, pid: %d, bin path: %s", @@ -543,7 +543,6 @@ static int __launch_directly(const char *appid, const char *app_path, int clifd, bundle *kb, appinfo_t *menu_info, candidate_process_context_t *cpc) { - char sock_path[PATH_MAX]; int pid = fork(); int max_fd; int iter_fd; @@ -559,9 +558,7 @@ static int __launch_directly(const char *appid, const char *app_path, int clifd, for (iter_fd = 3; iter_fd <= max_fd; iter_fd++) close(iter_fd); - snprintf(sock_path, sizeof(sock_path), "/run/aul/apps/%d/%d", - getuid(), getpid()); - unlink(sock_path); + _delete_sock_path(getpid(), getuid()); PERF("prepare exec - first done"); _D("lock up test log(no error) : prepare exec - first done"); diff --git a/src/launchpad_common.c b/src/launchpad_common.c index 32a70dd..83489d4 100644 --- a/src/launchpad_common.c +++ b/src/launchpad_common.c @@ -28,6 +28,9 @@ #include #include #include +#include +#include +#include #include "launchpad_common.h" #include "key.h" @@ -183,6 +186,7 @@ int _create_server_sock(const char *name) { struct sockaddr_un saddr; int fd; + int ret; if (name) fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); @@ -213,6 +217,25 @@ int _create_server_sock(const char *name) snprintf(saddr.sun_path, sizeof(saddr.sun_path), "%s/apps/%d/%d", SOCKET_PATH, getuid(), getpid()); + ret = mkdir(saddr.sun_path, 0700); + if (ret != 0) { + if (errno == EEXIST) { + if (access(saddr.sun_path, R_OK) != 0) { + _E("Failed to access %s directory - %d", + saddr.sun_path, errno); + close(fd); + return -1; + } + } else { + _E("Failed to create %s directory - %d", + saddr.sun_path, errno); + close(fd); + return -1; + } + } + snprintf(saddr.sun_path, sizeof(saddr.sun_path), + "%s/apps/%d/%d/.app-sock", + SOCKET_PATH, getuid(), getpid()); } unlink(saddr.sun_path); @@ -693,3 +716,53 @@ void _prepare_listen_sock(void) setenv("AUL_LISTEN_SOCK", buf, 1); } +static int __delete_dir(const char *path) +{ + DIR *dp; + struct dirent dentry; + struct dirent *result = NULL; + char buf[PATH_MAX]; + struct stat statbuf; + int ret; + + if (path == NULL) + return -1; + + dp = opendir(path); + if (dp == NULL) + return -1; + + while (readdir_r(dp, &dentry, &result) == 0 && result) { + if (!strcmp(dentry.d_name, ".") || !strcmp(dentry.d_name, "..")) + continue; + + snprintf(buf, sizeof(buf), "%s/%s", path, dentry.d_name); + ret = stat(buf, &statbuf); + if (ret == 0) { + if (S_ISDIR(statbuf.st_mode)) + __delete_dir(buf); + else + unlink(buf); + } + } + + rmdir(path); + closedir(dp); + + return 0; +} + +int _delete_sock_path(int pid, uid_t uid) +{ + char path[PATH_MAX]; + + snprintf(path, sizeof(path), "/run/aul/apps/%d/%d", uid, pid); + if (access(path, F_OK) == 0) + __delete_dir(path); + + if (access(path, F_OK) == 0) + return -1; + + return 0; +} + -- 2.7.4 From 8539e2b64630cacd33358e2af927f7d3bd38fb87 Mon Sep 17 00:00:00 2001 From: Hawnkyu Jhun Date: Sat, 25 Jun 2016 20:01:16 +0900 Subject: [PATCH 14/16] Exclude unused headers Change-Id: I44a4636d9cd1d418e8f87244a0a5215359253640 Signed-off-by: Hawnkyu Jhun --- src/launchpad_common.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/launchpad_common.c b/src/launchpad_common.c index 83489d4..f9f318d 100644 --- a/src/launchpad_common.c +++ b/src/launchpad_common.c @@ -29,8 +29,6 @@ #include #include #include -#include -#include #include "launchpad_common.h" #include "key.h" -- 2.7.4 From f2dfa51637ed2e0b556549857ce9ab57f5945bba Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Wed, 29 Jun 2016 14:05:52 +0900 Subject: [PATCH 15/16] Adjust timeout value Change-Id: I0b1173d7059573f020920edd06ce468ca6c3210e Signed-off-by: Junghoon Park --- packaging/default.loader.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packaging/default.loader.in b/packaging/default.loader.in index d0d151c..0ea64e5 100644 --- a/packaging/default.loader.in +++ b/packaging/default.loader.in @@ -3,8 +3,8 @@ NAME hw-loader1 EXE /usr/bin/launchpad-loader APP_TYPE capp|c++app HW_ACC ON -DETECTION_METHOD TIMEOUT|VISIBILITY -TIMEOUT 5000 +DETECTION_METHOD TIMEOUT +TIMEOUT 2000 EXTRA loader_type hw-loader EXTRA_ARRAY preload EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libappcore-efl.so.1 @@ -22,8 +22,8 @@ ALTERNATIVE_LOADER common-loader1 NAME common-loader1 EXE /usr/bin/launchpad-loader APP_TYPE capp|c++app -DETECTION_METHOD TIMEOUT|VISIBILITY -TIMEOUT 5000 +DETECTION_METHOD TIMEOUT +TIMEOUT 2000 EXTRA loader_type common-loader EXTRA_ARRAY preload EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libappcore-efl.so.1 -- 2.7.4 From 42cd958b6a32dc8b6dd5635b8b300ebb243c32d8 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 29 Jun 2016 20:56:52 +0900 Subject: [PATCH 16/16] Remove unnecessary capability Change-Id: I3b5083baebaad31c2cdf4d614079c1a380abb548 Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index c737c49..c99b544 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -82,8 +82,8 @@ cp %{_builddir}/%{name}-%{version}/LICENSE %{buildroot}/usr/share/license/%{nam %{_unitdir_user}/launchpad-process-pool.socket %{_unitdir_user}/sockets.target.wants/launchpad-process-pool.socket %{_unitdir_user}/default.target.wants/launchpad-process-pool.service -%caps(cap_mac_admin,cap_mac_override,cap_setgid=ei) %{_bindir}/launchpad-process-pool -%caps(cap_mac_override,cap_setgid=ei) %{_bindir}/launchpad-loader +%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/launchpad-process-pool +%caps(cap_setgid=ei) %{_bindir}/launchpad-loader %attr(0644,root,root) %{_libdir}/liblaunchpad.so.* %files devel -- 2.7.4