From 3a80ec5627488f3b87494eea0698b1aac129df7f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 19 Jun 2020 07:45:36 +0900 Subject: [PATCH 01/16] Reduce printing logs Change-Id: I8da9db42385a395aaf4a36d83ff27d48ffe1f7e8 Signed-off-by: Hwankyu Jhun --- src/common/src/launchpad_plugin.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/src/launchpad_plugin.c b/src/common/src/launchpad_plugin.c index 912c19d..30f41c3 100644 --- a/src/common/src/launchpad_plugin.c +++ b/src/common/src/launchpad_plugin.c @@ -35,7 +35,8 @@ int _launchpad_plugin_prepare_app(const char *app_id, bundle *kb) ret = access(PATH_LAUNCHPAD_PLUGIN, F_OK); if (ret != 0) { - _D("plugin module does not exist. errno(%d)", errno); + if (errno != ENOENT) + _W("plugin module does not exist. errno(%d)", errno); return 0; } -- 2.7.4 From 8f36fe1f81baf48af89550021dfb267208174f9a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 19 Jun 2020 07:07:43 +0900 Subject: [PATCH 02/16] Fix bugs about sending dbus signal If flushing a pending signal is failed, launchpad should not create and store a new pending item from it. Change-Id: Ieb72efd4c16d92610f1aa7a20dc741cd16e0998b Signed-off-by: Hwankyu Jhun --- src/launchpad/src/launchpad_dbus.c | 60 +++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/src/launchpad/src/launchpad_dbus.c b/src/launchpad/src/launchpad_dbus.c index 171612b..e408b3c 100644 --- a/src/launchpad/src/launchpad_dbus.c +++ b/src/launchpad/src/launchpad_dbus.c @@ -146,48 +146,32 @@ static int __emit_signal(const char *path, static int __emit_app_launch_signal(int pid, const char *app_id) { - pending_item_t *item; int ret; ret = __emit_signal(AUL_DBUS_PATH, AUL_DBUS_SIGNAL_INTERFACE, AUL_DBUS_APPLAUNCH_SIGNAL, g_variant_new("(us)", pid, app_id)); - if (ret < 0) { - item = __create_pending_item(app_id, pid, APP_SIGNAL_LAUNCH); - if (!item) - return -ENOMEM; + if (ret < 0) + return ret; - _W("Pend app launch signal. pid(%d), app_id(%s)", pid, app_id); - __pending_items = g_list_append(__pending_items, item); - __set_pending_item_timer(); - } else { - _D("App launch. pid(%d), app_id(%s)", pid, app_id); - } + _D("App launch. pid(%d), app_id(%s)", pid, app_id); return 0; } static int __emit_app_dead_signal(int pid) { - pending_item_t *item; int ret; ret = __emit_signal(AUL_DBUS_PATH, AUL_DBUS_SIGNAL_INTERFACE, AUL_DBUS_APPDEAD_SIGNAL, g_variant_new("(u)", pid)); - if (ret < 0) { - item = __create_pending_item(NULL, pid, APP_SIGNAL_DEAD); - if (!item) - return -ENOMEM; + if (ret < 0) + return ret; - _W("Pend app dead signal. pid(%d)", pid); - __pending_items = g_list_append(__pending_items, item); - __set_pending_item_timer(); - } else { - _D("App dead. pid(%d)", pid); - } + _D("App dead. pid(%d)", pid); return 0; } @@ -243,22 +227,50 @@ static void __unset_pending_item_timer(void) int _dbus_send_app_launch_signal(int pid, const char *app_id) { + pending_item_t *item; + int ret; + if (pid <= 1 || !app_id) { _E("Invalid parameter"); return -EINVAL; } - return __emit_app_launch_signal(pid, app_id); + ret = __emit_app_launch_signal(pid, app_id); + if (ret < 0) { + item = __create_pending_item(app_id, pid, APP_SIGNAL_LAUNCH); + if (!item) + return -ENOMEM; + + _W("Pend app launch signal. pid(%d), app_id(%s)", pid, app_id); + __pending_items = g_list_append(__pending_items, item); + __set_pending_item_timer(); + } + + return 0; } int _dbus_send_app_dead_signal(int pid) { + pending_item_t *item; + int ret; + if (pid <= 1) { _E("Invalid parameter"); return -EINVAL; } - return __emit_app_dead_signal(pid); + ret = __emit_app_dead_signal(pid); + if (ret < 0) { + item = __create_pending_item(NULL, pid, APP_SIGNAL_DEAD); + if (!item) + return -ENOMEM; + + _W("Pend app dead signal. pid(%d)", pid); + __pending_items = g_list_append(__pending_items, item); + __set_pending_item_timer(); + } + + return 0; } int _dbus_init(void) -- 2.7.4 From 6d9d7ba1328b71a35fb57850efba49bb47f256d2 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 18 Jun 2020 17:18:39 +0900 Subject: [PATCH 03/16] Fix standard I/O redirection If calling sd_journal_stream_fd() is failed, the child process uses the interitance of file descriptors. Change-Id: Ia37c1ca586d735280cc07298088c00c93815b2aa Signed-off-by: Hwankyu Jhun --- src/common/src/launchpad_common.c | 91 +++++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 32 deletions(-) diff --git a/src/common/src/launchpad_common.c b/src/common/src/launchpad_common.c index e41a391..d2bf965 100644 --- a/src/common/src/launchpad_common.c +++ b/src/common/src/launchpad_common.c @@ -923,53 +923,80 @@ int _close_all_fds(void) return 0; } -int _setup_stdio(const char *ident) +static int __redirect_stdin(void) { + int ret; int fd; - /* stdin */ fd = open(PATH_DEV_NULL, O_RDONLY | O_NOCTTY); if (fd < 0) { - _W("Failed to open /dev/null - err(%d)", errno); - return -1; - } - if (dup2(fd, STDIN_FILENO) < 0) { - _W("Failed to duplicate fd - oldfd(%d), newfd(%d)", - fd, STDIN_FILENO); + ret = -errno; + _E("open(%s) is failed. errno(%d)", PATH_DEV_NULL, errno); + return ret; } + + ret = dup2(fd, STDIN_FILENO); + if (ret < 0) + _W("dup2(%d, 0) is failed. errno(%d)", fd, errno); + close(fd); + return ret; +} + +static int __redirect_stdout(const char *ident) +{ + int ret; + int fd; - /* stdout */ - fd = sd_journal_stream_fd(ident, LOG_INFO, false); + fd = sd_journal_stream_fd(ident, LOG_INFO, 0); if (fd < 0) { - _W("Failed to connect journal socket - err(%d)", errno); - fd = open(PATH_DEV_NULL, O_WRONLY | O_NOCTTY); - if (fd < 0) { - _W("Failed to open /dev/null - err(%d)", errno); - return -1; - } - } - if (dup2(fd, STDOUT_FILENO) < 0) { - _W("Failed to duplicate fd - oldfd(%d), newfd(%d)", - fd, STDOUT_FILENO); + _W("sd_journal_stream_fd() is failed. error(%d)", fd); + return fd; } + + ret = dup2(fd, STDOUT_FILENO); + if (ret < 0) + _W("dup(%d, 1) is failed. errno(%d)", fd, errno); + close(fd); + return ret; +} - /* stderr */ - fd = sd_journal_stream_fd(ident, LOG_INFO, false); +static int __redirect_stderr(const char *ident) +{ + int ret; + int fd; + + fd = sd_journal_stream_fd(ident, LOG_WARNING, 0); if (fd < 0) { - _W("Failed to connect journal socket - err(%d)", errno); - fd = open(PATH_DEV_NULL, O_WRONLY | O_NOCTTY); - if (fd < 0) { - _W("Failed to open /dev/null - err(%d)", errno); - return -1; - } - } - if (dup2(fd, STDERR_FILENO) < 0) { - _W("Failed to duplicate fd - oldfd(%d), newfd(%d)", - fd, STDERR_FILENO); + _W("sd_journal_stream_fd() is failed. error(%d)", fd); + return fd; } + + ret = dup2(fd, STDERR_FILENO); + if (ret < 0) + _W("dup(%d, 2) is failed. errno(%d)", fd, errno); + close(fd); + return ret; + +} + +int _setup_stdio(const char *ident) +{ + int ret; + + ret = __redirect_stdin(); + if (ret < 0) + return ret; + + ret = __redirect_stdout(ident); + if (ret < 0) + return ret; + + ret = __redirect_stderr(ident); + if (ret < 0) + return ret; return 0; } -- 2.7.4 From 99464b08a3a13fd9e498a5d8d76c8bcb74047270 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 19 Jun 2020 08:33:49 +0900 Subject: [PATCH 04/16] Release version 0.15.5 Changes: - Limit error log from __get_connection - Reduce printing logs - Fix bugs about sending dbus signal - Fix standard I/O redirection Change-Id: If8157766ddc65e2c9ca55f61be76e825faacb6c5 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 7a2ec41..b0c679d 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.4 +Version: 0.15.5 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 9996f39b1d9d581fcb810dc0b031613637cd2f5d Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 23 Jun 2020 10:21:15 +0900 Subject: [PATCH 05/16] Check the error value Before printing error logs If the error value is -ENOENT(No such file or directory), the process doesn't print the error logs. Change-Id: I15548f966b4c28928f0f460c4be5a611df57503d Signed-off-by: Hwankyu Jhun --- src/common/src/launchpad_common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/common/src/launchpad_common.c b/src/common/src/launchpad_common.c index d2bf965..fdb2455 100644 --- a/src/common/src/launchpad_common.c +++ b/src/common/src/launchpad_common.c @@ -950,7 +950,8 @@ static int __redirect_stdout(const char *ident) fd = sd_journal_stream_fd(ident, LOG_INFO, 0); if (fd < 0) { - _W("sd_journal_stream_fd() is failed. error(%d)", fd); + if (fd != -ENOENT) + _W("sd_journal_stream_fd() is failed. error(%d)", fd); return fd; } @@ -969,7 +970,8 @@ static int __redirect_stderr(const char *ident) fd = sd_journal_stream_fd(ident, LOG_WARNING, 0); if (fd < 0) { - _W("sd_journal_stream_fd() is failed. error(%d)", fd); + if (fd != -ENOENT) + _W("sd_journal_stream_fd() is failed. error(%d)", fd); return fd; } -- 2.7.4 From 4ec25e48dc1c0abc206176e6832bfb1ea8f6126b Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 24 Jun 2020 07:33:45 +0900 Subject: [PATCH 06/16] Fix SMACK error When calling sd_journal_stream_fd() is failed, the child process used the fds of the parent. It causes SMACK errors. To prevent SMACK errors, the child process uses "/dev/null" for standard I/O redirection if calling sd_journal_stream_fd() is failed. Change-Id: Ia1816c552c8d417317d031d3945c9f89a86edb40 Signed-off-by: Hwankyu Jhun --- src/common/src/launchpad_common.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/common/src/launchpad_common.c b/src/common/src/launchpad_common.c index fdb2455..1521634 100644 --- a/src/common/src/launchpad_common.c +++ b/src/common/src/launchpad_common.c @@ -952,12 +952,22 @@ static int __redirect_stdout(const char *ident) if (fd < 0) { if (fd != -ENOENT) _W("sd_journal_stream_fd() is failed. error(%d)", fd); - return fd; + fd = open(PATH_DEV_NULL, O_WRONLY | O_NOCTTY); + if (fd < 0) { + ret = -errno; + _E("open(%s) is failed. errno(%d)", + PATH_DEV_NULL, errno); + close(STDOUT_FILENO); + return ret; + } } ret = dup2(fd, STDOUT_FILENO); - if (ret < 0) - _W("dup(%d, 1) is failed. errno(%d)", fd, errno); + if (ret < 0) { + ret = -errno; + _E("dup(%d, 1) is failed. errno(%d)", fd, errno); + close(STDOUT_FILENO); + } close(fd); return ret; @@ -972,12 +982,22 @@ static int __redirect_stderr(const char *ident) if (fd < 0) { if (fd != -ENOENT) _W("sd_journal_stream_fd() is failed. error(%d)", fd); - return fd; + fd = open(PATH_DEV_NULL, O_WRONLY | O_NOCTTY); + if (fd < 0) { + ret = -errno; + _E("open(%s) is failed. errno(%d)", + PATH_DEV_NULL, errno); + close(STDERR_FILENO); + return ret; + } } ret = dup2(fd, STDERR_FILENO); - if (ret < 0) - _W("dup(%d, 2) is failed. errno(%d)", fd, errno); + if (ret < 0) { + ret = -errno; + _E("dup(%d, 2) is failed. errno(%d)", fd, errno); + close(STDERR_FILENO); + } close(fd); return ret; -- 2.7.4 From 42ec3f45f044911da2dfda34e67102ff06424a7a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 24 Jun 2020 08:36:50 +0900 Subject: [PATCH 07/16] Release version 0.15.6 Changes: - Check the error value Before printing error logs - Fix SMACK error Change-Id: I9d40a9bd655b421d2e71e9e74247b8847a56a408 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 b0c679d..0c0cb55 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.5 +Version: 0.15.6 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 6813b19565277ac4102d3b97bc0e5039ad1cc5f5 Mon Sep 17 00:00:00 2001 From: "changyu.choi" Date: Thu, 25 Jun 2020 14:35:49 +0900 Subject: [PATCH 08/16] Change size method to 'sizeof' Change-Id: I22ae01445be913c5c4b8c890bd899bad56f71f1a Signed-off-by: changyu-choi --- src/common/src/launchpad_common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/src/launchpad_common.c b/src/common/src/launchpad_common.c index 1521634..3c61837 100644 --- a/src/common/src/launchpad_common.c +++ b/src/common/src/launchpad_common.c @@ -603,10 +603,10 @@ static bool __validate_bundle_key(const char *key) if (!key) return false; - if (!strncmp(key, "__AUL_", strlen("__AUL_"))) + if (!strncmp(key, "__AUL_", sizeof("__AUL_"))) return false; - if (!strncmp(key, "__APP_SVC_", strlen("__APP_SVC_"))) + if (!strncmp(key, "__APP_SVC_", sizeof("__APP_SVC_"))) return false; return true; -- 2.7.4 From e97b0c3c2003b3e92ac67dac53da9a766834c0ae Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 25 Jun 2020 18:57:56 +0900 Subject: [PATCH 09/16] Remove unused CMakeLists.txt file Change-Id: I1c27ed409b9cffe24cef5362e83a0df8cdfe3265 Signed-off-by: Hwankyu Jhun --- src/launchpad/src/CMakeLists.txt | 209 --------------------------------------- 1 file changed, 209 deletions(-) delete mode 100644 src/launchpad/src/CMakeLists.txt diff --git a/src/launchpad/src/CMakeLists.txt b/src/launchpad/src/CMakeLists.txt deleted file mode 100644 index 6197582..0000000 --- a/src/launchpad/src/CMakeLists.txt +++ /dev/null @@ -1,209 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET (this_target_pool launchpad_pool) -SET (this_target_loader launchpad_loader) -SET (this_target_lib launchpad) -SET (this_target_hydra launchpad_hydra) - -INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(${this_target_pool} REQUIRED - dlog - libsystemd - security-manager - tanchor - bundle - gio-2.0 - ttrace - vconf - libtzplatform-config - libcap - dbus-1 - iniparser - ) - -FOREACH(flag ${${this_target_pool}_CFLAGS}) - SET(EXTRA_CFLAGS_pool "${EXTRA_CFLAGS_pool} ${flag}") -ENDFOREACH(flag) - -PKG_CHECK_MODULES(${this_target_loader} REQUIRED - dlog - ecore - elementary - security-manager - libtzplatform-config - tanchor - bundle - aul - vconf - buxton2 - libsystemd - gio-2.0 - dbus-1 - libcap - ) - -FOREACH(flag ${${this_target_loader}_CFLAGS}) - SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${flag}") -ENDFOREACH(flag) - -PKG_CHECK_MODULES(${this_target_lib} REQUIRED - dlog - bundle - aul - security-manager - libtzplatform-config - tanchor - dbus-1 - libcap - ) - -FOREACH(flag ${${this_target_lib}_CFLAGS}) - SET(EXTRA_CFLAGS_lib "${EXTRA_CFLAGS_lib} ${flag}") -ENDFOREACH(flag) - -PKG_CHECK_MODULES(${this_target_hydra} REQUIRED - dlog - libsystemd) - -FOREACH(flag ${${this_target_hydra}_CFLAGS}) - SET(EXTRA_CFLAGS_hydra "${EXTRA_CFLAGS_hydra} ${flag}") -ENDFOREACH(flag) - -SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -Wl,-zdefs" ) -SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -fvisibility=hidden") -SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -fdata-sections -ffunction-sections -Wl,--gc-sections") -SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -D_FILE_OFFSET_BITS=64") -SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} -Werror") - -IF(_TIZEN_FEATURE_PRELINK) -MESSAGE(STATUS "[__PRELINK__] Enable") -SET(EXTRA_CFLAGS_pool "${EXTRA_CFLAGS_pool} ${EXTRA_CFLAGS_common}") -SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${EXTRA_CFLAGS_common}") -ELSE(_TIZEN_FEATURE_PRELINK) -MESSAGE(STATUS "[__PRELINK__] Disable") -SET(EXTRA_CFLAGS_pool "${EXTRA_CFLAGS_pool} ${EXTRA_CFLAGS_common} -fPIE") -SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${EXTRA_CFLAGS_common} -fPIE") -ENDIF(_TIZEN_FEATURE_PRELINK) - -SET(EXTRA_CFLAGS_lib "${EXTRA_CFLAGS_lib} ${EXTRA_CFLAGS_common}") -SET(EXTRA_CFLAGS_hydra "${EXTRA_CFLAGS_hydra} ${EXTRA_CFLAGS_common}") - -SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") -SET(CMAKE_C_FLAGS_RELEASE "-O2") -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") - -ADD_DEFINITIONS("-DSHARE_PREFIX=\"/usr/share/aul\"") -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) -IF(_TIZEN_FEATURE_SET_PERSONALITY_32) - ADD_DEFINITIONS("-DTIZEN_FEATURE_SET_PERSONALITY_32") -ENDIF(_TIZEN_FEATURE_SET_PERSONALITY_32) - -ADD_DEFINITIONS("-DLAUNCHPAD_LOG") -ADD_DEFINITIONS("-DPRELOAD_ACTIVATE") -ADD_DEFINITIONS("-DPREEXEC_ACTIVATE") -#ADD_DEFINITIONS("-DPERF_ACTIVATE") - -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc) - -# launchpad-loader -SET(LAUNCHPAD_LOADER "launchpad-loader") -SET(${LAUNCHPAD_LOADER}_SOURCE_FILES - src/launchpad_loader.c - src/launchpad_common.c - src/launchpad_lib.c - ) -ADD_EXECUTABLE(${LAUNCHPAD_LOADER} ${${LAUNCHPAD_LOADER}_SOURCE_FILES}) - -# To support 2.x applications which use their own shared libraries. -# Since we cannot set LD_LIBRARY_PATH directly by security issue, we make the -# dynamic linker looks in the CWD forcely. -TARGET_LINK_LIBRARIES(${LAUNCHPAD_LOADER} "-ldl -Wl,-rpath,: -Wl,--disable-new-dtags") - -IF(_TIZEN_FEATURE_PRELINK) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_LOADER} ${${this_target_loader}_LDFLAGS}) -ELSE(_TIZEN_FEATURE_PRELINK) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_LOADER} ${${this_target_loader}_LDFLAGS} "-pie") -ENDIF(_TIZEN_FEATURE_PRELINK) - -SET_TARGET_PROPERTIES(${LAUNCHPAD_LOADER} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_loader}) -SET_TARGET_PROPERTIES(${LAUNCHPAD_LOADER} - PROPERTIES SKIP_BUILD_RPATH TRUE - ) # remove rpath option that is automatically generated by cmake. -INSTALL(TARGETS ${LAUNCHPAD_LOADER} DESTINATION bin) - -# launchpad-process-pool -SET(LAUNCHPAD_PROCESS_POOL "launchpad-process-pool") -SET(${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES - src/launchpad.c - src/launchpad_common.c - src/loader_info.c - src/launcher_info.c - src/debugger_info.c - src/launchpad_debug.c - src/launchpad_signal.c - src/launchpad_config.c - src/launchpad_io_channel.c - src/launchpad_inotify.c - ) -ADD_EXECUTABLE(${LAUNCHPAD_PROCESS_POOL} ${${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES}) - -IF(_TIZEN_FEATURE_PRELINK) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${${this_target_pool}_LDFLAGS} "-lm") -ELSE(_TIZEN_FEATURE_PRELINK) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${${this_target_pool}_LDFLAGS} "-pie -lm") -ENDIF(_TIZEN_FEATURE_PRELINK) -SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_pool}) -SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL} - PROPERTIES SKIP_BUILD_RPATH TRUE - ) # remove rpath option that is automatically generated by cmake. - -CONFIGURE_FILE(packaging/default.debugger.in packaging/default.debugger @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/default.debugger DESTINATION share/aul) -INSTALL(TARGETS ${LAUNCHPAD_PROCESS_POOL} DESTINATION bin) - -CONFIGURE_FILE(packaging/default.loader.in packaging/default.loader @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/default.loader DESTINATION share/aul) - -CONFIGURE_FILE(conf/launchpad.conf.in conf/launchpad.conf @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/launchpad.conf DESTINATION share/aul) - -# liblaunchpad -SET(LAUNCHPAD_LIB "launchpad") -ADD_LIBRARY(${LAUNCHPAD_LIB} SHARED - src/launchpad_lib.c - src/launchpad_common.c - ) -SET_TARGET_PROPERTIES(${LAUNCHPAD_LIB} PROPERTIES SOVERSION ${MAJORVER}) -SET_TARGET_PROPERTIES(${LAUNCHPAD_LIB} PROPERTIES VERSION ${VERSION}) -SET_TARGET_PROPERTIES(${LAUNCHPAD_LIB} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_lib}) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_LIB} ${${this_target_lib}_LDFLAGS} "-ldl") - -INSTALL(TARGETS ${LAUNCHPAD_LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/inc/launchpad.h DESTINATION include/launchpad) -CONFIGURE_FILE(launchpad.pc.in launchpad.pc @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/launchpad.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) -CONFIGURE_FILE(launchpad.pc.in liblaunchpad.pc @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/liblaunchpad.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) - -# liblaunchpad_hydra -SET(LAUNCHPAD_HYDRA "launchpad-hydra") -ADD_LIBRARY(${LAUNCHPAD_HYDRA} SHARED - src/launchpad_hydra.c - ) -SET_TARGET_PROPERTIES(${LAUNCHPAD_HYDRA} PROPERTIES SOVERSION ${MAJORVER}) -SET_TARGET_PROPERTIES(${LAUNCHPAD_HYDRA} PROPERTIES VERSION ${VERSION}) -SET_TARGET_PROPERTIES(${LAUNCHPAD_HYDRA} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_hydra}) -TARGET_LINK_LIBRARIES(${LAUNCHPAD_HYDRA} ${${this_target_hydra}_LDFLAGS} "-ldl") - -INSTALL(TARGETS ${LAUNCHPAD_HYDRA} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/inc/launchpad_hydra.h DESTINATION include/launchpad) - -CONFIGURE_FILE(liblaunchpad-hydra.pc.in liblaunchpad-hydra.pc @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/liblaunchpad-hydra.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) - -# parser -ADD_SUBDIRECTORY(parser) \ No newline at end of file -- 2.7.4 From f6601b379e797f7e39dc40950d276722f81f6eec Mon Sep 17 00:00:00 2001 From: "changyu.choi" Date: Thu, 25 Jun 2020 17:55:03 +0900 Subject: [PATCH 10/16] Revert "Change size method to 'sizeof'" This reverts commit 6813b19565277ac4102d3b97bc0e5039ad1cc5f5. Change-Id: I242026d861b6f9dcc6a3fc847ffdb9aad68682a0 Signed-off-by: changyu-choi --- src/common/src/launchpad_common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/src/launchpad_common.c b/src/common/src/launchpad_common.c index 3c61837..1521634 100644 --- a/src/common/src/launchpad_common.c +++ b/src/common/src/launchpad_common.c @@ -603,10 +603,10 @@ static bool __validate_bundle_key(const char *key) if (!key) return false; - if (!strncmp(key, "__AUL_", sizeof("__AUL_"))) + if (!strncmp(key, "__AUL_", strlen("__AUL_"))) return false; - if (!strncmp(key, "__APP_SVC_", sizeof("__APP_SVC_"))) + if (!strncmp(key, "__APP_SVC_", strlen("__APP_SVC_"))) return false; return true; -- 2.7.4 From f15e2ec921d5eb11495345db0fe2e6f2c0001d5c Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 26 Jun 2020 14:33:53 +0900 Subject: [PATCH 11/16] Handle returned events When IO_ERR, IO_HUP or IO_NVAL is delivered, Launchpad tries to recover the socket. If it's failed, Launchpad uses abort() to terminate itself abnormally. Change-Id: I0680c5a6b1899d3dac22459361a927a2591478fc Signed-off-by: Hwankyu Jhun --- src/launchpad/inc/launchpad_signal.h | 2 + src/launchpad/src/launchpad.c | 77 ++++++++++++++++++++-- src/launchpad/src/launchpad_signal.c | 123 +++++++++++++++++++++++++++++------ 3 files changed, 175 insertions(+), 27 deletions(-) diff --git a/src/launchpad/inc/launchpad_signal.h b/src/launchpad/inc/launchpad_signal.h index aea5654..dffd961 100644 --- a/src/launchpad/inc/launchpad_signal.h +++ b/src/launchpad/inc/launchpad_signal.h @@ -25,6 +25,8 @@ typedef void (*signal_sigchld_cb)(int pid, void *user_data); int _signal_set_sigchld_cb(signal_sigchld_cb callback, void *user_data); +int _signal_unblock_sigchld(void); + int _signal_init(void); void _signal_fini(void); diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c index 02aab1b..9751138 100644 --- a/src/launchpad/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -192,6 +192,8 @@ static bool __is_low_memory(void); static void __update_slot_state(candidate_process_context_t *cpc, int method, bool force); static void __init_app_defined_loader_monitor(void); +static gboolean __launchpad_recovery_cb(gpointer data); +static gboolean __logger_recovery_cb(gpointer data); static gboolean __handle_queuing_slots(gpointer data) { @@ -781,7 +783,7 @@ static int __exec_loader_process(void *arg) char err_buf[1024]; _send_cmd_to_amd(LAUNCHPAD_CHILD_PROCESS); - _signal_fini(); + _signal_unblock_sigchld(); _close_all_fds(); _setup_stdio(basename(argv[LOADER_ARG_PATH])); @@ -1296,7 +1298,7 @@ static int __exec_app_process(void *arg) if (bundle_get_type(launch_arg->kb, AUL_K_SDK) != BUNDLE_TYPE_NONE) _debug_prepare_debugger(launch_arg->kb); - _signal_fini(); + _signal_unblock_sigchld(); _delete_sock_path(getpid(), getuid()); @@ -1517,6 +1519,12 @@ static bool __handle_label_monitor(int fd, io_condition_e cond, void *data) candidate_process_context_t *cpc; GList *iter = candidate_slot_list; + if (cond & (IO_ERR | IO_HUP | IO_NVAL)) { + _E("fd(%d), io_condition(%d)", fd, cond); + abort(); + return false; + } + _D("%s()", __FUNCTION__); security_manager_app_labels_monitor_process(label_monitor); @@ -2028,6 +2036,13 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) int loader_id; int ret; + if (cond & (IO_ERR | IO_HUP | IO_NVAL)) { + _E("fd(%d), condition(%d)", fd, cond); + g_idle_add(__launchpad_recovery_cb, __launchpad_channel); + __launchpad_channel = NULL; + return false; + } + traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "LAUNCHPAD:LAUNCH"); pkt = _accept_recv_pkt_raw(fd, &clifd, &cr); if (!pkt) { @@ -2408,7 +2423,8 @@ static int __remove_slot(int type, int loader_id) static int __init_launchpad_fd(int argc, char **argv) { - int fd = -1; + io_condition_e cond; + int fd; fd = __launchpad_pre_init(argc, argv); if (fd < 0) { @@ -2416,7 +2432,8 @@ static int __init_launchpad_fd(int argc, char **argv) return -1; } - __launchpad_channel = _io_channel_create(fd, IO_IN, + cond = IO_IN | IO_PRI | IO_HUP | IO_ERR | IO_NVAL; + __launchpad_channel = _io_channel_create(fd, cond, __handle_launch_event, NULL); if (!__launchpad_channel) { close(fd); @@ -2507,6 +2524,7 @@ static void __init_app_defined_loader_monitor(void) static int __init_label_monitor_fd(void) { + io_condition_e cond; int r; int fd = -1; @@ -2524,7 +2542,8 @@ static int __init_label_monitor_fd(void) goto err; } - __label_monitor_channel = _io_channel_create(fd, IO_IN, + cond = IO_IN | IO_PRI | IO_HUP | IO_ERR | IO_NVAL; + __label_monitor_channel = _io_channel_create(fd, cond, __handle_label_monitor, NULL); if (!__label_monitor_channel) goto err; @@ -2840,6 +2859,13 @@ static bool __handle_logger(int fd, io_condition_e cond, void *data) struct ucred cr; int clifd = -1; + if (cond & (IO_ERR | IO_HUP | IO_NVAL)) { + _E("fd(%d), io_condition(%d)", fd, cond); + g_idle_add(__logger_recovery_cb, __logger_channel); + __logger_channel = NULL; + return false; + } + pkt = _accept_recv_pkt_raw(fd, &clifd, &cr); if (!pkt) { _E("Failed to receive the packet"); @@ -2868,6 +2894,7 @@ end: static int __init_logger_fd(void) { + io_condition_e cond; int fd; fd = _create_server_sock(LAUNCHPAD_LOGGER_SOCK); @@ -2876,7 +2903,8 @@ static int __init_logger_fd(void) return -1; } - __logger_channel = _io_channel_create(fd, IO_IN, __handle_logger, NULL); + cond = IO_IN | IO_PRI | IO_ERR | IO_HUP | IO_NVAL; + __logger_channel = _io_channel_create(fd, cond, __handle_logger, NULL); if (!__logger_channel) { close(fd); return -1; @@ -2914,6 +2942,43 @@ static int __memory_monitor_cb(bool low_memory, void *user_data) return 0; } +static gboolean __logger_recovery_cb(gpointer data) +{ + io_channel_h channel = data; + int ret; + + _io_channel_destroy(channel); + + ret = __init_logger_fd(); + if (ret < 0) { + _E("Failed to recover logger socket"); + return G_SOURCE_REMOVE; + } + + _E("[__RECOVERY__] Logger socket"); + + return G_SOURCE_REMOVE; +} + +static gboolean __launchpad_recovery_cb(gpointer data) +{ + io_channel_h channel = data; + int ret; + + _io_channel_destroy(channel); + + ret = __init_launchpad_fd(0, NULL); + if (ret < 0) { + _E("Failed to recover launchpad socket"); + abort(); + return G_SOURCE_REMOVE; + } + + _E("[__RECOVERY__] Launchpad socket"); + + return G_SOURCE_REMOVE; +} + static int __before_loop(int argc, char **argv) { int ret; diff --git a/src/launchpad/src/launchpad_signal.c b/src/launchpad/src/launchpad_signal.c index 5ee3067..6212ca4 100644 --- a/src/launchpad/src/launchpad_signal.c +++ b/src/launchpad/src/launchpad_signal.c @@ -36,6 +36,7 @@ #define HYDRA_SIGCHLD_SOCK ".hydra-sigchld-sock" static pid_t __pid; +static sigset_t __mask; static sigset_t __old_mask; static socket_h __sigchld_socket; static io_channel_h __sigchld_channel; @@ -44,6 +45,9 @@ static io_channel_h __hydra_sigchld_channel; static signal_sigchld_cb __callback; static void *__user_data; +static gboolean __hydra_sigchld_recovery_cb(gpointer data); +static gboolean __sigchld_recovery_cb(gpointer data); + static void __socket_garbage_collector(void) { DIR *dp; @@ -99,6 +103,12 @@ static bool __hydra_sigchld_handler(int fd, io_condition_e cond, int pid = -1; int ret; + if (cond & (IO_ERR | IO_HUP | IO_NVAL)) { + _E("fd(%d), io_condition(%d)", fd, cond); + g_idle_add(__hydra_sigchld_recovery_cb, NULL); + return false; + } + ret = _socket_accept(__hydra_sigchld_socket, &client_socket); if (ret < 0) return true; @@ -130,6 +140,7 @@ static int __hydra_sigchld_init(void) { char path[LAUNCHPAD_SOCKET_PATH_SIZE]; io_channel_h channel; + io_condition_e cond; socket_h socket; int ret; int fd; @@ -142,7 +153,8 @@ static int __hydra_sigchld_init(void) _socket_get_fd(socket, &fd); - channel = _io_channel_create(fd, IO_IN | IO_PRI, + cond = IO_IN | IO_PRI | IO_ERR | IO_HUP | IO_NVAL; + channel = _io_channel_create(fd, cond, __hydra_sigchld_handler, NULL); if (!channel) { _socket_destroy(socket); @@ -180,6 +192,12 @@ static bool __sigchld_handler(int fd, io_condition_e cond, void *user_data) int status; int ret; + if (cond & (IO_ERR | IO_HUP | IO_NVAL)) { + _E("fd(%d), io_condition(%d)", fd, cond); + g_idle_add(__sigchld_recovery_cb, NULL); + return false; + } + do { ret = _socket_read(__sigchld_socket, &info, sizeof(info)); if (ret < 0) @@ -203,38 +221,71 @@ static bool __sigchld_handler(int fd, io_condition_e cond, void *user_data) return true; } -static int __sigchld_init(void) +static int __signal_block_sigchld(void) { - io_channel_h channel; - socket_h socket; - sigset_t mask; - int sfd; int ret; - sigemptyset(&mask); - sigaddset(&mask, SIGCHLD); + sigemptyset(&__mask); + sigaddset(&__mask, SIGCHLD); - ret = sigprocmask(SIG_BLOCK, &mask, &__old_mask); + ret = sigprocmask(SIG_BLOCK, &__mask, &__old_mask); if (ret < 0) { ret = -errno; _E("sigprocmask(SIG_BLOCK) is failed. errno(%d)", errno); return ret; } - sfd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC); + return 0; +} + +static int __signal_get_sigchld_fd(void) +{ + int sfd; + + sfd = signalfd(-1, &__mask, SFD_NONBLOCK | SFD_CLOEXEC); if (sfd < 0) { - ret = -errno; + sfd = -errno; _E("signalfd() is failed. errno(%d)", errno); + return sfd; + } + + return sfd; +} + +int _signal_unblock_sigchld(void) +{ + int ret; + + ret = sigprocmask(SIG_SETMASK, &__old_mask, NULL); + if (ret < 0) { + ret = -errno; + _E("sigprocmask(SIG_SETMASK) is failed. errno(%d)", errno); return ret; } + return 0; +} + +static int __sigchld_init(void) +{ + io_channel_h channel; + io_condition_e cond; + socket_h socket; + int sfd; + int ret; + + sfd = __signal_get_sigchld_fd(); + if (sfd < 0) + return sfd; + ret = _socket_create_with_fd(sfd, &socket); if (ret < 0) { close(sfd); return ret; } - channel = _io_channel_create(sfd, IO_IN | IO_PRI, + cond = IO_IN | IO_PRI | IO_ERR | IO_HUP | IO_NVAL; + channel = _io_channel_create(sfd, cond, __sigchld_handler, NULL); if (!channel) { _socket_destroy(socket); @@ -250,8 +301,6 @@ static int __sigchld_init(void) static int __sigchld_fini(void) { - int ret; - if (__sigchld_channel) _io_channel_destroy(__sigchld_channel); @@ -262,13 +311,6 @@ static int __sigchld_fini(void) _socket_destroy(__sigchld_socket); } - ret = sigprocmask(SIG_SETMASK, &__old_mask, NULL); - if (ret < 0) { - ret = -errno; - _E("sigprocmask(SIG_SETMASK) is failed. errno(%d)", errno); - return ret; - } - return 0; } @@ -280,6 +322,40 @@ int _signal_set_sigchld_cb(signal_sigchld_cb callback, void *user_data) return 0; } +static gboolean __hydra_sigchld_recovery_cb(gpointer data) +{ + int ret; + + __hydra_sigchld_fini(); + + ret = __hydra_sigchld_init(); + if (ret < 0) { + _E("Failed to recover hydra sigchld socket"); + abort(); + } else { + _W("[__RECOVERY__] Hydra SIGCHLD Socket"); + } + + return G_SOURCE_REMOVE; +} + +static gboolean __sigchld_recovery_cb(gpointer data) +{ + int ret; + + __sigchld_fini(); + + ret = __sigchld_init(); + if (ret < 0) { + _E("Failed to recover sigchld fd"); + abort(); + } else { + _W("[__RECOVERY__] SIGCHLD fd"); + } + + return G_SOURCE_REMOVE; +} + int _signal_init(void) { int ret; @@ -288,6 +364,10 @@ int _signal_init(void) _D("SIGNAL_INIT"); __pid = getpid(); + ret = __signal_block_sigchld(); + if (ret < 0) + return ret; + ret = __sigchld_init(); if (ret < 0) return ret; @@ -329,4 +409,5 @@ void _signal_fini(void) _signal_set_sigchld_cb(NULL, NULL); __hydra_sigchld_fini(); __sigchld_fini(); + _signal_unblock_sigchld(); } -- 2.7.4 From 5acb3702c72394e966b78b5c0863f22587b10e29 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 26 Jun 2020 15:31:58 +0900 Subject: [PATCH 12/16] Add a file log for debugging launchpad "/var/log/appfw/launchpad/launchpad.log" is added. Change-Id: I280d010bb048671c66f4fe0eed698977335a4a61 Signed-off-by: Hwankyu Jhun --- src/common/inc/launchpad_logger.h | 40 ++++++++ src/common/src/launchpad_logger.c | 195 ++++++++++++++++++++++++++++++++++++++ src/launchpad/inc/launchpad_log.h | 34 +++++++ src/launchpad/src/launchpad.c | 12 ++- src/launchpad/src/launchpad_log.c | 71 ++++++++++++++ 5 files changed, 351 insertions(+), 1 deletion(-) create mode 100644 src/common/inc/launchpad_logger.h create mode 100644 src/common/src/launchpad_logger.c create mode 100644 src/launchpad/inc/launchpad_log.h create mode 100644 src/launchpad/src/launchpad_log.c diff --git a/src/common/inc/launchpad_logger.h b/src/common/inc/launchpad_logger.h new file mode 100644 index 0000000..a54ebb7 --- /dev/null +++ b/src/common/inc/launchpad_logger.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LAUNCHPAD_LOGGER_H__ +#define __LAUNCHPAD_LOGGER_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define LAUNCHPAD_LOG_MAX_STRING_SIZE 128 + +typedef struct logger_s *logger_h; + +int _logger_create(const char *path, logger_h *handle); + +int _logger_destroy(logger_h handle); + +int _logger_print(logger_h handle, const char *tag, const char *format, ...); + +int _logger_get_fd(logger_h handle, int *fd); + +#ifdef __cplusplus +} +#endif + +#endif /* __LAUNCHPAD_LOGGER_H__ */ diff --git a/src/common/src/launchpad_logger.c b/src/common/src/launchpad_logger.c new file mode 100644 index 0000000..a4e6b7f --- /dev/null +++ b/src/common/src/launchpad_logger.c @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "launchpad_logger.h" +#include "log_private.h" + +#define LAUNCHPAD_LOG_APPFW_PATH "/var/log/appfw" +#define LAUNCHPAD_LOG_PATH "/var/log/appfw/launchpad" +#define LAUNCHPAD_LOG_MAX_SIZE 2500 +#define LAUNCHPAD_LOG_MAX_BUFFER_SIZE 256 + +struct logger_s { + int fd; + int index; +}; + +static int __create_directory(const char *path) +{ + mode_t mode; + int ret; + + ret = access(path, F_OK); + if (ret == 0) + return 0; + + mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP; + ret = mkdir(path, mode); + if (ret < 0) { + ret = -errno; + _E("Failed to create directory(%s). errno(%d)", path, errno); + return ret; + } + + return 0; +} + +static int __create_launchpad_directories(void) +{ + int ret; + + ret = __create_directory(LAUNCHPAD_LOG_APPFW_PATH); + if (ret < 0) + return ret; + + ret = __create_directory(LAUNCHPAD_LOG_PATH); + if (ret < 0) + return ret; + + return 0; +} + +int _logger_create(const char *path, logger_h *handle) +{ + struct logger_s *logger; + off_t offset; + int ret; + + if (!path || !handle) { + _E("Invalid parameter"); + return -EINVAL; + } + + ret = __create_launchpad_directories(); + if (ret < 0) + return ret; + + logger = calloc(1, sizeof(struct logger_s)); + if (!logger) { + _E("Out of memory"); + return -ENOMEM; + } + + logger->fd = open(path, O_CREAT | O_WRONLY, 0640); + if (logger->fd < 0) { + ret = -errno; + _E("Failed to open path(%s), errno(%d)", path, errno); + _logger_destroy(logger); + return ret; + } + + offset = lseek(logger->fd, 0, SEEK_END); + if (offset != 0) { + logger->index = (int)(offset / LAUNCHPAD_LOG_MAX_STRING_SIZE); + if (logger->index >= LAUNCHPAD_LOG_MAX_SIZE) { + logger->index = 0; + lseek(logger->fd, 0, SEEK_SET); + } + } + + *handle = logger; + + return 0; +} + +int _logger_destroy(logger_h handle) +{ + if (!handle) { + _E("Invalid parameter"); + return -EINVAL; + } + + if (handle->fd > 0) + close(handle->fd); + + free(handle); + + return 0; +} + +int _logger_print(logger_h handle, const char *tag, const char *format, ...) +{ + char buf[LAUNCHPAD_LOG_MAX_BUFFER_SIZE]; + char format_buf[128]; + struct tm tm = { 0, }; + time_t t; + ssize_t ret; + va_list ap; + off_t offset; + + if (!handle || !tag || !format) { + _E("Invalid parameter"); + return -EINVAL; + } + + t = time(NULL); + localtime_r(&t, &tm); + + if (handle->index != 0) + offset = lseek(handle->fd, 0, SEEK_CUR); + else + offset = lseek(handle->fd, 0, SEEK_SET); + + if (offset == -1) + _E("lseek() is failed. errno(%d)", errno); + + va_start(ap, format); + vsnprintf(format_buf, sizeof(format_buf), format, ap); + va_end(ap); + + snprintf(buf, sizeof(buf), + "[%6d] %04d-%02d-%02d %02d:%02d:%02d %-16s %-100s\n", + handle->index, + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec, + tag, format_buf); + ret = write(handle->fd, buf, strlen(buf)); + if (ret < 0) { + ret = -errno; + _E("Failed to write log message. errno(%d)", errno); + return ret; + } + + if (++handle->index >= LAUNCHPAD_LOG_MAX_SIZE) + handle->index = 0; + + return ret; +} + +int _logger_get_fd(logger_h handle, int *fd) +{ + if (!handle || !fd) { + _E("Invalid parameter"); + return -EINVAL; + } + + *fd = handle->fd; + + return 0; +} diff --git a/src/launchpad/inc/launchpad_log.h b/src/launchpad/inc/launchpad_log.h new file mode 100644 index 0000000..8e3cd89 --- /dev/null +++ b/src/launchpad/inc/launchpad_log.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LAUNCHPAD_LOG_H__ +#define __LAUNCHPAD_LOG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +int _log_print(const char *tag, const char *format, ...); + +int _log_init(void); + +void _log_fini(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __LAUNCHPAD_LOG_H__ */ diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c index 9751138..1f1d21c 100644 --- a/src/launchpad/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -47,6 +47,7 @@ #include "launchpad_debug.h" #include "launchpad_inotify.h" #include "launchpad_io_channel.h" +#include "launchpad_log.h" #include "launchpad_memory_monitor.h" #include "launchpad_plugin.h" #include "launchpad_proc.h" @@ -893,6 +894,8 @@ static int __prepare_candidate_process(int type, int loader_id) __set_live_timer(cpt); } + _log_print("[CANDIDATE]", "pid(%7d) | type(%d) | loader(%s)", + pid, cpt->loader_id, cpt->loader_name); _memory_monitor_reset_timer(); return 0; @@ -1493,6 +1496,7 @@ static void __handle_sigchild(int pid, void *user_data) g_hash_table_remove(__pid_table, GINT_TO_POINTER(pid)); } + _log_print("[SIGCHLD]", "pid(%7d)", pid); cpc = __find_slot_from_pid(pid); if (cpc != NULL) { cpc->pid = CANDIDATE_NONE; @@ -1525,7 +1529,7 @@ static bool __handle_label_monitor(int fd, io_condition_e cond, void *data) return false; } - _D("%s()", __FUNCTION__); + _log_print("[LABEL]", "fd(%d), condition(%d)", fd, cond); security_manager_app_labels_monitor_process(label_monitor); while (iter) { @@ -2209,6 +2213,8 @@ end: _dbus_send_app_launch_signal(pid, menu_info->appid); g_hash_table_insert(__pid_table, GINT_TO_POINTER(pid), strdup(menu_info->appid)); + _log_print("[LAUNCH]", "pid(%7d) | appid(%s)", + pid, menu_info->appid); } if (menu_info != NULL) @@ -2883,6 +2889,8 @@ static bool __handle_logger(int fd, io_condition_e cond, void *data) } _E("[%d] %s", cr.pid, (const char *)pkt->data); + _log_print("[ERROR]", "pid(%7d) | message(%s)", + cr.pid, (const char *)pkt->data); end: if (clifd != -1) close(clifd); @@ -3045,12 +3053,14 @@ static int __before_loop(int argc, char **argv) __init_app_defined_loader_monitor(); _memory_monitor_init(); _memory_monitor_set_event_cb(__memory_monitor_cb, NULL); + _log_init(); return 0; } static void __after_loop(void) { + _log_fini(); _memory_monitor_fini(); __unregister_vconf_events(); if (__pid_table) diff --git a/src/launchpad/src/launchpad_log.c b/src/launchpad/src/launchpad_log.c new file mode 100644 index 0000000..00acc46 --- /dev/null +++ b/src/launchpad/src/launchpad_log.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE +#include +#include + +#include "launchpad_log.h" +#include "launchpad_logger.h" +#include "log_private.h" + +#define PATH_LAUNCHPAD_LOG "/var/log/appfw/launchpad/launchpad.log" + +static logger_h __logger; + +int _log_print(const char *tag, const char *format, ...) +{ + char formatted_buf[LAUNCHPAD_LOG_MAX_STRING_SIZE]; + va_list ap; + int ret; + + if (!__logger) { + ret = _logger_create(PATH_LAUNCHPAD_LOG, &__logger); + if (ret != 0) { + _E("Failed to create log file. error(%d)", ret); + return -1; + } + } + + va_start(ap, format); + vsnprintf(formatted_buf, sizeof(formatted_buf), format, ap); + va_end(ap); + + return _logger_print(__logger, tag, formatted_buf); +} + +int _log_init(void) +{ + int ret; + + _W("LOG_INIT"); + + ret = _logger_create(PATH_LAUNCHPAD_LOG, &__logger); + if (ret != 0) { + _E("Failed to create log file. error(%d)", ret); + return ret; + } + + return 0; +} + +void _log_fini(void) +{ + _W("LOG_FINI"); + + if (__logger) + _logger_destroy(__logger); +} -- 2.7.4 From 21dcd7f72efe9cd4772071a28a8c3f0a62818940 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 30 Jun 2020 12:53:53 +0900 Subject: [PATCH 13/16] Change SMACK label of the log file Change-Id: Ib07f8c8b69065a817626557c2f1dc18698ff9941 Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 1 + src/launchpad/CMakeLists.txt | 1 + src/{common => launchpad}/inc/launchpad_logger.h | 0 src/{common => launchpad}/src/launchpad_logger.c | 30 ++++++++++++++++++++++++ 4 files changed, 32 insertions(+) rename src/{common => launchpad}/inc/launchpad_logger.h (100%) rename src/{common => launchpad}/src/launchpad_logger.c (87%) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 0c0cb55..198bc46 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -30,6 +30,7 @@ BuildRequires: pkgconfig(tanchor) BuildRequires: pkgconfig(dbus-1) BuildRequires: pkgconfig(iniparser) BuildRequires: pkgconfig(libxml-2.0) +BuildRequires: pkgconfig(libsmack) Requires(post): /sbin/ldconfig Requires(post): /usr/bin/systemctl diff --git a/src/launchpad/CMakeLists.txt b/src/launchpad/CMakeLists.txt index 39ce5c8..ad10ae0 100644 --- a/src/launchpad/CMakeLists.txt +++ b/src/launchpad/CMakeLists.txt @@ -10,6 +10,7 @@ PKG_CHECK_MODULES(LAUNCHPAD_PROCESS_POOL_PKGS REQUIRED gio-2.0 iniparser libcap + libsmack libsystemd libtzplatform-config security-manager diff --git a/src/common/inc/launchpad_logger.h b/src/launchpad/inc/launchpad_logger.h similarity index 100% rename from src/common/inc/launchpad_logger.h rename to src/launchpad/inc/launchpad_logger.h diff --git a/src/common/src/launchpad_logger.c b/src/launchpad/src/launchpad_logger.c similarity index 87% rename from src/common/src/launchpad_logger.c rename to src/launchpad/src/launchpad_logger.c index a4e6b7f..0a32b7e 100644 --- a/src/common/src/launchpad_logger.c +++ b/src/launchpad/src/launchpad_logger.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,21 @@ struct logger_s { int index; }; +static int __set_smack_label(const char *path, const char *label) +{ + int ret; + + ret = smack_setlabel(path, label, SMACK_LABEL_ACCESS); + if (ret != 0) { + ret = -errno; + _E("smack_setlabel() is failed. path(%s), label(%s), errno(%d)", + path, label, errno); + return ret; + } + + return 0; +} + static int __create_directory(const char *path) { mode_t mode; @@ -68,10 +84,18 @@ static int __create_launchpad_directories(void) if (ret < 0) return ret; + ret = __set_smack_label(LAUNCHPAD_LOG_APPFW_PATH, "_"); + if (ret < 0) + return ret; + ret = __create_directory(LAUNCHPAD_LOG_PATH); if (ret < 0) return ret; + ret = __set_smack_label(LAUNCHPAD_LOG_PATH, "User"); + if (ret < 0) + return ret; + return 0; } @@ -104,6 +128,12 @@ int _logger_create(const char *path, logger_h *handle) return ret; } + ret = __set_smack_label(path, "User"); + if (ret < 0) { + _logger_destroy(logger); + return ret; + } + offset = lseek(logger->fd, 0, SEEK_END); if (offset != 0) { logger->index = (int)(offset / LAUNCHPAD_LOG_MAX_STRING_SIZE); -- 2.7.4 From bfb27be798364f18b1fa23dd972f94f016becc7f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 30 Jun 2020 13:19:16 +0900 Subject: [PATCH 14/16] Release version 0.15.7 Changes: - Change size method to 'sizeof' - Remove unused CMakeLists.txt file - Revert "Change size method to 'sizeof'" - Handle returned events - Add a file log for debugging launchpad - Change SMACK label of the log file Change-Id: I06a676ee851b0a678496c1f4b4c53843328187f5 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 198bc46..fe40eb5 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.6 +Version: 0.15.7 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 012ea89d9cd1b84dd12956e823d19503c4a4d6ed Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 30 Jun 2020 14:38:01 +0900 Subject: [PATCH 15/16] Include missing header file Change-Id: I5c671b8fc280457632fdf163104b2bf1de8626f6 Signed-off-by: Hwankyu Jhun --- src/launchpad/src/launchpad_dbus.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/launchpad/src/launchpad_dbus.c b/src/launchpad/src/launchpad_dbus.c index e408b3c..0b3f298 100644 --- a/src/launchpad/src/launchpad_dbus.c +++ b/src/launchpad/src/launchpad_dbus.c @@ -16,6 +16,7 @@ #define _GNU_SOURCE #include +#include #include #include -- 2.7.4 From 016473c80e3c09736035430b3b86dfda76e5f45a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 30 Jun 2020 15:12:45 +0900 Subject: [PATCH 16/16] Release version 0.15.8 Changes: - Include missing header file Change-Id: I2e260900474094b74e5299754864b6a190234da3 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 fe40eb5..f9660e6 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.7 +Version: 0.15.8 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4