From 6de87bbcf91f9e2bd955b08ab7275429cf7a8533 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 22 Sep 2020 14:48:25 +0900 Subject: [PATCH 01/16] Release version 0.15.21 Changes: - Fix directory hierarchy & cmake configuration files Change-Id: I82bae4a397bb7a02f04bae3198dff0ec872341f0 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 d400b32..0545d95 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.20 +Version: 0.15.21 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From b527c120dcfa939426befa5bfe1dd9b0784ff7e9 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Tue, 29 Sep 2020 12:33:04 +0900 Subject: [PATCH 02/16] Refactor coding style - Fix some coding style - Change to make_shared instead of constructor - Use std::move() Change-Id: I8e2991eb98e68666cc880a5271204aaa548a41f0 Signed-off-by: Changgyu Choi --- src/app-defined-loader/src/app-defined-loader.cc | 35 +++++++++--------- src/app-defined-loader/src/config.hh | 1 - src/launchpad-parser/launchpad_parser_plugin.cc | 45 +++++++++++++----------- src/launchpad-parser/loader_info.cc | 11 +++--- src/launchpad-parser/loader_info.hh | 2 +- 5 files changed, 46 insertions(+), 48 deletions(-) diff --git a/src/app-defined-loader/src/app-defined-loader.cc b/src/app-defined-loader/src/app-defined-loader.cc index 7cc0a88..da8e3c6 100644 --- a/src/app-defined-loader/src/app-defined-loader.cc +++ b/src/app-defined-loader/src/app-defined-loader.cc @@ -42,36 +42,34 @@ namespace launchpad { -static const char PATH_CONF[] = "/usr/share/aul/app-defined-loader.conf"; -static const char SECTION_MEMORY[] = "Memory"; -static const char KEY_THRESHOLD[] = "Threshold"; -static uint32_t DEFAULT_THRESHOLD = 25600; // kB +namespace { +const char PATH_CONF[] = "/usr/share/aul/app-defined-loader.conf"; +const char SECTION_MEMORY[] = "Memory"; +const char KEY_THRESHOLD[] = "Threshold"; +const uint32_t DEFAULT_THRESHOLD = 25600; // kB +} // namespace class AppDefinedLoader { public: - AppDefinedLoader(int argc, char** argv) - : argc_(argc), argv_(argv) { - lifecycle_cb_ = std::shared_ptr( - new loader_lifecycle_callback_s()); + AppDefinedLoader(int argc, char** argv) : argc_(argc), argv_(argv) { + lifecycle_cb_ = std::make_shared(); lifecycle_cb_->create = OnCreate; lifecycle_cb_->launch = OnLaunch; lifecycle_cb_->terminate = OnTerminate; - adapter_ = std::shared_ptr(new loader_adapter_s()); + adapter_ = std::make_shared(); adapter_->loop_begin = OnLoopBegin; adapter_->loop_quit = OnLoopQuit; adapter_->add_fd = OnAddFd; adapter_->remove_fd = OnRemoveFd; - proc_ = std::unique_ptr(new Proc(getpid())); - + proc_ = std::make_unique(getpid()); Config conf(PATH_CONF); int threshold = conf.GetIntValue(SECTION_MEMORY, KEY_THRESHOLD); - if (threshold > 0) { + if (threshold > 0) threshold_ = static_cast(threshold); - } else { + else _W("Failed to get threshold"); - } } ~AppDefinedLoader() { @@ -192,7 +190,7 @@ class AppDefinedLoader { strerror_r(errno, err_str, sizeof(err_str))); } else { SECURE_LOGD("[candidate] Exec application (%s)", - argv_[LOADER_ARG_PATH]); + argv_[LOADER_ARG_PATH]); _close_all_fds(); if (!libdir.empty()) setenv("LD_LIBRARY_PATH", libdir.c_str(), 1); @@ -207,8 +205,7 @@ class AppDefinedLoader { } int DoDlOpen(bool restore, std::string old_cwd, std::string libdir) { - std::string hwc_message = "" + std::to_string(getpid()) + - "|lib loading start"; + std::string hwc_message = std::to_string(getpid()) + "|lib loading start"; prctl(PR_TASK_PERF_USER_TRACE, hwc_message.c_str(), hwc_message.size()); _W("dlopen(%s) ++", argv_[LOADER_ARG_PATH]); void* handle = dlopen(argv_[LOADER_ARG_PATH], @@ -220,13 +217,13 @@ class AppDefinedLoader { return -1; } - hwc_message = "" + std::to_string(getpid()) + "|lib loading end"; + hwc_message = std::to_string(getpid()) + "|lib loading end"; prctl(PR_TASK_PERF_USER_TRACE, hwc_message.c_str(), hwc_message.size()); if (restore && chdir(old_cwd.c_str())) _E("failed to chdir: %d", errno); - auto dl_main = reinterpret_cast( + auto dl_main = reinterpret_cast( dlsym(handle, "main")); if (dl_main == nullptr) { _E("dlsym not founded(%s). Please export 'main' function", dlerror()); diff --git a/src/app-defined-loader/src/config.hh b/src/app-defined-loader/src/config.hh index 3e12bdf..4188329 100644 --- a/src/app-defined-loader/src/config.hh +++ b/src/app-defined-loader/src/config.hh @@ -28,7 +28,6 @@ class Config { Config(const std::string& path); virtual ~Config(); - public: int GetIntValue(const std::string& section, const std::string& key) const; private: diff --git a/src/launchpad-parser/launchpad_parser_plugin.cc b/src/launchpad-parser/launchpad_parser_plugin.cc index 28f2b73..8ccee30 100644 --- a/src/launchpad-parser/launchpad_parser_plugin.cc +++ b/src/launchpad-parser/launchpad_parser_plugin.cc @@ -27,14 +27,13 @@ #define LOADERS_DIRECTORY_PATH "/opt/share/loaders/" -using namespace std; namespace launchpad_parser_plugin { -string LaunchpadParser::GetFilePath(string id) { +std::string LaunchpadParser::GetFilePath(std::string id) { return "/opt/share/loaders/" + id + ".loader"; } -int LaunchpadParser::WriteToFile(string pkgid) { +int LaunchpadParser::WriteToFile(std::string pkgid) { if (access(LOADERS_DIRECTORY_PATH, F_OK) != 0) mkdir(LOADERS_DIRECTORY_PATH, 0644); @@ -49,7 +48,7 @@ int LaunchpadParser::WriteToFile(string pkgid) { out_file << "APP_TYPE capp|c++app \n"; out_file << "DETECTION_METHOD TIMEOUT|VISIBILITY \n"; out_file << "TIMEOUT 5000 \n"; - out_file << "TTL " + to_string(i->GetTimeToLive()) + "\n"; + out_file << "TTL " + std::to_string(i->GetTimeToLive()) + "\n"; out_file << "OWNER " + pkgid + "\n"; out_file << "EXTRA loader_type common-loader \n"; if (i->GetPreloadLib().size() > 0) { @@ -63,18 +62,18 @@ int LaunchpadParser::WriteToFile(string pkgid) { return 0; } -bool LaunchpadParser::IsValidId(string loader_id, string pkgid) { +bool LaunchpadParser::IsValidId(std::string loader_id, std::string pkgid) { std::string needle("../"); - std::size_t found = loader_id.find(needle); + size_t found = loader_id.find(needle); if (found != std::string::npos) { _E("Invalid loader_id(%s)", loader_id.c_str()); return false; } - ifstream in_file(GetFilePath(loader_id).c_str()); + std::ifstream in_file(GetFilePath(loader_id).c_str()); if (!in_file.good()) return true; - string key, val; + std::string key, val; in_file >> key; while (in_file >> key >> val) { if (key == "OWNER") { @@ -86,7 +85,7 @@ bool LaunchpadParser::IsValidId(string loader_id, string pkgid) { return false; } -int LaunchpadParser::Install(xmlDocPtr doc, string pkgid) { +int LaunchpadParser::Install(xmlDocPtr doc, std::string pkgid) { pkgmgr_privilege_level level; pkgmgr_installer_info_get_privilege_level(&level); if (level != PM_PRIVILEGE_PLATFORM) { @@ -99,28 +98,32 @@ int LaunchpadParser::Install(xmlDocPtr doc, string pkgid) { if (!node->name) continue; - string name = string((char*)node->name); + std::string name = std::string(reinterpret_cast(node->name)); if (name != "provides-appdefined-loader") continue; - xmlChar* val = xmlGetProp(node, (const xmlChar *)"id"); - shared_ptr info = make_shared(string((char*)val)); + xmlChar* val = xmlGetProp(node, reinterpret_cast("id")); + std::shared_ptr info = + std::make_shared(std::string(reinterpret_cast(val))); if (!IsValidId(info->GetId(), pkgid)) return -1; - xmlChar* ttl = xmlGetProp(node, (const xmlChar *)"time-to-live"); + xmlChar* ttl = xmlGetProp(node, + reinterpret_cast("time-to-live")); if (ttl) - info->SetTimeToLive(stoi(string((char*)ttl))); + info->SetTimeToLive(std::stoi(std::string(reinterpret_cast(ttl)))); for (xmlNode* iter = node->children; iter; iter = iter->next) { if (!iter->name) continue; - string child_name = string((char*)iter->name); + std::string child_name = + std::string(reinterpret_cast(iter->name)); if (child_name == "preload-library") { - xmlChar* libname = xmlGetProp(iter, (const xmlChar *)"name"); + xmlChar* libname = xmlGetProp(iter, + reinterpret_cast("name")); if (!libname) continue; - info->AddPreloadLib(string((char*)libname)); + info->AddPreloadLib(std::string(reinterpret_cast(libname))); } } loader_list_.push_back(info); @@ -143,17 +146,17 @@ int LaunchpadParser::UnInstall(xmlDocPtr doc, std::string pkgid) { if (!node->name) continue; - string name = string((char*)node->name); + std::string name = std::string(reinterpret_cast(node->name)); if (name != "provides-appdefined-loader") continue; - xmlChar* val = xmlGetProp(node, (const xmlChar *)"id"); + xmlChar* val = xmlGetProp(node, reinterpret_cast("id")); if (!val) return -1; - string id = string((char*)val); + std::string id = std::string(reinterpret_cast(val)); if (!IsValidId(id, pkgid)) - return -1; + return -1; remove(GetFilePath(id).c_str()); } return 0; diff --git a/src/launchpad-parser/loader_info.cc b/src/launchpad-parser/loader_info.cc index 2f8ffcc..5a41e47 100644 --- a/src/launchpad-parser/loader_info.cc +++ b/src/launchpad-parser/loader_info.cc @@ -16,13 +16,12 @@ #include "launchpad-parser/loader_info.hh" -using namespace std; namespace launchpad_parser_plugin { -LoaderInfo::LoaderInfo(std::string id) : id_(id), time_to_live_(0) { +LoaderInfo::LoaderInfo(std::string id) : id_(std::move(id)), time_to_live_(0) { } -string LoaderInfo::GetId() { +std::string LoaderInfo::GetId() { return id_; } @@ -39,12 +38,12 @@ void LoaderInfo::SetTimeToLive(int time) { time_to_live_ = time; } -list LoaderInfo::GetPreloadLib() { +const std::list& LoaderInfo::GetPreloadLib() { return preload_lib_list_; } -void LoaderInfo::AddPreloadLib(string lib_name) { - preload_lib_list_.push_back(lib_name); +void LoaderInfo::AddPreloadLib(std::string lib_name) { + preload_lib_list_.push_back(std::move(lib_name)); } } // namspace launchpad_parser_plugin diff --git a/src/launchpad-parser/loader_info.hh b/src/launchpad-parser/loader_info.hh index f175591..d02af17 100644 --- a/src/launchpad-parser/loader_info.hh +++ b/src/launchpad-parser/loader_info.hh @@ -28,7 +28,7 @@ class LoaderInfo { std::string GetId(); int GetTimeToLive(); void SetTimeToLive(int time); - std::list GetPreloadLib(); + const std::list& GetPreloadLib(); void AddPreloadLib(std::string lib_name); private: -- 2.7.4 From 4d9decf6735a056735f33501754f2dcb22193ef5 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Mon, 5 Oct 2020 13:24:42 +0900 Subject: [PATCH 03/16] Release version 0.15.22 Changes: - Refactor coding style Change-Id: I62c50bc93d99a17c069415a1854e6037ededd516 Signed-off-by: Changgyu Choi --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 0545d95..edb1aa6 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.21 +Version: 0.15.22 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 023be6023f044393cd2db4f0578da5a40727553c Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 15 Oct 2020 08:00:21 +0900 Subject: [PATCH 04/16] Fix a bug about handling OOM When system is out of memory and the low memory status is true, launchpad-process-pool always tries to kill last running slot. Even if there is no running slot, launchpad-process-pool tries that. Because, the memory status is true. In that time, launchpad-process-pool is deadlock state. After this patch is applied, launchpad-process-pool tries to kill all running slots when system is OOM. If system is not OOM, launchpad-process-pool stops killing slots. Change-Id: I5ff858e20e948407252f603894ffb3edf7d64b12 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/src/launchpad.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/launchpad-process-pool/src/launchpad.c b/src/launchpad-process-pool/src/launchpad.c index c506541..d1585f1 100644 --- a/src/launchpad-process-pool/src/launchpad.c +++ b/src/launchpad-process-pool/src/launchpad.c @@ -530,7 +530,7 @@ static candidate_process_context_t *__get_running_slot(bool is_hydra) return NULL; } -static void __pause_last_running_slot(bool is_hydra) +static void __pause_all_running_slots(bool is_hydra) { candidate_process_context_t *cpc = NULL; GList *iter; @@ -538,16 +538,14 @@ static void __pause_last_running_slot(bool is_hydra) iter = g_list_last(candidate_slot_list); while (iter) { cpc = (candidate_process_context_t *)iter->data; - if (cpc->is_hydra == is_hydra && cpc->pid != CANDIDATE_NONE) - break; + if (cpc->is_hydra == is_hydra && cpc->pid != CANDIDATE_NONE) { + __update_slot_state(cpc, METHOD_OUT_OF_MEMORY, true); + if (!_memory_monitor_is_low_memory()) + return; + } iter = g_list_previous(iter); } - - if (!cpc) - return; - - __update_slot_state(cpc, METHOD_OUT_OF_MEMORY, true); } static void __resume_all_slots(void) @@ -3023,14 +3021,7 @@ static int __memory_monitor_cb(bool low_memory, void *user_data) candidate_slot_list = g_list_sort(candidate_slot_list, __compare_slot); - - do { - __pause_last_running_slot(false); - - cpc = __get_running_slot(false); - if (!cpc) - break; - } while (__is_low_memory()); + __pause_all_running_slots(false); } else { __resume_all_slots(); } -- 2.7.4 From faacaa784f8ff4444bfb37001809c64b2ca5e8c8 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Mon, 26 Oct 2020 09:54:27 +0900 Subject: [PATCH 05/16] Fix coding style Change-Id: I606f1009765cd0bd78afda1951f304855415043c Signed-off-by: Changgyu Choi --- src/launchpad-process-pool/src/launchpad_debug.c | 56 ++++++++++++------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/launchpad-process-pool/src/launchpad_debug.c b/src/launchpad-process-pool/src/launchpad_debug.c index 811e721..37934e0 100644 --- a/src/launchpad-process-pool/src/launchpad_debug.c +++ b/src/launchpad-process-pool/src/launchpad_debug.c @@ -32,11 +32,11 @@ #define DEBUGGER_INFO_PATH "/usr/share/aul" -static int debug_initialized; -static GList *debugger_info_list; -static debugger_info_h debugger_info; -static GList *debug_argv_list; -static GList *extra_argv_list; +static int __debug_initialized; +static GList *__debugger_info_list; +static debugger_info_h __debugger_info; +static GList *__debug_argv_list; +static GList *__extra_argv_list; int _debug_create_extra_argv(int *argc, char ***argv) { @@ -51,10 +51,10 @@ int _debug_create_extra_argv(int *argc, char ***argv) return -1; } - if (debugger_info == NULL) + if (__debugger_info == NULL) return 0; - new_argc = g_list_length(extra_argv_list); + new_argc = g_list_length(__extra_argv_list); if (new_argc == 0) return 0; @@ -65,7 +65,7 @@ int _debug_create_extra_argv(int *argc, char ***argv) } i = LOADER_ARG_PATH; - iter = g_list_first(extra_argv_list); + iter = g_list_first(__extra_argv_list); while (iter) { extra_argv = (const char *)iter->data; if (extra_argv) @@ -97,21 +97,21 @@ int _debug_create_argv(int *argc, char ***argv, bool *attach) return -1; } - if (debugger_info == NULL) + if (__debugger_info == NULL) return 0; - exe = _debugger_info_get_exe(debugger_info); + exe = _debugger_info_get_exe(__debugger_info); if (exe == NULL) return 0; - attach_str = _debugger_info_get_attach(debugger_info); + attach_str = _debugger_info_get_attach(__debugger_info); if (attach_str && strcasecmp(attach_str, "true") == 0) { *attach = true; new_argc++; } - list = _debugger_info_get_default_opt_list(debugger_info); - new_argc += g_list_length(debug_argv_list) + g_list_length(list) + 1; + list = _debugger_info_get_default_opt_list(__debugger_info); + new_argc += g_list_length(__debug_argv_list) + g_list_length(list) + 1; new_argv = (char **)calloc(new_argc, sizeof(char *)); if (new_argv == NULL) { _E("out of memory"); @@ -130,7 +130,7 @@ int _debug_create_argv(int *argc, char ***argv, bool *attach) iter = g_list_next(iter); } - iter = g_list_first(debug_argv_list); + iter = g_list_first(__debug_argv_list); while (iter) { debug_argv = (const char *)iter->data; if (debug_argv) @@ -259,7 +259,7 @@ static void __add_extra_argv(gpointer data, gpointer user_data) if (str_arr[i] == NULL) break; - extra_argv_list = g_list_append(extra_argv_list, + __extra_argv_list = g_list_append(__extra_argv_list, strdup(str_arr[i])); } @@ -294,7 +294,7 @@ static void __add_debug_argv(gpointer data, gpointer user_data) if (str_arr[i] == NULL) break; - debug_argv_list = g_list_append(debug_argv_list, + __debug_argv_list = g_list_append(__debug_argv_list, strdup(str_arr[i])); } @@ -375,41 +375,41 @@ void _debug_prepare_debugger(bundle *kb) _E("[DEBUG] Failed to redirect standard fds"); _D("[DEBUG] debugger: %s", debugger); - debugger_info = _debugger_info_find(debugger_info_list, debugger); - if (debugger_info == NULL) + __debugger_info = _debugger_info_find(__debugger_info_list, debugger); + if (__debugger_info == NULL) return; - list = _debugger_info_get_unlink_list(debugger_info); + list = _debugger_info_get_unlink_list(__debugger_info); g_list_foreach(list, __remove_file, NULL); - list = _debugger_info_get_extra_env_list(debugger_info); + list = _debugger_info_get_extra_env_list(__debugger_info); g_list_foreach(list, __set_debug_env, kb); - list = _debugger_info_get_extra_key_list(debugger_info); + list = _debugger_info_get_extra_key_list(__debugger_info); g_list_foreach(list, __add_debug_argv, kb); - list = _debugger_info_get_last_extra_key_list(debugger_info); + list = _debugger_info_get_last_extra_key_list(__debugger_info); g_list_foreach(list, __add_extra_argv, kb); } int _debug_init(void) { - if (debug_initialized) + if (__debug_initialized) return 0; - debugger_info_list = _debugger_info_load(DEBUGGER_INFO_PATH); - if (debugger_info_list == NULL) + __debugger_info_list = _debugger_info_load(DEBUGGER_INFO_PATH); + if (__debugger_info_list == NULL) return -1; - debug_initialized = 1; + __debug_initialized = 1; return 0; } void _debug_fini(void) { - if (!debug_initialized) + if (!__debug_initialized) return; - _debugger_info_unload(debugger_info_list); + _debugger_info_unload(__debugger_info_list); } -- 2.7.4 From e041e32628a945030d160ac58819efc05905c658 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 27 Oct 2020 10:28:27 +0900 Subject: [PATCH 06/16] Release version 0.15.23 Changes: - Fix a bug about handling OOM - Fix coding style Change-Id: I0ce4b8f4931ccf8ac06ff17a09f83d3c79831250 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 edb1aa6..cf557f7 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.22 +Version: 0.15.23 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 000c7dfb6138cd41b2d3207bb64813202bc31ad6 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 11 Nov 2020 16:24:29 +0900 Subject: [PATCH 07/16] Fix a bug about loader resumption When the system memory is available, all paused loaders should be prepared. Change-Id: I249b9a921fb25ed043e0086876afaf9922100d52 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/src/launchpad.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/launchpad-process-pool/src/launchpad.c b/src/launchpad-process-pool/src/launchpad.c index d1585f1..df329e7 100644 --- a/src/launchpad-process-pool/src/launchpad.c +++ b/src/launchpad-process-pool/src/launchpad.c @@ -556,7 +556,7 @@ static void __resume_all_slots(void) iter = candidate_slot_list; while (iter) { cpc = (candidate_process_context_t *)iter->data; - __update_slot_state(cpc, METHOD_AVAILABLE_MEMORY, false); + __update_slot_state(cpc, METHOD_AVAILABLE_MEMORY, true); iter = g_list_next(iter); } -- 2.7.4 From bf3d10ebc74915b7f2b0630d95569ba631457270 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 12 Nov 2020 11:47:52 +0900 Subject: [PATCH 08/16] Release version 0.15.24 Changes: - Fix a bug about loader resumption Change-Id: I8a0f7774832a0634af486669cbe52112db805cb7 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 cf557f7..c1c2592 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.23 +Version: 0.15.24 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 44ddd9d0a85d7314b9e23590e902f31b6254bcc9 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 25 Nov 2020 12:44:03 +0900 Subject: [PATCH 09/16] Support logger path setting Currently, the logger path is hard coded. After this patch is applied, the platform developer can change the logger path using the configuration file. Change-Id: Icd510c6bcdfee40e4ca1e15f938b202a92aac75e Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/conf/launchpad.conf.in | 3 ++ src/launchpad-process-pool/inc/launchpad_config.h | 1 + src/launchpad-process-pool/src/launchpad_config.c | 37 +++++++++++++++++++++++ src/launchpad-process-pool/src/launchpad_log.c | 9 ++++-- src/launchpad-process-pool/src/launchpad_logger.c | 14 ++++++--- 5 files changed, 58 insertions(+), 6 deletions(-) diff --git a/src/launchpad-process-pool/conf/launchpad.conf.in b/src/launchpad-process-pool/conf/launchpad.conf.in index 6e7e6b2..44acf40 100644 --- a/src/launchpad-process-pool/conf/launchpad.conf.in +++ b/src/launchpad-process-pool/conf/launchpad.conf.in @@ -10,3 +10,6 @@ Interval=5000 [CpuChecker] MaxCount=10 + +[Logger] +Path=/run/aul/log diff --git a/src/launchpad-process-pool/inc/launchpad_config.h b/src/launchpad-process-pool/inc/launchpad_config.h index 328f839..d38cae3 100644 --- a/src/launchpad-process-pool/inc/launchpad_config.h +++ b/src/launchpad-process-pool/inc/launchpad_config.h @@ -25,6 +25,7 @@ typedef enum { CONFIG_TYPE_MEMORY_MONITOR_THRESHOLD, CONFIG_TYPE_MEMORY_MONITOR_INTERVAL, CONFIG_TYPE_CPU_CHECKER_MAX_COUNT, + CONFIG_TYPE_LOGGER_PATH, } config_type_e; const char *_config_get_string_value(config_type_e type); diff --git a/src/launchpad-process-pool/src/launchpad_config.c b/src/launchpad-process-pool/src/launchpad_config.c index 0838dd7..f43bc1a 100644 --- a/src/launchpad-process-pool/src/launchpad_config.c +++ b/src/launchpad-process-pool/src/launchpad_config.c @@ -43,6 +43,9 @@ #define TAG_CPU_CHECKER "CpuChecker" #define KEY_CPU_CHECKER_MAX_COUNT "MaxCount" +#define TAG_LOGGER "Logger" +#define KEY_LOGGER_PATH "Path" + struct memory_status_s { char *low_key; int low_value; @@ -59,9 +62,14 @@ struct cpu_checker_s { int max_count; }; +struct logger_s { + char *path; +}; + static struct memory_status_s __memory_status; static struct memory_monitor_s __memory_monitor; static struct cpu_checker_s __cpu_checker; +static struct logger_s __logger; const char *_config_get_string_value(config_type_e type) { @@ -74,6 +82,9 @@ const char *_config_get_string_value(config_type_e type) case CONFIG_TYPE_MEMORY_STATUS_NORMAL_KEY: value = __memory_status.normal_key; break; + case CONFIG_TYPE_LOGGER_PATH: + value = __logger.path; + break; default: _E("Unknown type"); value = NULL; @@ -241,6 +252,29 @@ static void __cpu_checker_set(dictionary *d) _W("CPU Checker MaxCount(%d)", __cpu_checker.max_count); } +static void __logger_init(void) +{ + __logger.path = strdup("/var/log/appfw"); +} + +static void __logger_fini(void) +{ + free(__logger.path); +} + +static void __logger_set(dictionary *d) +{ + const char *str; + + str = __get_string_value(d, TAG_LOGGER, + KEY_LOGGER_PATH); + if (str) { + free(__logger.path); + __logger.path = strdup(str); + } + _W("Logger path(%s)", __logger.path); +} + int _config_init(void) { dictionary *d; @@ -251,6 +285,7 @@ int _config_init(void) __memory_status_init(); __memory_monitor_init(); __cpu_checker_init(); + __logger_init(); ret = access(PATH_LAUNCHPAD_CONF, F_OK); if (ret != 0) { @@ -267,6 +302,7 @@ int _config_init(void) __memory_status_set(d); __memory_monitor_set(d); __cpu_checker_set(d); + __logger_set(d); iniparser_freedict(d); @@ -277,6 +313,7 @@ void _config_fini(void) { _D("config fini"); + __logger_fini(); __cpu_checker_fini(); __memory_monitor_fini(); __memory_status_fini(); diff --git a/src/launchpad-process-pool/src/launchpad_log.c b/src/launchpad-process-pool/src/launchpad_log.c index a8d00a3..6c28d01 100644 --- a/src/launchpad-process-pool/src/launchpad_log.c +++ b/src/launchpad-process-pool/src/launchpad_log.c @@ -17,11 +17,14 @@ #define _GNU_SOURCE #include #include +#include +#include "launchpad_config.h" #include "launchpad_log.h" #include "launchpad_logger.h" #include "log_private.h" +#define LOG_FILE "launchpad.log" #define PATH_LAUNCHPAD_LOG "/var/log/appfw/launchpad/launchpad.log" static logger_h __logger; @@ -43,11 +46,13 @@ int _log_print(const char *tag, const char *format, ...) int _log_init(void) { + char path[PATH_MAX]; int ret; _W("LOG_INIT"); - - ret = _logger_create(PATH_LAUNCHPAD_LOG, &__logger); + snprintf(path, sizeof(path), "%s/launchpad/launchpad.log", + _config_get_string_value(CONFIG_TYPE_LOGGER_PATH)); + ret = _logger_create(path, &__logger); if (ret != 0) { _E("Failed to create log file. error(%d)", ret); return ret; diff --git a/src/launchpad-process-pool/src/launchpad_logger.c b/src/launchpad-process-pool/src/launchpad_logger.c index 0a32b7e..529b00c 100644 --- a/src/launchpad-process-pool/src/launchpad_logger.c +++ b/src/launchpad-process-pool/src/launchpad_logger.c @@ -27,7 +27,9 @@ #include #include #include +#include +#include "launchpad_config.h" #include "launchpad_logger.h" #include "log_private.h" @@ -78,21 +80,25 @@ static int __create_directory(const char *path) static int __create_launchpad_directories(void) { + const char *logger_path; + char path[PATH_MAX]; int ret; - ret = __create_directory(LAUNCHPAD_LOG_APPFW_PATH); + logger_path = _config_get_string_value(CONFIG_TYPE_LOGGER_PATH); + ret = __create_directory(logger_path); if (ret < 0) return ret; - ret = __set_smack_label(LAUNCHPAD_LOG_APPFW_PATH, "_"); + ret = __set_smack_label(logger_path, "User::Home"); if (ret < 0) return ret; - ret = __create_directory(LAUNCHPAD_LOG_PATH); + snprintf(path, sizeof(path), "%s/launchpad", logger_path); + ret = __create_directory(path); if (ret < 0) return ret; - ret = __set_smack_label(LAUNCHPAD_LOG_PATH, "User"); + ret = __set_smack_label(path, "User"); if (ret < 0) return ret; -- 2.7.4 From 920da45e28c3932cf98a01aa57b2110b9d60202a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 26 Nov 2020 13:53:12 +0900 Subject: [PATCH 10/16] Release version 0.15.25 Changes: - Support logger path setting Change-Id: I4ee727cb650dc9c93f46e928e0ba2dbd5fd22849 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 c1c2592..cc87eb0 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.24 +Version: 0.15.25 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 859d29b93678e910960b7d9309b12a1607b1199d Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 27 Nov 2020 07:36:24 +0900 Subject: [PATCH 11/16] Check executable file If an app_path is not executable, launchpad rejects the launch request. Change-Id: I2ae28b5c1852cb2d500d323fbbc2c4016f0f9720 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/src/launchpad.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/launchpad-process-pool/src/launchpad.c b/src/launchpad-process-pool/src/launchpad.c index df329e7..78399c9 100644 --- a/src/launchpad-process-pool/src/launchpad.c +++ b/src/launchpad-process-pool/src/launchpad.c @@ -753,7 +753,7 @@ static int __real_send(int clifd, int ret) return 0; } -static void __send_result_to_caller(int clifd, int ret, const char *app_path) +static void __send_result_to_caller(int clifd, int ret) { _W("send result: %d", ret); @@ -2204,21 +2204,38 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) menu_info = _appinfo_create(kb); if (menu_info == NULL) { _E("such pkg no found"); + __send_result_to_caller(clifd, -EINVAL); + clifd = -1; goto end; } app_path = _appinfo_get_app_path(menu_info); if (app_path == NULL) { _E("app_path is NULL"); + __send_result_to_caller(clifd, -EINVAL); + clifd = -1; goto end; } + if (app_path[0] != '/') { _E("app_path is not absolute path"); + __send_result_to_caller(clifd, -EINVAL); + clifd = -1; + goto end; + } + + if (access(app_path, X_OK) != 0) { + ret = -errno; + _E("%s is not executable. errno(%d)", app_path, errno); + __send_result_to_caller(clifd, ret); + clifd = -1; goto end; } if (menu_info->hwacc == NULL) { _E("[launchpad] Failed to find H/W acceleration type"); + __send_result_to_caller(clifd, -EINVAL); + clifd = -1; goto end; } @@ -2261,6 +2278,8 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) _modify_bundle(kb, cr.pid, menu_info, pkt->cmd); if (menu_info->appid == NULL) { _E("unable to get appid from menu_info"); + __send_result_to_caller(clifd, -EINVAL); + clifd = -1; goto end; } @@ -2287,7 +2306,7 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) } _memory_monitor_reset_timer(); - __send_result_to_caller(clifd, pid, app_path); + __send_result_to_caller(clifd, pid); clifd = -1; end: if (clifd != -1) -- 2.7.4 From a0b583fc7532778d623d239ec073f7f834df4187 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 27 Nov 2020 09:44:15 +0900 Subject: [PATCH 12/16] Release version 0.15.26 Changes: - Check executable file Change-Id: Ic205fdbd383441271532388fc2263cb0cb5a333b 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 cc87eb0..f498760 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.25 +Version: 0.15.26 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 706b9f5112c35fa3acf989b1756d7e6e868f11b9 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 11 Dec 2020 08:17:19 +0900 Subject: [PATCH 13/16] Check return value of vsnprintf() Change-Id: I6609f8bac28ec162e23867d01766a9857153e65b Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/src/launchpad_log.c | 7 ++++++- src/launchpad-process-pool/src/launchpad_logger.c | 7 ++++++- src/lib/common/src/launchpad_common.c | 19 ++++++++++++++----- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/launchpad-process-pool/src/launchpad_log.c b/src/launchpad-process-pool/src/launchpad_log.c index 6c28d01..fc5d698 100644 --- a/src/launchpad-process-pool/src/launchpad_log.c +++ b/src/launchpad-process-pool/src/launchpad_log.c @@ -33,13 +33,18 @@ int _log_print(const char *tag, const char *format, ...) { char formatted_buf[LAUNCHPAD_LOG_MAX_STRING_SIZE]; va_list ap; + int ret; if (!__logger) return 0; va_start(ap, format); - vsnprintf(formatted_buf, sizeof(formatted_buf), format, ap); + ret = vsnprintf(formatted_buf, sizeof(formatted_buf), format, ap); va_end(ap); + if (ret < 0 || ret >= sizeof(formatted_buf)) { + _E("vsnprintf() is failed. result(%d)", ret); + return -1; + } return _logger_print(__logger, tag, formatted_buf); } diff --git a/src/launchpad-process-pool/src/launchpad_logger.c b/src/launchpad-process-pool/src/launchpad_logger.c index 529b00c..3dd37a4 100644 --- a/src/launchpad-process-pool/src/launchpad_logger.c +++ b/src/launchpad-process-pool/src/launchpad_logger.c @@ -178,6 +178,7 @@ int _logger_print(logger_h handle, const char *tag, const char *format, ...) ssize_t ret; va_list ap; off_t offset; + int bytes; if (!handle || !tag || !format) { _E("Invalid parameter"); @@ -196,8 +197,12 @@ int _logger_print(logger_h handle, const char *tag, const char *format, ...) _E("lseek() is failed. errno(%d)", errno); va_start(ap, format); - vsnprintf(format_buf, sizeof(format_buf), format, ap); + bytes = vsnprintf(format_buf, sizeof(format_buf), format, ap); va_end(ap); + if (bytes < 0 || bytes >= sizeof(format_buf)) { + _E("vsnprintf() is failed. result(%d)", bytes); + return -1; + } snprintf(buf, sizeof(buf), "[%6d] %04d-%02d-%02d %02d:%02d:%02d %-16s %-100s\n", diff --git a/src/lib/common/src/launchpad_common.c b/src/lib/common/src/launchpad_common.c index 05d8bef..6e370ef 100644 --- a/src/lib/common/src/launchpad_common.c +++ b/src/lib/common/src/launchpad_common.c @@ -1441,16 +1441,20 @@ int _send_message_to_logger(const char *tag, const char *format, ...) int ret; int fd; + va_start(ap, format); + ret = vsnprintf(fmt, sizeof(fmt), format, ap); + va_end(ap); + if (ret < 0 || ret >= sizeof(fmt)) { + _E("vsnprintf() is failed. result(%d)", ret); + return -1; + } + snprintf(buf, sizeof(buf), "%s/daemons/%u/.launchpad-logger-sock", SOCKET_PATH, getuid()); fd = __create_client_socket(buf); if (fd < 0) return -1; - va_start(ap, format); - vsnprintf(fmt, sizeof(fmt), format, ap); - va_end(ap); - snprintf(buf, sizeof(buf), "%s: %s", tag, fmt); ret = __send_raw(fd, 0, (unsigned char *)buf, strlen(buf) + 1); if (ret < 0) { @@ -1467,10 +1471,15 @@ void _print_hwc_log(const char *format, ...) { char buf[1024]; va_list ap; + int ret; va_start(ap, format); - vsnprintf(buf, sizeof(buf), format, ap); + ret = vsnprintf(buf, sizeof(buf), format, ap); va_end(ap); + if (ret < 0 || ret >= sizeof(buf)) { + _E("vsnprintf() is failed. result(%d)", ret); + return; + } prctl(PR_TASK_PERF_USER_TRACE, buf, strlen(buf)); } -- 2.7.4 From d8ea456423b4927b7908c9a9a7a1f253a628b77a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 15 Dec 2020 16:47:47 +0900 Subject: [PATCH 14/16] Release version 0.15.27 Changes: - Check return value of vsnprintf() Change-Id: If70675a4c30020fca27db06e15f4669f4005a96e Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index f498760..5b4f91e 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.26 +Version: 0.15.27 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 6eef2204df3da2146624ad0856ed02b1edb29928 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 22 Dec 2020 12:49:58 +0900 Subject: [PATCH 15/16] Create port directory for component port Before starting launchpad-process-pool, the service file of systemd creates a user directory for component port API. Requires: - https://review.tizen.org/gerrit/#/c/platform/core/appfw/amd/+/250187/ Change-Id: I0b835b6b006e6126158909c5347a5009bdad070b Signed-off-by: Hwankyu Jhun --- packaging/launchpad-process-pool.service | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packaging/launchpad-process-pool.service b/packaging/launchpad-process-pool.service index ba2a747..c3a2ab0 100644 --- a/packaging/launchpad-process-pool.service +++ b/packaging/launchpad-process-pool.service @@ -17,5 +17,7 @@ ExecStartPre=-/usr/bin/mkdir -p /run/aul/dbspace/%U ExecStartPre=-/usr/bin/chmod 0701 /run/aul/dbspace/%U ExecStartPre=-/usr/bin/mkdir -p /run/aul/log/widget/%U ExecStartPre=-/usr/bin/chmod 0777 /run/aul/log/widget/%U +ExecStartPre=-/usr/bin/mkdir -p /run/aul/port/%U +ExecStartPre=-/usr/bin/chmod 0700 /run/aul/port/%U ExecStart=/bin/sh -l -c "/usr/bin/launchpad-process-pool" Sockets=launchpad-process-pool.socket -- 2.7.4 From a59f76b0eb4389b293f75fb45bb5d782d9e845b2 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 31 Dec 2020 09:41:14 +0900 Subject: [PATCH 16/16] Release version 0.16.0 Changes: - Create port directory for component port Change-Id: If65bd2768059a2c3800e453ad9c92729d2218310 Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 5b4f91e..7fc9bf9 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.15.27 +Version: 0.16.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4