From 643f4aea6eb710e2430b61b3f6e95228cd69a7f3 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 22 Jan 2020 15:02:40 +0900 Subject: [PATCH 01/16] Support launching service app with dynamic loader Change-Id: If385128a84a89e2e75d038ef5abe7ab6181c7402 Signed-off-by: Hwankyu Jhun --- src/launchpad.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/launchpad.c b/src/launchpad.c index b847c2c..ecd3f61 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -1890,7 +1890,15 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) if (menu_info->comp_type && strcmp(menu_info->comp_type, "svcapp") == 0) { - loader_id = PAD_LOADER_ID_DIRECT; + loader_id = __get_loader_id(kb); + if (loader_id > PAD_LOADER_ID_DYNAMIC_BASE) { + type = LAUNCHPAD_TYPE_DYNAMIC; + cpc = __find_slot(type, loader_id); + if (cpc && !cpc->prepared) + cpc = NULL; + } else { + loader_id = PAD_LOADER_ID_DIRECT; + } } else if (menu_info->comp_type && menu_info->app_type && strcmp(menu_info->comp_type, "widgetapp") == 0 && strcmp(menu_info->app_type, "webapp") == 0) { -- 2.7.4 From 1b870b7bc75c1f616d1058d2f9e06fab01b66cf5 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 31 Jan 2020 08:50:07 +0900 Subject: [PATCH 02/16] Release version 0.11.0 Changes: - Support launching service app with dynamic loader Change-Id: I568521232e4d1fcaf6797f67bd40f961bbdc4b79 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 b89d29a..76464ea 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.10.5 +Version: 0.11.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 0c3dace9197251b325a77a22dc0d9726b168dc0d Mon Sep 17 00:00:00 2001 From: hyunho Date: Mon, 3 Feb 2020 11:29:49 +0900 Subject: [PATCH 03/16] Add a plugin for app-defined loader Change-Id: I73f527421a98bc619266171553280acd9029c61d Signed-off-by: hyunho --- CMakeLists.txt | 3 + packaging/launchpad.spec | 4 + parser/CMakeLists.txt | 39 ++++++ parser/common.hh | 25 ++++ parser/launchpad_parser_plugin.cc | 146 +++++++++++++++++++++ parser/launchpad_parser_plugin.hh | 45 +++++++ parser/launchpad_parser_plugin_pkgmgr_interface.cc | 68 ++++++++++ parser/launchpad_plugins.txt | 1 + parser/loader_info.cc | 44 +++++++ parser/loader_info.hh | 43 ++++++ parser/log_private.hh | 47 +++++++ 11 files changed, 465 insertions(+) create mode 100644 parser/CMakeLists.txt create mode 100644 parser/common.hh create mode 100644 parser/launchpad_parser_plugin.cc create mode 100644 parser/launchpad_parser_plugin.hh create mode 100644 parser/launchpad_parser_plugin_pkgmgr_interface.cc create mode 100644 parser/launchpad_plugins.txt create mode 100644 parser/loader_info.cc create mode 100644 parser/loader_info.hh create mode 100644 parser/log_private.hh diff --git a/CMakeLists.txt b/CMakeLists.txt index 5239b49..20d8f0f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,3 +203,6 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/inc/launchpad_hydra.h DESTINATION incl 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 diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 76464ea..babb8b4 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -26,6 +26,7 @@ BuildRequires: pkgconfig(libcap) BuildRequires: pkgconfig(tanchor) BuildRequires: pkgconfig(dbus-1) BuildRequires: pkgconfig(iniparser) +BuildRequires: pkgconfig(libxml-2.0) Requires(post): /sbin/ldconfig Requires(post): /usr/bin/systemctl @@ -119,6 +120,7 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %install rm -rf %{buildroot} + %make_install mkdir -p %{buildroot}%{_unitdir_user}/basic.target.wants mkdir -p %{buildroot}%{_unitdir_user}/sockets.target.wants @@ -139,6 +141,8 @@ ln -sf ../launchpad-process-pool.service %{buildroot}%{_unitdir_user}/basic.targ %{_unitdir_user}/basic.target.wants/launchpad-process-pool.service %{_bindir}/launchpad-process-pool %{_prefix}/share/aul/launchpad.conf +%{_sysconfdir}/package-manager/parserlib/liblaunchpad-parser.so +%{_datadir}/parser-plugins/* %files devel %{_includedir}/launchpad/*.h diff --git a/parser/CMakeLists.txt b/parser/CMakeLists.txt new file mode 100644 index 0000000..f98579f --- /dev/null +++ b/parser/CMakeLists.txt @@ -0,0 +1,39 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(launchpad-parser CXX) + +INCLUDE(FindPkgConfig) +pkg_check_modules(PKGS REQUIRED + dlog + libxml-2.0 +) + +FOREACH(FLAGS ${PKGS_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${FLAGS}") +ENDFOREACH(FLAGS) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline -std=c++11") + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_CXX_FLAGS_RELEASE "-O2") + +ADD_LIBRARY(${PROJECT_NAME} SHARED + launchpad_parser_plugin.cc + loader_info.cc + launchpad_parser_plugin_pkgmgr_interface.cc +) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../) + +SET(PLUGINS_LIST_FILE_NAME launchpad_plugins.txt) +SET(PLUGINS_LIST_FILE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${PLUGINS_LIST_FILE_NAME}) + +SET(PLUGINS_LIST_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/share/parser-plugins) + +ADD_DEFINITIONS("-DPLUGINS_LIST_INSTALL_PATH=\"${PLUGINS_LIST_INSTALL_PATH}\"") + +INSTALL(FILES ${PLUGINS_LIST_FILE_PATH} DESTINATION ${PLUGINS_LIST_INSTALL_PATH}/) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PKGS_LDFLAGS}) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/parserlib) diff --git a/parser/common.hh b/parser/common.hh new file mode 100644 index 0000000..910caa5 --- /dev/null +++ b/parser/common.hh @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * 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_PARSER_PLUGIN_COMMON_HH_ +#define LAUNCHPAD_PARSER_PLUGIN_COMMON_HH_ + +#ifdef EXPORT_API +#undef EXPORT_API +#endif +#define EXPORT_API __attribute__((visibility("default"))) + +#endif // LAUNCHPAD_PARSER_PLUGIN_COMMON_HH_ diff --git a/parser/launchpad_parser_plugin.cc b/parser/launchpad_parser_plugin.cc new file mode 100644 index 0000000..a880a6e --- /dev/null +++ b/parser/launchpad_parser_plugin.cc @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#include +#include + +#include +#include + +#include "launchpad_parser_plugin.hh" +#include "log_private.hh" + +#define LOADERS_DIRECTORY_PATH "/opt/share/loaders/" + +using namespace std; +namespace launchpad_parser_plugin { + +string LaunchpadParser::GetFilePath(string id) { + return "/opt/share/loaders/" + id + ".loader"; +} + +int LaunchpadParser::WriteToFile(string pkgid) { + if (access(LOADERS_DIRECTORY_PATH, F_OK) != 0) + mkdir(LOADERS_DIRECTORY_PATH, 0644); + + LOGI("write to file (%d)", loader_list_.size()); + for (auto& i : loader_list_) { + std::ofstream out_file; + LOGI("write ID (%s)", i->GetId().c_str()); + out_file.open(GetFilePath(i->GetId())); + out_file << "[LOADER]\n"; + out_file << "NAME " + i->GetId() + "\n"; + out_file << "EXE /usr/bin/launchpad-loader \n"; + 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 << "OWNER " + pkgid + "\n"; + out_file << "EXTRA loader_type common-loader \n"; + if (i->GetPreloadLib().size() > 0) { + out_file << "EXTRA_ARRAY preload \n"; + for (auto& lib : i->GetPreloadLib()) { + out_file << "EXTRA_ARRAY_VAL /usr/lib/" + lib + "\n"; + } + } + out_file.close(); + } + return 0; +} + +bool LaunchpadParser::IsValidId(string loader_id, string pkgid) { + ifstream in_file(GetFilePath(loader_id).c_str()); + if (!in_file.good()) + return true; + string key, val; + in_file >> key; + while (in_file >> key >> val) { + if (key == "OWNER") { + LOGI("key (%s), val (%s)", key.c_str(), val.c_str()); + if (val == pkgid) + return true; + } + } + return false; +} + +int LaunchpadParser::Install(xmlDocPtr doc, string pkgid) { + xmlNode* root = xmlDocGetRootElement(doc); + for (xmlNode* node = root->children; node; node = node->next) { + if (!node->name) + continue; + + string name = string((char*)node->name); + if (name != "provides-appdefined-loader") + continue; + + xmlChar* val = xmlGetProp(node, (const xmlChar *)"id"); + shared_ptr info = make_shared(string((char*)val)); + if (!IsValidId(info->GetId(), pkgid)) + return -1; + + xmlChar* ttl = xmlGetProp(node, (const xmlChar *)"time-to-live"); + if (ttl) + info->SetTimeToLive(stoi(string((char*)ttl))); + + for (xmlNode* iter = node->children; iter; iter = iter->next) { + if (!iter->name) + continue; + string child_name = string((char*)iter->name); + if (child_name == "preload-library") { + xmlChar* libname = xmlGetProp(iter, (const xmlChar *)"name"); + if (!libname) + continue; + info->AddPreloadLib(string((char*)libname)); + } + } + loader_list_.push_back(info); + } + WriteToFile(pkgid); + + return 0; +} + +int LaunchpadParser::Upgrade(xmlDocPtr doc, std::string pkgid) { + if (UnInstall(doc, pkgid) != 0) + return -1; + + return Install(doc, pkgid); +} + +int LaunchpadParser::UnInstall(xmlDocPtr doc, std::string pkgid) { + xmlNode* root = xmlDocGetRootElement(doc); + for (xmlNode* node = root->children; node; node = node->next) { + if (!node->name) + continue; + + string name = string((char*)node->name); + if (name != "provides-appdefined-loader") + continue; + + xmlChar* val = xmlGetProp(node, (const xmlChar *)"id"); + if (!val) + return -1; + + string id = string((char*)val); + if (!IsValidId(id, pkgid)) + return -1; + remove(GetFilePath(id).c_str()); + } + return 0; +} + +} // namspace launchpad_parser_plugin diff --git a/parser/launchpad_parser_plugin.hh b/parser/launchpad_parser_plugin.hh new file mode 100644 index 0000000..091e50c --- /dev/null +++ b/parser/launchpad_parser_plugin.hh @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * 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_PARSER_PLUGIN_LAUNCHPAD_PARSER_PLUGIN_HH_ +#define LAUNCHPAD_PARSER_PLUGIN_LAUNCHPAD_PARSER_PLUGIN_HH_ + +#include +#include +#include +#include + +#include "loader_info.hh" + +namespace launchpad_parser_plugin { + +class LaunchpadParser { + public: + std::string GetFilePath(std::string id); + int WriteToFile(std::string pkgid); + int Install(xmlDocPtr doc, std::string pkgid); + int Upgrade(xmlDocPtr doc, std::string pkgid); + int UnInstall(xmlDocPtr doc, std::string pkgid); + bool IsValidId(std::string loader_id, std::string pkgid); + + private: + std::list> loader_list_; +}; + +} // namespace launchpad_parser_plugin + +#endif // LAUNCHPAD_PARSER_PLUGIN_LAUNCHPAD_PARSER_PLUGIN_HH_ + diff --git a/parser/launchpad_parser_plugin_pkgmgr_interface.cc b/parser/launchpad_parser_plugin_pkgmgr_interface.cc new file mode 100644 index 0000000..34d16ba --- /dev/null +++ b/parser/launchpad_parser_plugin_pkgmgr_interface.cc @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2019 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. + */ + +#include + +#include "launchpad_parser_plugin.hh" +#include "log_private.hh" +#include "common.hh" + +using namespace launchpad_parser_plugin; + +extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc, const char *package) +{ + LaunchpadParser parser; + LOGI("install"); + return parser.Install(doc, package); +} + +extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr doc, const char *package) +{ + LOGI("uninstall"); + LaunchpadParser parser; + return parser.UnInstall(doc, package); +} + +extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc, const char *package) +{ + LOGI("upgrade"); + LaunchpadParser parser; + return parser.Upgrade(doc, package); +} + +extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_RECOVERINSTALL(xmlDocPtr doc, + const char *package) +{ + LOGW("recover install"); + LaunchpadParser parser; + return parser.UnInstall(doc, package); +} + +extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_RECOVERUNINSTALL(xmlDocPtr doc, + const char *package) +{ + LOGW("recover uninstall"); + LaunchpadParser parser; + return parser.UnInstall(doc, package); +} + +extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_RECOVERUPGRADE(xmlDocPtr doc, + const char *package) +{ + LOGW("recover upgrade"); + LaunchpadParser parser; + return parser.Upgrade(doc, package); +} diff --git a/parser/launchpad_plugins.txt b/parser/launchpad_plugins.txt new file mode 100644 index 0000000..75a63d0 --- /dev/null +++ b/parser/launchpad_plugins.txt @@ -0,0 +1 @@ +type="tag";name="provides-appdefined-loader";path="/etc/package-manager/parserlib/liblaunchpad-parser.so";vitalness="true" diff --git a/parser/loader_info.cc b/parser/loader_info.cc new file mode 100644 index 0000000..1f6a2f5 --- /dev/null +++ b/parser/loader_info.cc @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * 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. + */ +#include "loader_info.hh" + +using namespace std; +namespace launchpad_parser_plugin { + +LoaderInfo::LoaderInfo(std::string id) : id_(id), time_to_live_(0) { +} + +string LoaderInfo::GetId() { + return id_; +} + +int LoaderInfo::GetTimeToLive() { + return time_to_live_; +} + +void LoaderInfo::SetTimeToLive(int time) { + time_to_live_ = time; +} + +list LoaderInfo::GetPreloadLib() { + return preload_lib_list_; +} + +void LoaderInfo::AddPreloadLib(string lib_name) { + preload_lib_list_.push_back(lib_name); +} + +} // namspace launchpad_parser_plugin diff --git a/parser/loader_info.hh b/parser/loader_info.hh new file mode 100644 index 0000000..c4ab4f3 --- /dev/null +++ b/parser/loader_info.hh @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * 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_PARSER_PLUGIN_LOADER_INFO_HH_ +#define LAUNCHPAD_PARSER_PLUGIN_LOADER_INFO_HH_ + +#include +#include + +namespace launchpad_parser_plugin { + +class LoaderInfo { + public: + LoaderInfo(std::string id); + std::string GetId(); + int GetTimeToLive(); + void SetTimeToLive(int time); + std::list GetPreloadLib(); + void AddPreloadLib(std::string lib_name); + + private: + std::string id_; + int time_to_live_; + std::list preload_lib_list_; +}; + +} // namespace launchpad_parser_plugin + +#endif // LAUNCHPAD_PARSER_PLUGIN_LOADER_INFO_HH_ + diff --git a/parser/log_private.hh b/parser/log_private.hh new file mode 100644 index 0000000..80e244b --- /dev/null +++ b/parser/log_private.hh @@ -0,0 +1,47 @@ +/* + * 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_PARSER_PLUGIN_LOG_PRIVATE_HH_ +#define LAUNCHPAD_PARSER_PLUGIN_LOG_PRIVATE_HH_ + +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "LAUNCHPAD_PARSER_PLUGIN" + +#ifdef _E +#undef _E +#endif +#define _E(fmt, arg...) LOGE(fmt, ##arg) + +#ifdef _D +#undef _D +#endif +#define _D(fmt, arg...) LOGD(fmt, ##arg) + +#ifdef _W +#undef _W +#endif +#define _W(fmt, arg...) LOGW(fmt, ##arg) + +#ifdef _I +#undef _I +#endif +#define _I(fmt, arg...) LOGI(fmt, ##arg) + +#endif /* LAUNCHPAD_PARSER_PLUGIN_LOG_PRIVATE_HH_ */ -- 2.7.4 From f345f214eb2a04895dd91479e89c69a440ca7592 Mon Sep 17 00:00:00 2001 From: Jusung Son Date: Fri, 7 Feb 2020 09:10:57 +0900 Subject: [PATCH 04/16] Add app-defined loader Requires: - https://review.tizen.org/gerrit/#/c/platform/core/appfw/aul-1/+/224466/ - https://review.tizen.org/gerrit/#/c/platform/core/appfw/amd/+/224634/ - https://review.tizen.org/gerrit/#/c/platform/core/api/app-control/+/224798/ - https://review.tizen.org/gerrit/#/c/platform/core/appfw/launchpad/+/224161/ Change-Id: I66ea0abec98fd387e91cf67a7f5db94e5d0234d0 Signed-off-by: Jusung Son --- CMakeLists.txt | 1 + inc/launchpad_common.h | 1 + inc/launchpad_inotify.h | 34 +++++++++ inc/loader_info.h | 6 +- inc/preexec.h | 0 src/launchpad.c | 152 +++++++++++++++++++++++++++++++++++++- src/launchpad_inotify.c | 191 ++++++++++++++++++++++++++++++++++++++++++++++++ src/loader_info.c | 55 +++++++++++++- 8 files changed, 437 insertions(+), 3 deletions(-) mode change 100755 => 100644 CMakeLists.txt create mode 100644 inc/launchpad_inotify.h mode change 100755 => 100644 inc/preexec.h mode change 100755 => 100644 src/launchpad.c create mode 100644 src/launchpad_inotify.c diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 index 20d8f0f..6197582 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,6 +147,7 @@ SET(${LAUNCHPAD_PROCESS_POOL}_SOURCE_FILES 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}) diff --git a/inc/launchpad_common.h b/inc/launchpad_common.h index c5859e2..dc60559 100644 --- a/inc/launchpad_common.h +++ b/inc/launchpad_common.h @@ -46,6 +46,7 @@ #define PAD_CMD_DEMAND 14 #define PAD_CMD_PING 15 #define PAD_CMD_UPDATE_APP_TYPE 16 +#define PAD_CMD_PREPARE_APP_DEFINED_LOADER 17 #define LAUNCHPAD_LAUNCH_SIGNAL 83 #define LAUNCHPAD_DEAD_SIGNAL 61 diff --git a/inc/launchpad_inotify.h b/inc/launchpad_inotify.h new file mode 100644 index 0000000..4db903e --- /dev/null +++ b/inc/launchpad_inotify.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. + */ + +#pragma once + +#include +#include + +typedef struct inotify_watch_info_s *inotify_watch_info_h; + +typedef bool (*inotify_watch_cb)(const char *event_name, uint32_t mask, + void *data); + +int _inotify_add_watch(const char *path, uint32_t mask, + inotify_watch_cb callback, void *data); + +void _inotify_rm_watch(inotify_watch_info_h handle); + +int _inotify_init(void); + +void _inotify_fini(void); diff --git a/inc/loader_info.h b/inc/loader_info.h index 8714198..2e703b5 100644 --- a/inc/loader_info.h +++ b/inc/loader_info.h @@ -57,10 +57,14 @@ typedef struct _loader_info { typedef void (*loader_info_foreach_cb)(loader_info_t *info, void *data); -GList *_loader_info_load(const char *path); +GList *_loader_info_load_dir(const char *path); +GList *_loader_info_load_file(GList *list, const char *path); +GList *_loader_info_unload(GList *list, const char *loader_name); 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); +const char* _loader_info_find_loader_path_by_loader_name(GList *info, const char *loader_name); +const loader_info_t* _loader_info_find_loader_by_loader_name(GList *info, const char *loader_name); int *_loader_get_alternative_types(GList *info, int type, int *len); int _loader_info_foreach(GList *info, loader_info_foreach_cb callback, void *data); diff --git a/inc/preexec.h b/inc/preexec.h old mode 100755 new mode 100644 diff --git a/src/launchpad.c b/src/launchpad.c old mode 100755 new mode 100644 index ecd3f61..af409f5 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -49,6 +49,7 @@ #include "launchpad_types.h" #include "loader_info.h" #include "perf.h" +#include "launchpad_inotify.h" #define AUL_PR_NAME 16 #define EXEC_CANDIDATE_EXPIRED 5 @@ -60,6 +61,11 @@ #define LAUNCHPAD_LOGGER_SOCK ".launchpad-logger-sock" #define LOADER_PATH_DEFAULT "/usr/bin/launchpad-loader" #define LOADER_INFO_PATH "/usr/share/aul" +#define OPT_SHARE_PATH "/opt/share" +#define LOADERS_PATH "loaders" +#define APP_DEFINED_LOADER_INFO_PATH OPT_SHARE_PATH "/" LOADERS_PATH +#define COMMON_LOADER_NAME "common-loader1" + #define LAUNCHER_INFO_PATH LOADER_INFO_PATH #define REGULAR_UID_MIN 5000 #define PAD_ERR_FAILED -1 @@ -142,6 +148,7 @@ struct app_info { static int __sys_hwacc; static GList *loader_info_list; +static GList *app_defined_loader_info_list; static int user_slot_offset; static GList *candidate_slot_list; static app_labels_monitor *label_monitor; @@ -171,6 +178,7 @@ static int __add_idle_checker(int detection_method, GList *cur); static void __dispose_candidate_process(candidate_process_context_t *cpc); static bool __is_low_memory(void); static void __update_slot_state(candidate_process_context_t *cpc, int method); +static void __init_app_defined_loader_monitor(void); static gboolean __handle_queuing_slots(gpointer data) { @@ -1588,6 +1596,60 @@ static int __dispatch_cmd_add_loader(bundle *kb) return -1; } +static int __dispatch_cmd_add_app_defined_loader(bundle *kb) +{ + const char *loader_name; + const char *loader_path; + int lid, len; + candidate_process_context_t *cpc; + const loader_info_t *info; + bundle_raw *extra; + + _W("cmd add defined loader"); + loader_name = bundle_get_val(kb, AUL_K_LOADER_NAME); + + if (loader_name == NULL) { + _E("loader_name is NULL"); + return -1; + } + + loader_path = _loader_info_find_loader_path_by_loader_name( + loader_info_list, COMMON_LOADER_NAME); + info = _loader_info_find_loader_by_loader_name( + app_defined_loader_info_list, loader_name); + + if (loader_path == NULL || info == NULL || info->extra == NULL) { + _E("loader_name %s, loader_path %d, info %d", + loader_name, loader_path != NULL, info != NULL); + return -1; + } + + bundle_encode(info->extra, &extra, &len); + + lid = __make_loader_id(); + cpc = __add_slot(LAUNCHPAD_TYPE_DYNAMIC, lid, 0, + loader_path, (const char *)extra, + METHOD_TIMEOUT | METHOD_VISIBILITY, + METHOD_REQUEST | METHOD_AVAILABLE_MEMORY, + METHOD_TTL | METHOD_OUT_OF_MEMORY, + info->ttl, + 2000, + DEFAULT_CPU_THRESHOLD_MAX, + DEFAULT_CPU_THRESHOLD_MIN, + false, + true, 0); + + if (cpc == NULL) { + _E("cpc is NULL"); + bundle_free_encoded_rawdata(&extra); + return -1; + } + + __prepare_candidate_process(LAUNCHPAD_TYPE_DYNAMIC, lid); + + return lid; +} + static int __dispatch_cmd_remove_loader(bundle *kb) { const char *id = bundle_get_val(kb, AUL_K_LOADER_ID); @@ -1841,6 +1903,11 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) __real_send(clifd, ret); clifd = -1; goto end; + case PAD_CMD_PREPARE_APP_DEFINED_LOADER: + ret = __dispatch_cmd_add_app_defined_loader(kb); + __real_send(clifd, ret); + clifd = -1; + goto end; case PAD_CMD_DEMAND: ret = __dispatch_cmd_hint(kb, METHOD_DEMAND); __real_send(clifd, ret); @@ -2191,6 +2258,77 @@ static int __init_sigchild_fd(void) return 0; } +static bool __on_directory_create(const char *event_name, uint32_t mask, + void *user_data) +{ + if (!event_name) { + _E("Invalid parameter"); + return true; + } + + if (!strcmp(event_name, LOADERS_PATH)) { + __init_app_defined_loader_monitor(); + return false; + } + + return true; +} + +static bool __on_file_change(const char *event_name, uint32_t mask, + void *user_data) +{ + char buf[PATH_MAX]; + char *ext; + if (!event_name) { + _E("Invalid parameter"); + return true; + } + + ext = strrchr(event_name, '.'); + if (ext == NULL || strcmp(ext, ".loader") != 0) + return true; + + if (mask & IN_CREATE) { + snprintf(buf, sizeof(buf), "%s/%s", + APP_DEFINED_LOADER_INFO_PATH, event_name); + app_defined_loader_info_list = _loader_info_load_file( + app_defined_loader_info_list, buf); + } else if (mask & IN_DELETE) { + snprintf(buf, ext - event_name, "%s", event_name); + app_defined_loader_info_list = _loader_info_unload( + app_defined_loader_info_list, buf); + } + + return true; +} + +static void __init_app_defined_loader_monitor(void) +{ + int ret; + + ret = access(APP_DEFINED_LOADER_INFO_PATH, F_OK); + if (ret < 0) { + _W("Failed to access %s", APP_DEFINED_LOADER_INFO_PATH); + ret = _inotify_add_watch(OPT_SHARE_PATH, + IN_CREATE, __on_directory_create, NULL); + if (ret != 0) + _E("Failed to add inotify watch %s", OPT_SHARE_PATH); + + return; + } + + ret = _inotify_add_watch(APP_DEFINED_LOADER_INFO_PATH, + IN_CREATE | IN_DELETE, __on_file_change, NULL); + + if (ret < 0) { + _E("Failed to add inotify watch %s", + APP_DEFINED_LOADER_INFO_PATH); + } + + return; + +} + static int __init_label_monitor_fd(void) { int r; @@ -2331,7 +2469,7 @@ static int __add_default_slots(void) if (loader_info_list) _loader_info_dispose(loader_info_list); - loader_info_list = _loader_info_load(LOADER_INFO_PATH); + loader_info_list = _loader_info_load_dir(LOADER_INFO_PATH); if (loader_info_list == NULL) return -1; @@ -2342,6 +2480,11 @@ static int __add_default_slots(void) return 0; } +static void __add_app_defined_loaders(void) +{ + app_defined_loader_info_list = _loader_info_load_dir(APP_DEFINED_LOADER_INFO_PATH); +} + static bool __is_low_memory(void) { if (__memory_status_low >= MEMORY_STATUS_LOW) @@ -2562,9 +2705,13 @@ static int __before_loop(int argc, char **argv) if (ret != 0) _W("Failed to initialize config"); + _inotify_init(); + __add_default_slots(); launcher_info_list = _launcher_info_load(LAUNCHER_INFO_PATH); + __add_app_defined_loaders(); + ret = _send_cmd_to_amd(LAUNCHPAD_LAUNCH_SIGNAL); if (ret < 0) _W("Failed to send cmd(%d) to amd", LAUNCHPAD_LAUNCH_SIGNAL); @@ -2577,6 +2724,7 @@ static int __before_loop(int argc, char **argv) } __register_vconf_events(); + __init_app_defined_loader_monitor(); return 0; } @@ -2593,6 +2741,8 @@ static void __after_loop(void) _debug_fini(); _launcher_info_unload(launcher_info_list); _config_fini(); + _inotify_fini(); + _loader_info_dispose(app_defined_loader_info_list); if (__label_monitor_channel) _io_channel_destroy(__label_monitor_channel); diff --git a/src/launchpad_inotify.c b/src/launchpad_inotify.c new file mode 100644 index 0000000..9130fa2 --- /dev/null +++ b/src/launchpad_inotify.c @@ -0,0 +1,191 @@ +/* + * 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 "launchpad_inotify.h" +#include "log_private.h" + +struct inotify_watch_info_s { + int fd; + int wd; + GIOChannel *io; + guint tag; + uint32_t mask; + inotify_watch_cb cb; + void *data; +}; + +static GList *__watch_list; + +static gboolean __inotify_cb(GIOChannel *source, GIOCondition condition, + gpointer data) +{ +#define ALIGN_INOTIFY_EVENT \ + __attribute__ ((aligned(__alignof__(struct inotify_event)))) +#define SIZE_INOTIFY_EVENT (sizeof(struct inotify_event)) + int fd = g_io_channel_unix_get_fd(source); + char buf[4096] ALIGN_INOTIFY_EVENT; + const struct inotify_event *event; + struct inotify_watch_info_s *info = data; + ssize_t len; + char *ptr; + char *nptr; + + while ((len = read(fd, buf, sizeof(buf))) > 0) { + for (ptr = buf; ptr < buf + len; + ptr += sizeof(struct inotify_event) + event->len) { + if ((ptr + SIZE_INOTIFY_EVENT) > (buf + len)) + break; + + event = (const struct inotify_event *)ptr; + nptr = ptr + sizeof(struct inotify_event) + event->len; + if (nptr > buf + len) + break; + + if (event->mask & info->mask) { + if (!info->cb(event->name, event->mask, + info->data)) { + _inotify_rm_watch(info); + return G_SOURCE_CONTINUE; + } + } + } + } + + return G_SOURCE_CONTINUE; +} + +static void __destroy_inotify_watch_info(gpointer data) +{ + struct inotify_watch_info_s *info = (struct inotify_watch_info_s *)data; + + if (info == NULL) + return; + + if (info->tag > 0) + g_source_remove(info->tag); + + if (info->io) + g_io_channel_unref(info->io); + + if (info->wd > 0) + inotify_rm_watch(info->fd, info->wd); + + if (info->fd > 0) + close(info->fd); + + free(info); +} + +static struct inotify_watch_info_s *__create_inotify_watch_info( + const char *path, uint32_t mask, inotify_watch_cb cb, + void *data) +{ + GIOCondition cond = G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP; + struct inotify_watch_info_s *info; + + info = calloc(1, sizeof(struct inotify_watch_info_s)); + if (info == NULL) { + _E("Out of memory"); + return NULL; + } + + info->fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); + if (info->fd < 0) { + _E("inotify_init1() is failed. errno(%d)", errno); + __destroy_inotify_watch_info(info); + return NULL; + } + + info->wd = inotify_add_watch(info->fd, path, mask); + if (info->wd < 0) { + _E("inotify_add_watch() is failed. path(%s), errno(%d)", + path, errno); + __destroy_inotify_watch_info(info); + return NULL; + } + + info->io = g_io_channel_unix_new(info->fd); + if (!info->io) { + _E("g_io_channel_unix_new() is failed"); + __destroy_inotify_watch_info(info); + return NULL; + } + + info->tag = g_io_add_watch(info->io, cond, + __inotify_cb, info); + if (!info->tag) { + _E("g_io_add_watch() is failed"); + __destroy_inotify_watch_info(info); + return NULL; + } + + info->mask = mask; + info->cb = cb; + info->data = data; + + return info; +} + +int _inotify_add_watch(const char *path, uint32_t mask, + inotify_watch_cb callback, void *data) +{ + struct inotify_watch_info_s *info; + + if (path == NULL || callback == NULL) { + _E("Invalid parameter"); + return -1; + } + + info = __create_inotify_watch_info(path, mask, callback, data); + if (info == NULL) + return -1; + + __watch_list = g_list_append(__watch_list, info); + + return 0; +} + +void _inotify_rm_watch(inotify_watch_info_h handle) +{ + if (handle == NULL) + return; + + __watch_list = g_list_remove(__watch_list, handle); + __destroy_inotify_watch_info(handle); +} + +int _inotify_init(void) +{ + _D("inotify init"); + + return 0; +} + +void _inotify_fini(void) +{ + _D("inotify fini"); + + if (__watch_list) + g_list_free_full(__watch_list, __destroy_inotify_watch_info); +} diff --git a/src/loader_info.c b/src/loader_info.c index 39e9f21..375c1fd 100644 --- a/src/loader_info.c +++ b/src/loader_info.c @@ -53,6 +53,9 @@ #define VAL_METHOD_TTL "TTL" #define VAL_METHOD_OUT_OF_MEMORY "OUT_OF_MEMORY" +static int __comp_name(gconstpointer a, gconstpointer b); +static void __free_info(gpointer data); + static loader_info_t *__create_loader_info() { loader_info_t *info; @@ -320,7 +323,7 @@ static GList *__parse_file(GList *list, const char *path) return list; } -GList *_loader_info_load(const char *path) +GList *_loader_info_load_dir(const char *path) { DIR *dir_info; struct dirent *entry = NULL; @@ -346,6 +349,56 @@ GList *_loader_info_load(const char *path) return list; } +GList *_loader_info_load_file(GList *list, const char *path) +{ + return __parse_file(list, path); +} + +GList *_loader_info_unload(GList *list, const char *loader_name) +{ + GList *cur; + loader_info_t *info; + + cur = g_list_find_custom(list, loader_name, __comp_name); + if (cur == NULL) + return list; + + info = cur->data; + + list = g_list_remove(list, info); + __free_info(info); + + return list; +} + +const char* _loader_info_find_loader_path_by_loader_name(GList *list, const char *loader_name) +{ + GList *cur; + loader_info_t *info; + + cur = g_list_find_custom(list, loader_name, __comp_name); + if (cur == NULL) + return NULL; + + info = cur->data; + + return info->exe; +} + +const loader_info_t* _loader_info_find_loader_by_loader_name(GList *list, const char *loader_name) +{ + GList *cur; + loader_info_t *info; + + cur = g_list_find_custom(list, loader_name, __comp_name); + if (cur == NULL) + return NULL; + + info = cur->data; + + return info; +} + static void __free_info(gpointer data) { loader_info_t *info; -- 2.7.4 From 69414338722e64a6df6fe8ab4edc4c86a56bde85 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 18 Feb 2020 10:47:14 +0900 Subject: [PATCH 05/16] Fix return values of __dispatch_cmd_add_app_defined_loader() Change-Id: Ia7504d0a4b4078cc932af2094dddc174d82df123 Signed-off-by: Hwankyu Jhun --- src/launchpad.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/launchpad.c b/src/launchpad.c index af409f5..b1a3ef1 100644 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -15,6 +15,7 @@ */ #define _GNU_SOURCE +#include #include #include #include @@ -1610,18 +1611,19 @@ static int __dispatch_cmd_add_app_defined_loader(bundle *kb) if (loader_name == NULL) { _E("loader_name is NULL"); - return -1; + return -EINVAL; } + /* TODO: use app-defined-loader */ loader_path = _loader_info_find_loader_path_by_loader_name( loader_info_list, COMMON_LOADER_NAME); - info = _loader_info_find_loader_by_loader_name( - app_defined_loader_info_list, loader_name); + info = _loader_info_find_loader_by_loader_name( + app_defined_loader_info_list, loader_name); if (loader_path == NULL || info == NULL || info->extra == NULL) { _E("loader_name %s, loader_path %d, info %d", loader_name, loader_path != NULL, info != NULL); - return -1; + return -EINVAL; } bundle_encode(info->extra, &extra, &len); @@ -1638,11 +1640,10 @@ static int __dispatch_cmd_add_app_defined_loader(bundle *kb) DEFAULT_CPU_THRESHOLD_MIN, false, true, 0); - if (cpc == NULL) { _E("cpc is NULL"); bundle_free_encoded_rawdata(&extra); - return -1; + return -ENOMEM; } __prepare_candidate_process(LAUNCHPAD_TYPE_DYNAMIC, lid); -- 2.7.4 From 878706d59193174a36be0085aa7205877790327a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 18 Feb 2020 17:22:08 +0900 Subject: [PATCH 06/16] Separate codes into directories Change-Id: I497213884beecebe3d532f4d4ece55dbcf5fd329 Signed-off-by: Hwankyu Jhun --- CMakeLists.txt | 197 +------------------ .../launchpad-loader.manifest | 0 launchpad.manifest => packaging/launchpad.manifest | 0 packaging/launchpad.spec | 7 +- .../liblaunchpad.manifest | 0 src/CMakeLists.txt | 9 + {inc => src/common/inc}/key.h | 0 {inc => src/common/inc}/launchpad_common.h | 0 {inc => src/common/inc}/launchpad_types.h | 7 + src/{ => common/inc}/log_private.h | 0 {inc => src/common/inc}/perf.h | 0 {inc => src/common/inc}/preexec.h | 0 src/{ => common/src}/launchpad_common.c | 0 src/hydra/CMakeLists.txt | 41 ++++ {inc => src/hydra/inc}/launchpad_hydra.h | 0 .../hydra/pkgconfig/liblaunchpad-hydra.pc.in | 0 src/{ => hydra/src}/launchpad_hydra.c | 0 src/launchpad/CMakeLists.txt | 71 +++++++ {conf => src/launchpad/conf}/launchpad.conf.in | 0 {inc => src/launchpad/inc}/debugger_info.h | 0 {inc => src/launchpad/inc}/launcher_info.h | 0 {inc => src/launchpad/inc}/launchpad_config.h | 0 {inc => src/launchpad/inc}/launchpad_debug.h | 0 {inc => src/launchpad/inc}/launchpad_inotify.h | 0 {inc => src/launchpad/inc}/launchpad_io_channel.h | 0 {inc => src/launchpad/inc}/launchpad_signal.h | 0 {inc => src/launchpad/inc}/loader_info.h | 0 src/launchpad/src/CMakeLists.txt | 209 +++++++++++++++++++++ src/{ => launchpad/src}/debugger_info.c | 0 src/{ => launchpad/src}/launcher_info.c | 0 src/{ => launchpad/src}/launchpad.c | 30 +-- src/{ => launchpad/src}/launchpad_config.c | 0 src/{ => launchpad/src}/launchpad_debug.c | 0 src/{ => launchpad/src}/launchpad_inotify.c | 0 src/{ => launchpad/src}/launchpad_io_channel.c | 0 src/{ => launchpad/src}/launchpad_signal.c | 0 src/{ => launchpad/src}/loader_info.c | 0 src/lib/CMakeLists.txt | 53 ++++++ {inc => src/lib/inc}/launchpad.h | 2 + .../lib/pkgconfig/launchpad.pc.in | 0 src/{ => lib/src}/launchpad_lib.c | 2 +- src/loader/CMakeLists.txt | 74 ++++++++ src/{ => loader/src}/launchpad_loader.c | 0 {parser => src/parser}/CMakeLists.txt | 0 {parser => src/parser}/common.hh | 0 {parser => src/parser}/launchpad_parser_plugin.cc | 0 {parser => src/parser}/launchpad_parser_plugin.hh | 0 .../launchpad_parser_plugin_pkgmgr_interface.cc | 0 {parser => src/parser}/launchpad_plugins.txt | 0 {parser => src/parser}/loader_info.cc | 0 {parser => src/parser}/loader_info.hh | 0 {parser => src/parser}/log_private.hh | 0 52 files changed, 492 insertions(+), 210 deletions(-) rename launchpad-loader.manifest => packaging/launchpad-loader.manifest (100%) rename launchpad.manifest => packaging/launchpad.manifest (100%) rename liblaunchpad.manifest => packaging/liblaunchpad.manifest (100%) create mode 100644 src/CMakeLists.txt rename {inc => src/common/inc}/key.h (100%) rename {inc => src/common/inc}/launchpad_common.h (100%) rename {inc => src/common/inc}/launchpad_types.h (85%) rename src/{ => common/inc}/log_private.h (100%) rename {inc => src/common/inc}/perf.h (100%) rename {inc => src/common/inc}/preexec.h (100%) rename src/{ => common/src}/launchpad_common.c (100%) create mode 100644 src/hydra/CMakeLists.txt rename {inc => src/hydra/inc}/launchpad_hydra.h (100%) rename liblaunchpad-hydra.pc.in => src/hydra/pkgconfig/liblaunchpad-hydra.pc.in (100%) rename src/{ => hydra/src}/launchpad_hydra.c (100%) create mode 100644 src/launchpad/CMakeLists.txt rename {conf => src/launchpad/conf}/launchpad.conf.in (100%) rename {inc => src/launchpad/inc}/debugger_info.h (100%) rename {inc => src/launchpad/inc}/launcher_info.h (100%) rename {inc => src/launchpad/inc}/launchpad_config.h (100%) rename {inc => src/launchpad/inc}/launchpad_debug.h (100%) rename {inc => src/launchpad/inc}/launchpad_inotify.h (100%) rename {inc => src/launchpad/inc}/launchpad_io_channel.h (100%) rename {inc => src/launchpad/inc}/launchpad_signal.h (100%) rename {inc => src/launchpad/inc}/loader_info.h (100%) create mode 100644 src/launchpad/src/CMakeLists.txt rename src/{ => launchpad/src}/debugger_info.c (100%) rename src/{ => launchpad/src}/launcher_info.c (100%) rename src/{ => launchpad/src}/launchpad.c (98%) rename src/{ => launchpad/src}/launchpad_config.c (100%) rename src/{ => launchpad/src}/launchpad_debug.c (100%) rename src/{ => launchpad/src}/launchpad_inotify.c (100%) rename src/{ => launchpad/src}/launchpad_io_channel.c (100%) rename src/{ => launchpad/src}/launchpad_signal.c (100%) rename src/{ => launchpad/src}/loader_info.c (100%) create mode 100644 src/lib/CMakeLists.txt rename {inc => src/lib/inc}/launchpad.h (98%) rename launchpad.pc.in => src/lib/pkgconfig/launchpad.pc.in (100%) rename src/{ => lib/src}/launchpad_lib.c (99%) create mode 100644 src/loader/CMakeLists.txt rename src/{ => loader/src}/launchpad_loader.c (100%) rename {parser => src/parser}/CMakeLists.txt (100%) rename {parser => src/parser}/common.hh (100%) rename {parser => src/parser}/launchpad_parser_plugin.cc (100%) rename {parser => src/parser}/launchpad_parser_plugin.hh (100%) rename {parser => src/parser}/launchpad_parser_plugin_pkgmgr_interface.cc (100%) rename {parser => src/parser}/launchpad_plugins.txt (100%) rename {parser => src/parser}/loader_info.cc (100%) rename {parser => src/parser}/loader_info.hh (100%) rename {parser => src/parser}/log_private.hh (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6197582..e7d515c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,95 +1,5 @@ -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") +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(launchpad C CXX) ADD_DEFINITIONS("-DSHARE_PREFIX=\"/usr/share/aul\"") IF(_TIZEN_FEATURE_PRIORITY_CHANGE) @@ -102,108 +12,9 @@ IF(_TIZEN_FEATURE_SET_PERSONALITY_32) ADD_DEFINITIONS("-DTIZEN_FEATURE_SET_PERSONALITY_32") ENDIF(_TIZEN_FEATURE_SET_PERSONALITY_32) +ADD_DEFINITIONS("-DSHARE_PREFIX=\"/usr/share/aul\"") 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 +ADD_SUBDIRECTORY(src) diff --git a/launchpad-loader.manifest b/packaging/launchpad-loader.manifest similarity index 100% rename from launchpad-loader.manifest rename to packaging/launchpad-loader.manifest diff --git a/launchpad.manifest b/packaging/launchpad.manifest similarity index 100% rename from launchpad.manifest rename to packaging/launchpad.manifest diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index babb8b4..4250709 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -7,7 +7,9 @@ License: Apache-2.0 Source0: %{name}-%{version}.tar.gz Source101: launchpad-process-pool.service Source102: launchpad-process-pool.socket - +Source1001: %{name}.manifest +Source1002: lib%{name}.manifest +Source1003: %{name}-loader.manifest BuildRequires: cmake BuildRequires: pkgconfig(bundle) @@ -87,6 +89,9 @@ Launchpad library (devel) %prep %setup -q +cp %{SOURCE1001} . +cp %{SOURCE1002} . +cp %{SOURCE1003} . %build %if 0%{?sec_build_binary_debug_enable} diff --git a/liblaunchpad.manifest b/packaging/liblaunchpad.manifest similarity index 100% rename from liblaunchpad.manifest rename to packaging/liblaunchpad.manifest diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..3a0a104 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,9 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) + +ADD_SUBDIRECTORY(launchpad) +ADD_SUBDIRECTORY(lib) +ADD_SUBDIRECTORY(loader) +ADD_SUBDIRECTORY(hydra) +ADD_SUBDIRECTORY(parser) + +ADD_DEPENDENCIES(launchpad-loader launchpad-lib) diff --git a/inc/key.h b/src/common/inc/key.h similarity index 100% rename from inc/key.h rename to src/common/inc/key.h diff --git a/inc/launchpad_common.h b/src/common/inc/launchpad_common.h similarity index 100% rename from inc/launchpad_common.h rename to src/common/inc/launchpad_common.h diff --git a/inc/launchpad_types.h b/src/common/inc/launchpad_types.h similarity index 85% rename from inc/launchpad_types.h rename to src/common/inc/launchpad_types.h index 22ae867..fc822d7 100644 --- a/inc/launchpad_types.h +++ b/src/common/inc/launchpad_types.h @@ -40,6 +40,13 @@ typedef enum hydra_cmd { LAUNCH_CANDIDATE, } hydra_cmd_e; +typedef enum launchpad_loader_type { + LAUNCHPAD_LOADER_TYPE_UNSUPPORTED = -1, + LAUNCHPAD_LOADER_TYPE_USER = 1, + LAUNCHPAD_LOADER_TYPE_DYNAMIC = 100, + LAUNCHPAD_LOADER_TYPE_MAX +} launchpad_loader_type_e; + #ifdef __cplusplus } #endif diff --git a/src/log_private.h b/src/common/inc/log_private.h similarity index 100% rename from src/log_private.h rename to src/common/inc/log_private.h diff --git a/inc/perf.h b/src/common/inc/perf.h similarity index 100% rename from inc/perf.h rename to src/common/inc/perf.h diff --git a/inc/preexec.h b/src/common/inc/preexec.h similarity index 100% rename from inc/preexec.h rename to src/common/inc/preexec.h diff --git a/src/launchpad_common.c b/src/common/src/launchpad_common.c similarity index 100% rename from src/launchpad_common.c rename to src/common/src/launchpad_common.c diff --git a/src/hydra/CMakeLists.txt b/src/hydra/CMakeLists.txt new file mode 100644 index 0000000..0ff9ebe --- /dev/null +++ b/src/hydra/CMakeLists.txt @@ -0,0 +1,41 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(launchpad-hydra C) +SET(LAUNCHPAD_HYDRA "launchpad-hydra") + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(LAUNCHPAD_HYDRA_PKGS REQUIRED + dlog + libsystemd) + +FOREACH(flag ${LAUNCHPAD_HYDRA_PKGS_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") + +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") + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/inc) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/common/inc) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES) + +ADD_LIBRARY(${LAUNCHPAD_HYDRA} SHARED ${SOURCES}) +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} ${LAUNCHPAD_HYDRA_PKGS_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(${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/liblaunchpad-hydra.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/liblaunchpad-hydra.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/liblaunchpad-hydra.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/inc/launchpad_hydra.h b/src/hydra/inc/launchpad_hydra.h similarity index 100% rename from inc/launchpad_hydra.h rename to src/hydra/inc/launchpad_hydra.h diff --git a/liblaunchpad-hydra.pc.in b/src/hydra/pkgconfig/liblaunchpad-hydra.pc.in similarity index 100% rename from liblaunchpad-hydra.pc.in rename to src/hydra/pkgconfig/liblaunchpad-hydra.pc.in diff --git a/src/launchpad_hydra.c b/src/hydra/src/launchpad_hydra.c similarity index 100% rename from src/launchpad_hydra.c rename to src/hydra/src/launchpad_hydra.c diff --git a/src/launchpad/CMakeLists.txt b/src/launchpad/CMakeLists.txt new file mode 100644 index 0000000..a51f395 --- /dev/null +++ b/src/launchpad/CMakeLists.txt @@ -0,0 +1,71 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(launchpad-process-pool C) +SET(LAUNCHPAD_PROCESS_POOL "launchpad-process-pool") + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(LAUNCHPAD_PROCESS_POOL_PKGS REQUIRED + bundle + dbus-1 + dlog + gio-2.0 + iniparser + libcap + libsystemd + libtzplatform-config + security-manager + tanchor + ttrace + vconf + ) + +FOREACH(flag ${LAUNCHPAD_PROCESS_POOL_PKGS_CFLAGS}) + SET(EXTRA_CFLAGS_pool "${EXTRA_CFLAGS_pool} ${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}") +ELSE(_TIZEN_FEATURE_PRELINK) +MESSAGE(STATUS "[__PRELINK__] Disable") +SET(EXTRA_CFLAGS_pool "${EXTRA_CFLAGS_pool} ${EXTRA_CFLAGS_common} -fPIE") +ENDIF(_TIZEN_FEATURE_PRELINK) + +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/inc) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/common/inc) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/src/common/src COMMON_SOURCES) + +SET(LAUNCHPAD_PROCESS_POOL_SOURCE_FILES + ${COMMON_SOURCES} + ${SOURCES}) + +ADD_EXECUTABLE(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_SOURCE_FILES}) + +IF(_TIZEN_FEATURE_PRELINK) +TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_PKGS_LDFLAGS} "-lm") +ELSE(_TIZEN_FEATURE_PRELINK) +TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_PKGS_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(${CMAKE_SOURCE_DIR}/packaging/default.debugger.in ${CMAKE_SOURCE_DIR}/packaging/default.debugger @ONLY) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/packaging/default.debugger DESTINATION share/aul) +INSTALL(TARGETS ${LAUNCHPAD_PROCESS_POOL} DESTINATION bin) + +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/conf/launchpad.conf.in ${CMAKE_CURRENT_SOURCE_DIR}/conf/launchpad.conf @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/launchpad.conf DESTINATION share/aul) diff --git a/conf/launchpad.conf.in b/src/launchpad/conf/launchpad.conf.in similarity index 100% rename from conf/launchpad.conf.in rename to src/launchpad/conf/launchpad.conf.in diff --git a/inc/debugger_info.h b/src/launchpad/inc/debugger_info.h similarity index 100% rename from inc/debugger_info.h rename to src/launchpad/inc/debugger_info.h diff --git a/inc/launcher_info.h b/src/launchpad/inc/launcher_info.h similarity index 100% rename from inc/launcher_info.h rename to src/launchpad/inc/launcher_info.h diff --git a/inc/launchpad_config.h b/src/launchpad/inc/launchpad_config.h similarity index 100% rename from inc/launchpad_config.h rename to src/launchpad/inc/launchpad_config.h diff --git a/inc/launchpad_debug.h b/src/launchpad/inc/launchpad_debug.h similarity index 100% rename from inc/launchpad_debug.h rename to src/launchpad/inc/launchpad_debug.h diff --git a/inc/launchpad_inotify.h b/src/launchpad/inc/launchpad_inotify.h similarity index 100% rename from inc/launchpad_inotify.h rename to src/launchpad/inc/launchpad_inotify.h diff --git a/inc/launchpad_io_channel.h b/src/launchpad/inc/launchpad_io_channel.h similarity index 100% rename from inc/launchpad_io_channel.h rename to src/launchpad/inc/launchpad_io_channel.h diff --git a/inc/launchpad_signal.h b/src/launchpad/inc/launchpad_signal.h similarity index 100% rename from inc/launchpad_signal.h rename to src/launchpad/inc/launchpad_signal.h diff --git a/inc/loader_info.h b/src/launchpad/inc/loader_info.h similarity index 100% rename from inc/loader_info.h rename to src/launchpad/inc/loader_info.h diff --git a/src/launchpad/src/CMakeLists.txt b/src/launchpad/src/CMakeLists.txt new file mode 100644 index 0000000..6197582 --- /dev/null +++ b/src/launchpad/src/CMakeLists.txt @@ -0,0 +1,209 @@ +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 diff --git a/src/debugger_info.c b/src/launchpad/src/debugger_info.c similarity index 100% rename from src/debugger_info.c rename to src/launchpad/src/debugger_info.c diff --git a/src/launcher_info.c b/src/launchpad/src/launcher_info.c similarity index 100% rename from src/launcher_info.c rename to src/launchpad/src/launcher_info.c diff --git a/src/launchpad.c b/src/launchpad/src/launchpad.c similarity index 98% rename from src/launchpad.c rename to src/launchpad/src/launchpad.c index b1a3ef1..6d7b43b 100644 --- a/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -41,7 +41,6 @@ #include "key.h" #include "launcher_info.h" -#include "launchpad.h" #include "launchpad_common.h" #include "launchpad_config.h" #include "launchpad_debug.h" @@ -338,8 +337,8 @@ static candidate_process_context_t *__find_slot_from_static_type(int type) candidate_process_context_t *cpc; GList *iter = candidate_slot_list; - if (type == LAUNCHPAD_TYPE_DYNAMIC || - type == LAUNCHPAD_TYPE_UNSUPPORTED) + if (type == LAUNCHPAD_LOADER_TYPE_DYNAMIC || + type == LAUNCHPAD_LOADER_TYPE_UNSUPPORTED) return NULL; while (iter) { @@ -419,7 +418,7 @@ static candidate_process_context_t *__find_slot_from_loader_id(int id) static candidate_process_context_t *__find_slot(int type, int loader_id) { - if (type == LAUNCHPAD_TYPE_DYNAMIC) + if (type == LAUNCHPAD_LOADER_TYPE_DYNAMIC) return __find_slot_from_loader_id(loader_id); return __find_slot_from_static_type(type); @@ -1388,7 +1387,7 @@ static bool __handle_sigchild(int fd, io_condition_e cond, void *data) cpc = __find_slot_from_caller_pid(pid); while (cpc) { - __remove_slot(LAUNCHPAD_TYPE_DYNAMIC, cpc->loader_id); + __remove_slot(LAUNCHPAD_LOADER_TYPE_DYNAMIC, cpc->loader_id); cpc = __find_slot_from_caller_pid(pid); } } while (s > 0); @@ -1579,7 +1578,8 @@ static int __dispatch_cmd_add_loader(bundle *kb) if (add_slot_str && caller_pid) { lid = __make_loader_id(); - cpc = __add_slot(LAUNCHPAD_TYPE_DYNAMIC, lid, atoi(caller_pid), + cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_DYNAMIC, lid, + atoi(caller_pid), add_slot_str, extra, METHOD_TIMEOUT | METHOD_VISIBILITY, METHOD_REQUEST | METHOD_AVAILABLE_MEMORY, @@ -1629,7 +1629,7 @@ static int __dispatch_cmd_add_app_defined_loader(bundle *kb) bundle_encode(info->extra, &extra, &len); lid = __make_loader_id(); - cpc = __add_slot(LAUNCHPAD_TYPE_DYNAMIC, lid, 0, + cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_DYNAMIC, lid, 0, loader_path, (const char *)extra, METHOD_TIMEOUT | METHOD_VISIBILITY, METHOD_REQUEST | METHOD_AVAILABLE_MEMORY, @@ -1646,7 +1646,7 @@ static int __dispatch_cmd_add_app_defined_loader(bundle *kb) return -ENOMEM; } - __prepare_candidate_process(LAUNCHPAD_TYPE_DYNAMIC, lid); + __prepare_candidate_process(LAUNCHPAD_LOADER_TYPE_DYNAMIC, lid); return lid; } @@ -1659,7 +1659,7 @@ static int __dispatch_cmd_remove_loader(bundle *kb) _W("cmd remove loader"); if (id) { lid = atoi(id); - if (__remove_slot(LAUNCHPAD_TYPE_DYNAMIC, lid) == 0) + if (__remove_slot(LAUNCHPAD_LOADER_TYPE_DYNAMIC, lid) == 0) return 0; } @@ -1960,7 +1960,7 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) strcmp(menu_info->comp_type, "svcapp") == 0) { loader_id = __get_loader_id(kb); if (loader_id > PAD_LOADER_ID_DYNAMIC_BASE) { - type = LAUNCHPAD_TYPE_DYNAMIC; + type = LAUNCHPAD_LOADER_TYPE_DYNAMIC; cpc = __find_slot(type, loader_id); if (cpc && !cpc->prepared) cpc = NULL; @@ -1978,7 +1978,7 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) menu_info->app_type, menu_info->loader_name, &org_cpc); } else { - type = LAUNCHPAD_TYPE_DYNAMIC; + type = LAUNCHPAD_LOADER_TYPE_DYNAMIC; cpc = __find_slot(type, loader_id); if (cpc && !cpc->prepared) cpc = NULL; @@ -2422,7 +2422,7 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) int len; if (!strcmp(info->exe, "null")) { - cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset, + cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_USER + user_slot_offset, PAD_LOADER_ID_DIRECT, 0, info->exe, NULL, 0, 0, 0, 0, 0, @@ -2433,7 +2433,7 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) if (cpc == NULL) return; - info->type = LAUNCHPAD_TYPE_USER + user_slot_offset; + info->type = LAUNCHPAD_LOADER_TYPE_USER + user_slot_offset; user_slot_offset++; return; } @@ -2445,7 +2445,7 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) if (info->extra) bundle_encode(info->extra, &extra, &len); - cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset, + cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_USER + user_slot_offset, PAD_LOADER_ID_STATIC, 0, info->exe, (char *)extra, info->detection_method, @@ -2460,7 +2460,7 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) if (cpc == NULL) return; - info->type = LAUNCHPAD_TYPE_USER + user_slot_offset; + info->type = LAUNCHPAD_LOADER_TYPE_USER + user_slot_offset; user_slot_offset++; } } diff --git a/src/launchpad_config.c b/src/launchpad/src/launchpad_config.c similarity index 100% rename from src/launchpad_config.c rename to src/launchpad/src/launchpad_config.c diff --git a/src/launchpad_debug.c b/src/launchpad/src/launchpad_debug.c similarity index 100% rename from src/launchpad_debug.c rename to src/launchpad/src/launchpad_debug.c diff --git a/src/launchpad_inotify.c b/src/launchpad/src/launchpad_inotify.c similarity index 100% rename from src/launchpad_inotify.c rename to src/launchpad/src/launchpad_inotify.c diff --git a/src/launchpad_io_channel.c b/src/launchpad/src/launchpad_io_channel.c similarity index 100% rename from src/launchpad_io_channel.c rename to src/launchpad/src/launchpad_io_channel.c diff --git a/src/launchpad_signal.c b/src/launchpad/src/launchpad_signal.c similarity index 100% rename from src/launchpad_signal.c rename to src/launchpad/src/launchpad_signal.c diff --git a/src/loader_info.c b/src/launchpad/src/loader_info.c similarity index 100% rename from src/loader_info.c rename to src/launchpad/src/loader_info.c diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt new file mode 100644 index 0000000..d5a2ecd --- /dev/null +++ b/src/lib/CMakeLists.txt @@ -0,0 +1,53 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(launchpad-lib C) +SET(LAUNCHPAD_LIB "launchpad") + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(LAUNCHPAD_LIB_PKGS REQUIRED + aul + bundle + dbus-1 + dlog + libcap + libtzplatform-config + security-manager + tanchor + ) + +FOREACH(flag ${LAUNCHPAD_LIB_PKGS_CFLAGS}) + SET(EXTRA_CFLAGS_lib "${EXTRA_CFLAGS_lib} ${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") + +SET(EXTRA_CFLAGS_lib "${EXTRA_CFLAGS_lib} ${EXTRA_CFLAGS_common}") + +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/inc) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/common/inc) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/src/common/src COMMON_SOURCES) + +ADD_LIBRARY(${LAUNCHPAD_LIB} SHARED + ${COMMON_SOURCES} + ${SOURCES}) + +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} ${LAUNCHPAD_LIB_PKGS_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(${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/launchpad.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/launchpad.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/launchpad.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/launchpad.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/liblaunchpad.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/liblaunchpad.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/inc/launchpad.h b/src/lib/inc/launchpad.h similarity index 98% rename from inc/launchpad.h rename to src/lib/inc/launchpad.h index b5a11db..7d20175 100644 --- a/inc/launchpad.h +++ b/src/lib/inc/launchpad.h @@ -75,6 +75,8 @@ int launchpad_loader_main(int argc, char **argv, */ int launchpad_loader_set_priority(int prio); +bundle *launchpad_loader_get_bundle(void); + #ifdef __cplusplus } #endif diff --git a/launchpad.pc.in b/src/lib/pkgconfig/launchpad.pc.in similarity index 100% rename from launchpad.pc.in rename to src/lib/pkgconfig/launchpad.pc.in diff --git a/src/launchpad_lib.c b/src/lib/src/launchpad_lib.c similarity index 99% rename from src/launchpad_lib.c rename to src/lib/src/launchpad_lib.c index 118f561..e2a75bc 100644 --- a/src/launchpad_lib.c +++ b/src/lib/src/launchpad_lib.c @@ -382,7 +382,7 @@ static int __after_loop(void) return -1; } -bundle *launchpad_loader_get_bundle() +API bundle *launchpad_loader_get_bundle(void) { return __bundle; } diff --git a/src/loader/CMakeLists.txt b/src/loader/CMakeLists.txt new file mode 100644 index 0000000..997f034 --- /dev/null +++ b/src/loader/CMakeLists.txt @@ -0,0 +1,74 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(launchpad-loader C) +SET(LAUNCHPAD_LOADER "launchpad-loader") + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(LAUNCHPAD_LOADER_PKGS REQUIRED + dlog + ecore + elementary + security-manager + libtzplatform-config + tanchor + bundle + aul + vconf + buxton2 + libsystemd + gio-2.0 + dbus-1 + libcap + ) + +FOREACH(flag ${LAUNCHPAD_LOADER_PKGS_CFLAGS}) + SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${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_loader "${EXTRA_CFLAGS_loader} ${EXTRA_CFLAGS_common}") +ELSE(_TIZEN_FEATURE_PRELINK) +MESSAGE(STATUS "[__PRELINK__] Disable") +SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${EXTRA_CFLAGS_common} -fPIE") +ENDIF(_TIZEN_FEATURE_PRELINK) + +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/common/inc) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/lib/inc) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/src/common/src COMMON_SOURCES) + +SET(LAUNCHPAD_LOADER_SOURCE_FILES + ${COMMON_SOURCES} + ${SOURCES}) +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} ${LAUNCHPAD_LOADER_PKGS_LDFLAGS} launchpad) +ELSE(_TIZEN_FEATURE_PRELINK) +TARGET_LINK_LIBRARIES(${LAUNCHPAD_LOADER} ${LAUNCHPAD_LOADER_PKGS_LDFLAGS} launchpad "-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) + +CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/packaging/default.loader.in ${CMAKE_SOURCE_DIR}/packaging/default.loader @ONLY) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/packaging/default.loader DESTINATION share/aul) diff --git a/src/launchpad_loader.c b/src/loader/src/launchpad_loader.c similarity index 100% rename from src/launchpad_loader.c rename to src/loader/src/launchpad_loader.c diff --git a/parser/CMakeLists.txt b/src/parser/CMakeLists.txt similarity index 100% rename from parser/CMakeLists.txt rename to src/parser/CMakeLists.txt diff --git a/parser/common.hh b/src/parser/common.hh similarity index 100% rename from parser/common.hh rename to src/parser/common.hh diff --git a/parser/launchpad_parser_plugin.cc b/src/parser/launchpad_parser_plugin.cc similarity index 100% rename from parser/launchpad_parser_plugin.cc rename to src/parser/launchpad_parser_plugin.cc diff --git a/parser/launchpad_parser_plugin.hh b/src/parser/launchpad_parser_plugin.hh similarity index 100% rename from parser/launchpad_parser_plugin.hh rename to src/parser/launchpad_parser_plugin.hh diff --git a/parser/launchpad_parser_plugin_pkgmgr_interface.cc b/src/parser/launchpad_parser_plugin_pkgmgr_interface.cc similarity index 100% rename from parser/launchpad_parser_plugin_pkgmgr_interface.cc rename to src/parser/launchpad_parser_plugin_pkgmgr_interface.cc diff --git a/parser/launchpad_plugins.txt b/src/parser/launchpad_plugins.txt similarity index 100% rename from parser/launchpad_plugins.txt rename to src/parser/launchpad_plugins.txt diff --git a/parser/loader_info.cc b/src/parser/loader_info.cc similarity index 100% rename from parser/loader_info.cc rename to src/parser/loader_info.cc diff --git a/parser/loader_info.hh b/src/parser/loader_info.hh similarity index 100% rename from parser/loader_info.hh rename to src/parser/loader_info.hh diff --git a/parser/log_private.hh b/src/parser/log_private.hh similarity index 100% rename from parser/log_private.hh rename to src/parser/log_private.hh -- 2.7.4 From 207abc7fb457773d1caf2c7033e7a31602baefeb Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 20 Feb 2020 08:14:35 +0900 Subject: [PATCH 07/16] Release version 0.12.0 Changes: - Add a plugin for app-defined loader - Add app-defined loader - Fix return values of __dispatch_cmd_add_app_defined_loader() - Separate codes into directories Change-Id: I0e76ec5d9493acc58e41b88dc0b7559de79ef81f 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 4250709..3cd3478 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.11.0 +Version: 0.12.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From aea787b684bc5fdc3fa1fb1b64bc95d5211866cf Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 20 Feb 2020 09:32:19 +0900 Subject: [PATCH 08/16] Fix log format Change-Id: I7105f7057dc81bb6d40b3bfd5c7ad62f14a57058 Signed-off-by: Hwankyu Jhun --- src/parser/launchpad_parser_plugin.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser/launchpad_parser_plugin.cc b/src/parser/launchpad_parser_plugin.cc index a880a6e..95deccb 100644 --- a/src/parser/launchpad_parser_plugin.cc +++ b/src/parser/launchpad_parser_plugin.cc @@ -36,7 +36,7 @@ int LaunchpadParser::WriteToFile(string pkgid) { if (access(LOADERS_DIRECTORY_PATH, F_OK) != 0) mkdir(LOADERS_DIRECTORY_PATH, 0644); - LOGI("write to file (%d)", loader_list_.size()); + LOGI("write to file (%zu)", loader_list_.size()); for (auto& i : loader_list_) { std::ofstream out_file; LOGI("write ID (%s)", i->GetId().c_str()); -- 2.7.4 From c8420009b043419336926914312b675e925646be Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 20 Feb 2020 09:32:33 +0900 Subject: [PATCH 09/16] Release version 0.12.1 Changes: - Fix log format Change-Id: I7fdd6ddf39a2b876d53312ba8e4e5ef26b4c6a59 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 3cd3478..db73636 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.12.0 +Version: 0.12.1 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 1c9a87dca5fb04388284b35f41106dd7111d9e29 Mon Sep 17 00:00:00 2001 From: hyunho Date: Thu, 20 Feb 2020 11:11:36 +0900 Subject: [PATCH 10/16] Add app_defined_loader Change-Id: I9ec6d2202ec3e6596a19b787a204703771996669 Signed-off-by: hyunho --- packaging/app-defined-loader.manifest | 8 + packaging/launchpad.spec | 14 + src/CMakeLists.txt | 2 + src/app_defined_loader/CMakeLists.txt | 69 +++++ src/app_defined_loader/src/app_defined_loader.cc | 330 +++++++++++++++++++++++ src/common/inc/launchpad_common.h | 14 + src/launchpad/src/launchpad.c | 12 +- src/loader/src/launchpad_loader.c | 5 - 8 files changed, 440 insertions(+), 14 deletions(-) create mode 100644 packaging/app-defined-loader.manifest create mode 100644 src/app_defined_loader/CMakeLists.txt create mode 100644 src/app_defined_loader/src/app_defined_loader.cc diff --git a/packaging/app-defined-loader.manifest b/packaging/app-defined-loader.manifest new file mode 100644 index 0000000..bd30b8b --- /dev/null +++ b/packaging/app-defined-loader.manifest @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index db73636..5935833 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -10,6 +10,7 @@ Source102: launchpad-process-pool.socket Source1001: %{name}.manifest Source1002: lib%{name}.manifest Source1003: %{name}-loader.manifest +Source1004: app-defined-loader.manifest BuildRequires: cmake BuildRequires: pkgconfig(bundle) @@ -72,6 +73,13 @@ Group: Application Framework/Application Launcher %description -n launchpad-loader Launchpad-Loader for launching applications +%package -n app-defined-loader +Summary: App-Defined-Loader for launching applications +Group: Application Framework/Application Launcher + +%description -n app-defined-loader +App-Defined-Loader for launching applications + %package -n liblaunchpad Summary: Launchpad library Group: Development/Libraries @@ -92,6 +100,7 @@ Launchpad library (devel) cp %{SOURCE1001} . cp %{SOURCE1002} . cp %{SOURCE1003} . +cp %{SOURCE1004} . %build %if 0%{?sec_build_binary_debug_enable} @@ -160,6 +169,11 @@ ln -sf ../launchpad-process-pool.service %{buildroot}%{_unitdir_user}/basic.targ %{_prefix}/share/aul/default.loader %{_bindir}/launchpad-loader +%files -n app-defined-loader +%manifest app-defined-loader.manifest +%license LICENSE +%{_bindir}/app-defined-loader + %files -n liblaunchpad %manifest liblaunchpad.manifest %license LICENSE diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3a0a104..dbab7f3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,9 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8) ADD_SUBDIRECTORY(launchpad) ADD_SUBDIRECTORY(lib) ADD_SUBDIRECTORY(loader) +ADD_SUBDIRECTORY(app_defined_loader) ADD_SUBDIRECTORY(hydra) ADD_SUBDIRECTORY(parser) ADD_DEPENDENCIES(launchpad-loader launchpad-lib) +ADD_DEPENDENCIES(app-defined-loader launchpad-lib) diff --git a/src/app_defined_loader/CMakeLists.txt b/src/app_defined_loader/CMakeLists.txt new file mode 100644 index 0000000..b0f869e --- /dev/null +++ b/src/app_defined_loader/CMakeLists.txt @@ -0,0 +1,69 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(app-defined-loader) +SET(APP_DEFINED_LOADER "app-defined-loader") + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(APP_DEFINED_LOADER_PKGS REQUIRED + dlog + ecore + ecore-core + bundle + aul + gio-2.0 + dbus-1 + libsystemd + ) + +FOREACH(flag ${APP_DEFINED_LOADER_PKGS_CFLAGS}) + SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${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_loader "${EXTRA_CFLAGS_loader} ${EXTRA_CFLAGS_common}") +ELSE(_TIZEN_FEATURE_PRELINK) +MESSAGE(STATUS "[__PRELINK__] Disable") +SET(EXTRA_CFLAGS_loader "${EXTRA_CFLAGS_loader} ${EXTRA_CFLAGS_common} -fPIE") +ENDIF(_TIZEN_FEATURE_PRELINK) + +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_CXX_FLAGS_RELEASE "-O2") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/common/inc) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/lib/inc) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/src/common/src COMMON_SOURCES) + +SET(APP_DEFINED_LOADER_SOURCE_FILES + ${COMMON_SOURCES} + ${SOURCES}) +ADD_EXECUTABLE(${APP_DEFINED_LOADER} ${APP_DEFINED_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(${APP_DEFINED_LOADER} "-ldl -Wl,-rpath,: -Wl,--disable-new-dtags") + +IF(_TIZEN_FEATURE_PRELINK) +TARGET_LINK_LIBRARIES(${APP_DEFINED_LOADER} ${APP_DEFINED_LOADER_PKGS_LDFLAGS} launchpad) +ELSE(_TIZEN_FEATURE_PRELINK) +TARGET_LINK_LIBRARIES(${APP_DEFINED_LOADER} ${APP_DEFINED_LOADER_PKGS_LDFLAGS} launchpad "-pie") +ENDIF(_TIZEN_FEATURE_PRELINK) + +SET_TARGET_PROPERTIES(${APP_DEFINED_LOADER} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_loader}) +SET_TARGET_PROPERTIES(${APP_DEFINED_LOADER} + PROPERTIES SKIP_BUILD_RPATH TRUE + ) # remove rpath option that is automatically generated by cmake. +INSTALL(TARGETS ${APP_DEFINED_LOADER} DESTINATION bin) \ No newline at end of file diff --git a/src/app_defined_loader/src/app_defined_loader.cc b/src/app_defined_loader/src/app_defined_loader.cc new file mode 100644 index 0000000..39ba7d1 --- /dev/null +++ b/src/app_defined_loader/src/app_defined_loader.cc @@ -0,0 +1,330 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include "launchpad_common.h" +#include "launchpad_types.h" +#include "launchpad.h" +#include "key.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "APP_DEFINED_LOADER" + +#ifndef PR_TASK_PERF_USER_TRACE +#define PR_TASK_PERF_USER_TRACE 666 +#endif + +#ifndef C_EXPORT +#define C_EXPORT extern "C" __attribute__((visibility("default"))) +#endif + +using namespace tizen_base; +using namespace std; +namespace launchpad { + +class AppDefinedLoader { + public: + AppDefinedLoader(int argc, char** argv) + : argc_(argc), argv_(argv) { + lifecycle_cb_ = shared_ptr(new loader_lifecycle_callback_s()); + lifecycle_cb_->create = OnCreate; + lifecycle_cb_->launch = OnLaunch; + lifecycle_cb_->terminate = OnTerminate; + + adapter_ = shared_ptr(new loader_adapter_s()); + adapter_->loop_begin = OnLoopBegin; + adapter_->loop_quit = OnLoopQuit; + adapter_->add_fd = OnAddFd; + adapter_->remove_fd = OnRemoveFd; + } + + ~AppDefinedLoader() { + _W("app defined loader destroyed"); + } + + shared_ptr GetLifeCycle() { + return lifecycle_cb_; + } + + shared_ptr GetAdapter() { + return adapter_; + } + + void SetLoaderPriority(bool enable) { + loader_priority_enabled_ = enable; + } + + void SetPriorityChanged(bool enable) { + priority_change_enabled_ = enable; + } + + bool IsLoaderPriorityEnabled() { + return loader_priority_enabled_; + } + + bool IsPriorityChangeEnabled() { + return priority_change_enabled_; + } + + void SetFdHandler(Ecore_Fd_Handler* fd_handler) { + fd_handler_ = fd_handler; + } + + Ecore_Fd_Handler* GetFdHandler() { + return fd_handler_; + } + + void SetReceiver(loader_receiver_cb receiver) { + receiver_cb_ = receiver; + } + + loader_receiver_cb GetReceiver() { + return receiver_cb_; + } + + private: + static void PreloadLib(Bundle data) { + vector so_array = data.GetStringArray("preload"); + if (so_array.size() == 0) + return; + for (auto& i : so_array) { + if (i.empty()) + continue; + void* handle = dlopen(i.c_str(), RTLD_NOW | RTLD_NODELETE); + if (handle == nullptr) + _E("fail to load : %s, err : %s", i.c_str(), dlerror()); + else + _D("preload %s# - handle : %p", i.c_str(), handle); + } + } + + static void OnCreate(bundle *extra, int type, void *user_data) { + _I("on create"); + AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + Bundle ex = Bundle(extra, false, false); + string loader_type = ex.GetString(KEY_LOADER_TYPE); + if (loader_type.empty()) { + _E("No loader type"); + return; + } + + if (loader->IsLoaderPriorityEnabled()) + launchpad_loader_set_priority(19); + loader->PreloadLib(ex); + ecore_init(); + setenv("AUL_LOADER_INIT", "1", 1); + + if (loader_type == LOADER_TYPE_SW) + setenv("AUL_HWACC", "none", 1); + else if (loader_type == LOADER_TYPE_HW) + setenv("AUL_HWACC", "hw", 1); + } + + static int OnLaunch(int argc, char **argv, const char *app_path, + const char *appid, const char *pkgid, const char *pkg_type, void *user_data) { + _I("on launch"); + AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + if (!loader->IsPriorityChangeEnabled()) + return 0; + + bundle *kb = launchpad_loader_get_bundle(); + if (kb == nullptr) + return 0; + + Bundle data(kb, false, false); + string high_priority = data.GetString(AUL_K_HIGHPRIORITY); + if (high_priority == "true") + launchpad_loader_set_priority(-12); + data.Delete(AUL_K_HIGHPRIORITY); + return 0; + } + + void DoExec(string libdir) { + _I("do exec"); + char err_str[MAX_LOCAL_BUFSZ]; + if (access(argv_[LOADER_ARG_PATH], F_OK | R_OK)) { + SECURE_LOGE("access() failed for file: \"%s\", error: %d (%s)", argv_[LOADER_ARG_PATH], errno, + strerror_r(errno, err_str, sizeof(err_str))); + } else { + SECURE_LOGD("[candidate] Exec application (%s)", + argv_[LOADER_ARG_PATH]); + _close_all_fds(); + if (!libdir.empty()) + setenv("LD_LIBRARY_PATH", libdir.c_str(), 1); + unsetenv("AUL_LOADER_INIT"); + unsetenv("AUL_HWACC"); + if (execv(argv_[LOADER_ARG_PATH], argv_) < 0) { + _send_message_to_logger(argv_[LOADER_ARG_PATH], + "Failed to execute a file. error(%d:%s)", errno, + strerror_r(errno, err_str, sizeof(err_str))); + } + } + } + + int DoDlOpen(bool restore, string old_cwd, string libdir) { + _I("do dlopen"); + string hwc_message = "" + to_string(getpid()) + "|lib loading start"; + prctl(PR_TASK_PERF_USER_TRACE, hwc_message.c_str(), hwc_message.size()); + void* handle = dlopen(argv_[LOADER_ARG_PATH], + RTLD_LAZY | RTLD_GLOBAL | RTLD_NODELETE); + if (handle == nullptr) { + _E("dlopen(%s) is failed. error(%s)", argv_[LOADER_ARG_PATH], dlerror()); + DoExec(libdir); + return -1; + } + + hwc_message = "" + 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); + + void* dl_main = dlsym(handle, "main"); + if (dl_main == nullptr) { + _E("dlsym not founded(%s). Please export 'main' function", dlerror()); + dlclose(handle); + DoExec(libdir); + return -1; + } + + _I("call main"); + return ((int (*)(int, char**))dl_main)(argc_, argv_); + } + + static int OnTerminate(int argc, char **argv, void *user_data) { + SECURE_LOGD("[candidate] Launch real application (%s)", argv[LOADER_ARG_PATH]); + char old_cwd[PATH_MAX] = {0, }; + AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + if (getcwd(old_cwd, sizeof(old_cwd)) == nullptr) { + loader->DoDlOpen(false, old_cwd, ""); + } else { + char* libdir = _get_libdir(argv[LOADER_ARG_PATH]); + if (libdir == NULL) { + return loader->DoDlOpen(false, old_cwd, ""); + } else { + /* To support 2.x applications which use their own shared libraries. + * We set '-rpath' to make the dynamic linker looks in the CWD forcely, + * so here we change working directory to find shared libraries well. + */ + bool restore = false; + if (chdir(libdir)) + _E("failed to chdir: %d", errno); + else + restore = true; + string libdir_str = string(libdir); + free(libdir); + return loader->DoDlOpen(restore, old_cwd, libdir_str); + } + } + return -1; + } + + static void OnLoopBegin(void* user_data) { + _I("on loop begin"); + ecore_main_loop_begin(); + } + + static void OnLoopQuit(void* user_data) { + _I("on loop quit"); + ecore_main_loop_quit(); + } + + static void OnAddFd(void* user_data, int fd, + loader_receiver_cb receiver) { + AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + Ecore_Fd_Handler* handler = ecore_main_fd_handler_add(fd, + (Ecore_Fd_Handler_Flags)(ECORE_FD_READ | ECORE_FD_ERROR), + FdHandler, loader, nullptr, nullptr); + if (handler == nullptr) { + _E("fd_handler is NULL"); + close(fd); + exit(-1); + } + _I("set handler done (%d)", fd); + loader->SetFdHandler(handler); + loader->SetReceiver(receiver); + } + + static Eina_Bool FdHandler(void *user_data, Ecore_Fd_Handler *handler) { + _I("fd handler"); + AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + int fd = ecore_main_fd_handler_fd_get(handler); + if (fd == -1) { + _E("[candidate] ECORE_FD_GET"); + exit(-1); + } + if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ)) { + if (loader->GetReceiver()) + loader->GetReceiver()(fd); + } else if (ecore_main_fd_handler_active_get( + handler, ECORE_FD_ERROR)) { + _E("[candidate] ECORE_FD_ERROR"); + close(fd); + exit(-1); + } + return ECORE_CALLBACK_CANCEL; + } + + static void OnRemoveFd(void *user_data, int fd) { + _I("remove fd"); + AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + if (loader->GetFdHandler() == nullptr) + return; + ecore_main_fd_handler_del(loader->GetFdHandler()); + loader->SetFdHandler(nullptr); + loader->SetReceiver(nullptr); + } + + private: + shared_ptr lifecycle_cb_ = nullptr; + shared_ptr adapter_ = nullptr; + bool loader_priority_enabled_ = false; + bool priority_change_enabled_ = false; + loader_receiver_cb receiver_cb_; + Ecore_Fd_Handler* fd_handler_ = nullptr; + int argc_; + char** argv_; +}; + +} + +C_EXPORT int main(int argc, char **argv) +{ + launchpad::AppDefinedLoader loader(argc, argv); + +#ifdef TIZEN_FEATURE_LOADER_PRIORITY + loader->SetLoaderPriority(true); +#endif +#ifdef TIZEN_FEATURE_PRIORITY_CHANGE + loader->SetPriorityChanged(true); +#endif + + return launchpad_loader_main(argc, argv, + loader.GetLifeCycle().get(), loader.GetAdapter().get(), &loader); +} \ No newline at end of file diff --git a/src/common/inc/launchpad_common.h b/src/common/inc/launchpad_common.h index dc60559..5d97b77 100644 --- a/src/common/inc/launchpad_common.h +++ b/src/common/inc/launchpad_common.h @@ -17,7 +17,9 @@ #ifndef __LAUNCHPAD_COMMON_H__ #define __LAUNCHPAD_COMMON_H__ +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif #include #include @@ -57,6 +59,11 @@ #define PAD_LOADER_ID_DIRECT 1 #define PAD_LOADER_ID_DYNAMIC_BASE 10 +#define KEY_LOADER_TYPE "loader_type" +#define LOADER_TYPE_COMMON "common-loader" +#define LOADER_TYPE_HW "hw-loader" +#define LOADER_TYPE_SW "sw-loader" + #define _E(fmt, arg...) LOGE(fmt, ##arg) #define _D(fmt, arg...) LOGD(fmt, ##arg) #define _W(fmt, arg...) LOGW(fmt, ##arg) @@ -72,6 +79,10 @@ #define ARRAY_SIZE(x) ((sizeof(x)) / sizeof(x[0])) #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) +#ifdef __cplusplus +extern "C" { +#endif + typedef struct _app_pkt_t { int cmd; int len; @@ -125,5 +136,8 @@ int _verify_proc_caps(void); int _prepare_id_file(void); void _print_hwc_log(const char *format, ...); +#ifdef __cplusplus +} +#endif #endif /* __LAUNCHPAD_COMMON_H__ */ diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c index 6d7b43b..f1a7d09 100644 --- a/src/launchpad/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -1600,7 +1600,6 @@ static int __dispatch_cmd_add_loader(bundle *kb) static int __dispatch_cmd_add_app_defined_loader(bundle *kb) { const char *loader_name; - const char *loader_path; int lid, len; candidate_process_context_t *cpc; const loader_info_t *info; @@ -1614,15 +1613,10 @@ static int __dispatch_cmd_add_app_defined_loader(bundle *kb) return -EINVAL; } - /* TODO: use app-defined-loader */ - loader_path = _loader_info_find_loader_path_by_loader_name( - loader_info_list, COMMON_LOADER_NAME); - info = _loader_info_find_loader_by_loader_name( app_defined_loader_info_list, loader_name); - if (loader_path == NULL || info == NULL || info->extra == NULL) { - _E("loader_name %s, loader_path %d, info %d", - loader_name, loader_path != NULL, info != NULL); + if (info == NULL || info->extra == NULL) { + _E("loader_name %s, info %d", loader_name, info != NULL); return -EINVAL; } @@ -1630,7 +1624,7 @@ static int __dispatch_cmd_add_app_defined_loader(bundle *kb) lid = __make_loader_id(); cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_DYNAMIC, lid, 0, - loader_path, (const char *)extra, + "/usr/bin/app-defined-loader", (const char *)extra, METHOD_TIMEOUT | METHOD_VISIBILITY, METHOD_REQUEST | METHOD_AVAILABLE_MEMORY, METHOD_TTL | METHOD_OUT_OF_MEMORY, diff --git a/src/loader/src/launchpad_loader.c b/src/loader/src/launchpad_loader.c index 4dc371e..fee50e6 100644 --- a/src/loader/src/launchpad_loader.c +++ b/src/loader/src/launchpad_loader.c @@ -37,11 +37,6 @@ #define PR_TASK_PERF_USER_TRACE 666 #endif -#define KEY_LOADER_TYPE "loader_type" -#define LOADER_TYPE_COMMON "common-loader" -#define LOADER_TYPE_HW "hw-loader" -#define LOADER_TYPE_SW "sw-loader" - #define PATH_LIB_VC_ELM "/usr/lib/libvc-elm.so.0" extern bundle *launchpad_loader_get_bundle(void); -- 2.7.4 From 3e627970ab601d2f93b21536841e34e8fd375dfc Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 21 Feb 2020 12:34:13 +0900 Subject: [PATCH 11/16] Support memory management feature To manage memory usage, the launchpad checks the proc filesystem. If the percentage of memory usage is over the threshold value, the launchpad terminates the running slots. In this time, the running slots are managed by the score and the memory usage(PSS). (exclude hydra loader) The score of the candidate slot is decided by the amount of usage. Change-Id: Ie8678be7dc6dfb346b4523b996bfa39d02b006f5 Signed-off-by: Hwankyu Jhun --- src/launchpad/conf/launchpad.conf.in | 4 + src/launchpad/inc/launchpad_config.h | 2 + src/launchpad/inc/launchpad_memory_monitor.h | 34 ++++ src/launchpad/inc/launchpad_proc.h | 24 +++ src/launchpad/src/launchpad.c | 234 +++++++++++++++++++++++---- src/launchpad/src/launchpad_config.c | 109 ++++++++++--- src/launchpad/src/launchpad_memory_monitor.c | 157 ++++++++++++++++++ src/launchpad/src/launchpad_proc.c | 147 +++++++++++++++++ 8 files changed, 658 insertions(+), 53 deletions(-) create mode 100644 src/launchpad/inc/launchpad_memory_monitor.h create mode 100644 src/launchpad/inc/launchpad_proc.h create mode 100644 src/launchpad/src/launchpad_memory_monitor.c create mode 100644 src/launchpad/src/launchpad_proc.c diff --git a/src/launchpad/conf/launchpad.conf.in b/src/launchpad/conf/launchpad.conf.in index 91fed8c..3615188 100644 --- a/src/launchpad/conf/launchpad.conf.in +++ b/src/launchpad/conf/launchpad.conf.in @@ -3,3 +3,7 @@ LowKey=memory/sysman/low_memory LowValue=2 NormalKey=memory/sysman/low_memory NormalValue=1 + +[MemoryMonitor] +Threshold=80 +Interval=5000 diff --git a/src/launchpad/inc/launchpad_config.h b/src/launchpad/inc/launchpad_config.h index 3b819da..1d2ee1e 100644 --- a/src/launchpad/inc/launchpad_config.h +++ b/src/launchpad/inc/launchpad_config.h @@ -22,6 +22,8 @@ typedef enum { CONFIG_TYPE_MEMORY_STATUS_LOW_VALUE, CONFIG_TYPE_MEMORY_STATUS_NORMAL_KEY, CONFIG_TYPE_MEMORY_STATUS_NORMAL_VALUE, + CONFIG_TYPE_MEMORY_MONITOR_THRESHOLD, + CONFIG_TYPE_MEMORY_MONITOR_INTERVAL, } config_type_e; const char *_config_get_string_value(config_type_e type); diff --git a/src/launchpad/inc/launchpad_memory_monitor.h b/src/launchpad/inc/launchpad_memory_monitor.h new file mode 100644 index 0000000..a8486be --- /dev/null +++ b/src/launchpad/inc/launchpad_memory_monitor.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_MEMORY_MONITOR_H__ +#define __LAUNCHPAD_MEMORY_MONITOR_H__ + +#include + +typedef int (*memory_monitor_cb)(bool low_memory, void *user_data); + +int _memory_monitor_init(void); + +void _memory_monitor_fini(void); + +int _memory_monitor_set_event_cb(memory_monitor_cb callback, void *user_data); + +int _memory_monitor_reset_timer(void); + +bool _memory_monitor_is_low_memory(void); + +#endif /* __LAUNCHPAD_MEMORY_MONITOR_H__ */ diff --git a/src/launchpad/inc/launchpad_proc.h b/src/launchpad/inc/launchpad_proc.h new file mode 100644 index 0000000..eaff0f6 --- /dev/null +++ b/src/launchpad/inc/launchpad_proc.h @@ -0,0 +1,24 @@ +/* + * 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_PROC_H__ +#define __LAUNCHPAD_PROC_H__ + +int _proc_get_mem_used_ratio(unsigned int *mem_used_ratio); + +int _proc_get_mem_pss(int pid, unsigned int *mem_pss); + +#endif /* __LAUNCHPAD_PROC_H__ */ diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c index f1a7d09..487da6e 100644 --- a/src/launchpad/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -44,12 +44,14 @@ #include "launchpad_common.h" #include "launchpad_config.h" #include "launchpad_debug.h" +#include "launchpad_inotify.h" #include "launchpad_io_channel.h" +#include "launchpad_memory_monitor.h" +#include "launchpad_proc.h" #include "launchpad_signal.h" #include "launchpad_types.h" #include "loader_info.h" #include "perf.h" -#include "launchpad_inotify.h" #define AUL_PR_NAME 16 #define EXEC_CANDIDATE_EXPIRED 5 @@ -74,6 +76,8 @@ #define PAD_ERR_INVALID_PATH -4 #define CPU_CHECKER_TIMEOUT 1000 #define PI 3.14159265 +#define WIN_SCORE 100 +#define LOSE_SCORE_RATE 0.7f enum candidate_process_state_e { CANDIDATE_PROCESS_STATE_RUNNING, @@ -114,6 +118,8 @@ typedef struct { io_channel_h client_channel; io_channel_h channel; io_channel_h hydra_channel; + unsigned int score; + unsigned int pss; } candidate_process_context_t; typedef struct { @@ -177,7 +183,8 @@ static gboolean __handle_idle_checker(gpointer data); static int __add_idle_checker(int detection_method, GList *cur); static void __dispose_candidate_process(candidate_process_context_t *cpc); static bool __is_low_memory(void); -static void __update_slot_state(candidate_process_context_t *cpc, int method); +static void __update_slot_state(candidate_process_context_t *cpc, int method, + bool force); static void __init_app_defined_loader_monitor(void); static gboolean __handle_queuing_slots(gpointer data) @@ -424,6 +431,106 @@ static candidate_process_context_t *__find_slot(int type, int loader_id) return __find_slot_from_static_type(type); } +static void __update_slot_score(candidate_process_context_t *slot) +{ + if (!slot) + return; + + slot->score *= LOSE_SCORE_RATE; + slot->score += WIN_SCORE; +} + +static void __update_slots_pss(void) +{ + candidate_process_context_t *cpc; + GList *iter; + + iter = candidate_slot_list; + while (iter) { + cpc = (candidate_process_context_t *)iter->data; + iter = g_list_next(iter); + + if (cpc->pid == CANDIDATE_NONE) + continue; + + _proc_get_mem_pss(cpc->pid, &cpc->pss); + } +} + +static gint __compare_slot(gconstpointer a, gconstpointer b) +{ + candidate_process_context_t *slot_a = (candidate_process_context_t *)a; + candidate_process_context_t *slot_b = (candidate_process_context_t *)b; + + if (slot_a->is_hydra && !slot_b->is_hydra) + return -1; + if (!slot_a->is_hydra && slot_b->is_hydra) + return 1; + + if (slot_a->score < slot_b->score) + return 1; + if (slot_a->score > slot_b->score) + return -1; + + if (slot_a->pss < slot_b->pss) + return -1; + if (slot_a->pss > slot_b->pss) + return 1; + + return 0; +} + +static candidate_process_context_t *__get_running_slot(bool is_hydra) +{ + candidate_process_context_t *cpc; + GList *iter; + + iter = candidate_slot_list; + while (iter) { + cpc = (candidate_process_context_t *)iter->data; + if (cpc->is_hydra == is_hydra && cpc->pid != CANDIDATE_NONE) + return cpc; + + iter = g_list_next(iter); + } + + return NULL; +} + +static void __pause_last_running_slot(bool is_hydra) +{ + candidate_process_context_t *cpc = NULL; + GList *iter; + + 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; + + iter = g_list_previous(iter); + } + + if (!cpc) + return; + + __update_slot_state(cpc, METHOD_OUT_OF_MEMORY, true); +} + +static void __resume_all_slots(void) +{ + candidate_process_context_t *cpc; + GList *iter; + + iter = candidate_slot_list; + while (iter) { + cpc = (candidate_process_context_t *)iter->data; + __update_slot_state(cpc, METHOD_AVAILABLE_MEMORY, false); + + iter = g_list_next(iter); + } +} + static void __kill_process(int pid) { char err_str[MAX_LOCAL_BUFSZ] = { 0, }; @@ -671,7 +778,7 @@ static gboolean __handle_deactivate_event(gpointer user_data) candidate_process_context_t *cpc; cpc = (candidate_process_context_t *)user_data; - __update_slot_state(cpc, METHOD_TTL); + __update_slot_state(cpc, METHOD_TTL, false); _D("Deactivate event: type(%d)", cpc->type); return G_SOURCE_REMOVE; @@ -761,6 +868,8 @@ static int __prepare_candidate_process(int type, int loader_id) __set_live_timer(cpt); } + _memory_monitor_reset_timer(); + return 0; } @@ -865,6 +974,8 @@ static int __send_launchpad_loader(candidate_process_context_t *cpc, cpc->pid = CANDIDATE_NONE; __dispose_candidate_process(cpc); __set_timer(cpc); + __update_slot_score(cpc); + return pid; } @@ -1806,34 +1917,53 @@ static int __dispatch_cmd_update_app_type(bundle *b) return 0; } -static void __update_slot_state(candidate_process_context_t *cpc, int method) +static void __deactivate_slot(candidate_process_context_t *cpc) { - if (method == METHOD_OUT_OF_MEMORY) { - if ((cpc->deactivation_method & method) && __is_low_memory()) { - cpc->state = CANDIDATE_PROCESS_STATE_PAUSED; - __dispose_candidate_process(cpc); - } else { - cpc->state = CANDIDATE_PROCESS_STATE_RUNNING; - if (!cpc->touched && !cpc->on_boot) - return; - if (!cpc->app_exists || cpc->pid > CANDIDATE_NONE) - return; - if (cpc->detection_method & METHOD_TIMEOUT) - __set_timer(cpc); - } - } else if (cpc->activation_method & method) { - __update_slot_state(cpc, METHOD_OUT_OF_MEMORY); - } else if (cpc->deactivation_method & method) { - cpc->state = CANDIDATE_PROCESS_STATE_PAUSED; - __dispose_candidate_process(cpc); - } else { - cpc->state = CANDIDATE_PROCESS_STATE_RUNNING; - if (!cpc->touched && !cpc->on_boot) - return; - if (!cpc->app_exists || cpc->pid > CANDIDATE_NONE) - return; - if (cpc->detection_method & METHOD_TIMEOUT) - __set_timer(cpc); + if (cpc->state == CANDIDATE_PROCESS_STATE_PAUSED) + return; + + cpc->state = CANDIDATE_PROCESS_STATE_PAUSED; + __dispose_candidate_process(cpc); +} + +static void __activate_slot(candidate_process_context_t *cpc) +{ + if (cpc->state == CANDIDATE_PROCESS_STATE_RUNNING) + return; + + cpc->state = CANDIDATE_PROCESS_STATE_RUNNING; + if (!cpc->touched && !cpc->on_boot) + return; + + if (!cpc->app_exists || cpc->pid > CANDIDATE_NONE) + return; + + if (cpc->detection_method & METHOD_TIMEOUT) + __set_timer(cpc); +} + +static void __update_slot_state(candidate_process_context_t *cpc, int method, + bool force) +{ + switch (method) { + case METHOD_OUT_OF_MEMORY: + if ((force || cpc->deactivation_method & method) && + __is_low_memory()) + __deactivate_slot(cpc); + else + __activate_slot(cpc); + break; + case METHOD_TTL: + if (force || cpc->deactivation_method & method) + __deactivate_slot(cpc); + break; + case METHOD_AVAILABLE_MEMORY: + case METHOD_REQUEST: + __update_slot_state(cpc, METHOD_OUT_OF_MEMORY, force); + break; + default: + __activate_slot(cpc); + break; } } @@ -1999,7 +2129,7 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) org_cpc->timer = 0; } - __update_slot_state(org_cpc, METHOD_REQUEST); + __update_slot_state(org_cpc, METHOD_REQUEST, true); __set_timer(org_cpc); } } else { @@ -2007,6 +2137,7 @@ static bool __handle_launch_event(int fd, io_condition_e cond, void *data) pid = __send_launchpad_loader(cpc, pkt, app_path, clifd); } + _memory_monitor_reset_timer(); __send_result_to_caller(clifd, pid, app_path); clifd = -1; end: @@ -2109,6 +2240,8 @@ static candidate_process_context_t *__create_slot(int type, int loader_id, cpc->ttl = ttl; cpc->live_timer = 0; cpc->is_hydra = is_hydra; + cpc->score = WIN_SCORE; + cpc->pss = 0; if ((cpc->deactivation_method & METHOD_OUT_OF_MEMORY) && __is_low_memory()) @@ -2482,8 +2615,12 @@ static void __add_app_defined_loaders(void) static bool __is_low_memory(void) { + if (_memory_monitor_is_low_memory()) + return true; + if (__memory_status_low >= MEMORY_STATUS_LOW) return true; + return false; } @@ -2512,7 +2649,7 @@ static void __memory_status_low_changed_cb(keynode_t *node, void *data) iter = candidate_slot_list; while (iter) { cpc = (candidate_process_context_t *)iter->data; - __update_slot_state(cpc, METHOD_OUT_OF_MEMORY); + __update_slot_state(cpc, METHOD_OUT_OF_MEMORY, false); iter = g_list_next(iter); } } @@ -2529,7 +2666,7 @@ static void __memory_status_normal_changed_cb(keynode_t *node, void *data) iter = candidate_slot_list; while (iter) { cpc = (candidate_process_context_t *)iter->data; - __update_slot_state(cpc, METHOD_AVAILABLE_MEMORY); + __update_slot_state(cpc, METHOD_AVAILABLE_MEMORY, true); iter = g_list_next(iter); } } @@ -2664,6 +2801,34 @@ static int __init_logger_fd(void) return 0; } +static int __memory_monitor_cb(bool low_memory, void *user_data) +{ + candidate_process_context_t *cpc; + + cpc = __get_running_slot(false); + if (!cpc && low_memory) + return -1; + + __update_slots_pss(); + + candidate_slot_list = g_list_sort(candidate_slot_list, __compare_slot); + + _W("low memory(%s)", low_memory ? "true" : "false"); + if (low_memory) { + do { + __pause_last_running_slot(false); + + cpc = __get_running_slot(false); + if (!cpc) + break; + } while (__is_low_memory()); + } else { + __resume_all_slots(); + } + + return 0; +} + static int __before_loop(int argc, char **argv) { int ret; @@ -2720,12 +2885,15 @@ static int __before_loop(int argc, char **argv) __register_vconf_events(); __init_app_defined_loader_monitor(); + _memory_monitor_init(); + _memory_monitor_set_event_cb(__memory_monitor_cb, NULL); return 0; } static void __after_loop(void) { + _memory_monitor_fini(); __unregister_vconf_events(); if (__pid_table) g_hash_table_destroy(__pid_table); diff --git a/src/launchpad/src/launchpad_config.c b/src/launchpad/src/launchpad_config.c index 8c74693..5b517b0 100644 --- a/src/launchpad/src/launchpad_config.c +++ b/src/launchpad/src/launchpad_config.c @@ -36,6 +36,10 @@ #define KEY_MEMORY_STATUS_NORMAL_KEY "NormalKey" #define KEY_MEMORY_STATUS_NORMAL_VALUE "NormalValue" +#define TAG_MEMORY_MONITOR "MemoryMonitor" +#define KEY_MEMORY_MONITOR_THRESHOLD "Threshold" +#define KEY_MEMORY_MONITOR_INTERVAL "Interval" + struct memory_status_s { char *low_key; int low_value; @@ -43,7 +47,13 @@ struct memory_status_s { int normal_value; }; +struct memory_monitor_s { + int threshold; + int interval; +}; + static struct memory_status_s __memory_status; +static struct memory_monitor_s __memory_monitor; const char *_config_get_string_value(config_type_e type) { @@ -76,6 +86,12 @@ int _config_get_int_value(config_type_e type) case CONFIG_TYPE_MEMORY_STATUS_NORMAL_VALUE: value = __memory_status.normal_value; break; + case CONFIG_TYPE_MEMORY_MONITOR_THRESHOLD: + value = __memory_monitor.threshold; + break; + case CONFIG_TYPE_MEMORY_MONITOR_INTERVAL: + value = __memory_monitor.interval; + break; default: _E("Unknown type"); value = INT_MIN; @@ -102,31 +118,27 @@ static int __get_int_value(dictionary *d, const char *tag, return iniparser_getint(d, buf, INT_MIN); } -int _config_init(void) +static void __memory_status_init(void) { - dictionary *d; - char *val; - const char *str; - int ret; - - _D("config init"); - __memory_status.low_key = strdup(VCONFKEY_SYSMAN_LOW_MEMORY); __memory_status.low_value = VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING; __memory_status.normal_key = strdup(VCONFKEY_SYSMAN_LOW_MEMORY); __memory_status.normal_value = VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL; +} - ret = access(PATH_LAUNCHPAD_CONF, F_OK); - if (ret != 0) { - _W("The file doesn't exist. errno(%d)", errno); - return 0; - } +static void __memory_status_fini(void) +{ + __memory_status.normal_value = 0; + free(__memory_status.normal_key); + __memory_status.low_value = 0; + free(__memory_status.low_key); +} - d = iniparser_load(PATH_LAUNCHPAD_CONF); - if (!d) { - _E("Failed to load the config file"); - return -1; - } +static void __memory_status_set(dictionary *d) +{ + const char *str; + char *val; + int ret; str = __get_string_value(d, TAG_MEMORY_STATUS, KEY_MEMORY_STATUS_LOW_KEY); @@ -163,6 +175,63 @@ int _config_init(void) __memory_status.low_value, __memory_status.normal_key, __memory_status.normal_value); +} + +static void __memory_monitor_init(void) +{ + __memory_monitor.threshold = 80; /* 80 % */ + __memory_monitor.interval = 5000; /* 5 seconds */ +} + +static void __memory_monitor_fini(void) +{ + __memory_monitor.threshold = 0; + __memory_monitor.interval = 0; +} + +static void __memory_monitor_set(dictionary *d) +{ + int ret; + + ret = __get_int_value(d, TAG_MEMORY_MONITOR, + KEY_MEMORY_MONITOR_THRESHOLD); + if (ret != INT_MIN) + __memory_monitor.threshold = ret; + + ret = __get_int_value(d, TAG_MEMORY_MONITOR, + KEY_MEMORY_MONITOR_INTERVAL); + if (ret != INT_MIN) + __memory_monitor.interval = ret; + + _W("Memory Monitor Threshold(%d), Interval(%d)", + __memory_monitor.threshold, + __memory_monitor.interval); +} + +int _config_init(void) +{ + dictionary *d; + int ret; + + _D("config init"); + + __memory_status_init(); + __memory_monitor_init(); + + ret = access(PATH_LAUNCHPAD_CONF, F_OK); + if (ret != 0) { + _W("The file doesn't exist. errno(%d)", errno); + return 0; + } + + d = iniparser_load(PATH_LAUNCHPAD_CONF); + if (!d) { + _E("Failed to load the config file"); + return -1; + } + + __memory_status_set(d); + __memory_monitor_set(d); iniparser_freedict(d); @@ -173,6 +242,6 @@ void _config_fini(void) { _D("config fini"); - free(__memory_status.normal_key); - free(__memory_status.low_key); + __memory_monitor_fini(); + __memory_status_fini(); } diff --git a/src/launchpad/src/launchpad_memory_monitor.c b/src/launchpad/src/launchpad_memory_monitor.c new file mode 100644 index 0000000..c6e0d2c --- /dev/null +++ b/src/launchpad/src/launchpad_memory_monitor.c @@ -0,0 +1,157 @@ +/* + * 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 "launchpad_config.h" +#include "launchpad_memory_monitor.h" +#include "launchpad_proc.h" +#include "log_private.h" + +#define INTERVAL_BASE_RATE 0.15f + +struct memory_monitor_s { + unsigned int threshold; + unsigned int prev_used_ratio; + unsigned int base_interval; + unsigned int interval; + guint tag; + memory_monitor_cb callback; + void *user_data; +}; + +static struct memory_monitor_s __monitor; + +static void __memory_monitor_start(void); + +static gboolean __memory_check_cb(gpointer data) +{ + unsigned int mem_used_ratio = 0; + int ret; + + __monitor.tag = 0; + ret = _proc_get_mem_used_ratio(&mem_used_ratio); + if (ret != 0) { + _E("Failed to get mem used ratio"); + __monitor.interval = __monitor.base_interval; + __memory_monitor_start(); + return G_SOURCE_REMOVE; + } + + if (__monitor.callback) { + ret = __monitor.callback(mem_used_ratio > __monitor.threshold, + __monitor.user_data); + if (ret == 0) { + _W("Reset interval"); + __monitor.interval = __monitor.base_interval; + } + } + + _W("previous used ratio(%u), current used ratio(%u)", + __monitor.prev_used_ratio, mem_used_ratio); + + __monitor.prev_used_ratio = mem_used_ratio; + __memory_monitor_start(); + + return G_SOURCE_REMOVE; +} + +static void __memory_monitor_stop(void) +{ + if (!__monitor.tag) + return; + + g_source_remove(__monitor.tag); + __monitor.tag = 0; +} + +static void __memory_monitor_start(void) +{ + if (__monitor.tag) + return; + + __monitor.tag = g_timeout_add(__monitor.interval, + __memory_check_cb, NULL); + + __monitor.interval += __monitor.interval * INTERVAL_BASE_RATE; +} + +int _memory_monitor_reset_timer(void) +{ + _W("Reset"); + __monitor.interval = __monitor.base_interval; + + __memory_monitor_stop(); + __memory_monitor_start(); + + return 0; +} + +bool _memory_monitor_is_low_memory(void) +{ + unsigned int mem_used_ratio = 0; + + _proc_get_mem_used_ratio(&mem_used_ratio); + __monitor.prev_used_ratio = mem_used_ratio; + + if (mem_used_ratio > __monitor.threshold) + return true; + + return false; +} + +int _memory_monitor_set_event_cb(memory_monitor_cb callback, void *user_data) +{ + __monitor.callback = callback; + __monitor.user_data = user_data; + + return 0; +} + +int _memory_monitor_init(void) +{ + int ret; + + _W("MEMORY_MONITOR_INIT"); + + __monitor.threshold = _config_get_int_value( + CONFIG_TYPE_MEMORY_MONITOR_THRESHOLD); + __monitor.base_interval = _config_get_int_value( + CONFIG_TYPE_MEMORY_MONITOR_INTERVAL); + __monitor.interval = __monitor.base_interval; + + ret = _proc_get_mem_used_ratio(&__monitor.prev_used_ratio); + if (ret != 0) { + _E("Failed to get mem used ratio. error(%d)", ret); + return ret; + } + + __memory_monitor_start(); + + return 0; +} + +void _memory_monitor_fini(void) +{ + _W("MEMORY_MONITOR_FINI"); + + __memory_monitor_stop(); +} diff --git a/src/launchpad/src/launchpad_proc.c b/src/launchpad/src/launchpad_proc.c new file mode 100644 index 0000000..daad003 --- /dev/null +++ b/src/launchpad/src/launchpad_proc.c @@ -0,0 +1,147 @@ +/* + * 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 "launchpad_proc.h" +#include "log_private.h" + +#define auto_ptr(x) __attribute__ ((__cleanup__(x))) + +static unsigned int __convert_string(const char *str) +{ + while (*str < '0' || *str > '9') + str++; + + return atoi(str); +} + +static int __open_file(const char *file, FILE **fp) +{ + int ret; + + *fp = fopen(file, "r"); + if (!*fp) { + ret = -errno; + _E("Failed to open %s. errno(%d)", file, errno); + return ret; + } + + return 0; +} + +static void __close_file(FILE **fp) +{ + if (!fp || !*fp) + return; + + fclose(*fp); +} + +int _proc_get_mem_used_ratio(unsigned int *mem_used_ratio) +{ + auto_ptr(__close_file) FILE *fp = NULL; + char buf[LINE_MAX]; + char *str; + unsigned int mem_free = 0; + unsigned int mem_total = 0; + unsigned int mem_available = 0; + unsigned int cached = 0; + unsigned int used; + unsigned int used_ratio; + int ret; + + if (!mem_used_ratio) { + _E("Invalid parameter"); + return -EINVAL; + } + + ret = __open_file("/proc/meminfo", &fp); + if (ret != 0) + return ret; + + while (fgets(buf, sizeof(buf), fp) != NULL) { + if ((str = strstr(buf, "MemTotal:"))) { + str += strlen("MemTotal:"); + mem_total = __convert_string(str); + } else if ((str = strstr(buf, "MemFree:"))) { + str += strlen("MemFree:"); + mem_free = __convert_string(str); + } else if ((str = strstr(buf, "MemAvailable:"))) { + str += strlen("MemAvailable:"); + mem_available = __convert_string(str); + } else if ((str = strstr(buf, "Cached:")) && + !strstr(buf, "Swap")) { + str += strlen("Cached:"); + cached = atoi(str); + break; + } + } + + if (mem_total == 0) { + _E("Failed to get total memory size"); + return -1; + } + + if (mem_available == 0) + mem_available = mem_free + cached; + + used = mem_total - mem_available; + used_ratio = used * 100 / mem_total; + _I("memory used ratio: %u %%", used_ratio); + + *mem_used_ratio = used_ratio; + + return 0; +} + +int _proc_get_mem_pss(int pid, unsigned int *mem_pss) +{ + auto_ptr(__close_file) FILE *fp = NULL; + char path[PATH_MAX]; + char buf[LINE_MAX]; + unsigned int pss = 0; + unsigned int total_pss = 0; + int ret; + + if (pid < 1 || !mem_pss) { + _E("Invalid parameter"); + return -EINVAL; + } + + snprintf(path, sizeof(path), "/proc/%d/smaps", pid); + ret = __open_file(path, &fp); + if (ret != 0) + return ret; + + while (fgets(buf, sizeof(buf), fp) != NULL) { + if (sscanf(buf, "Pss: %d kB", &pss) == 1) { + total_pss += pss; + pss = 0; + } + } + + *mem_pss = total_pss; + _I("[%d] PSS: %u kB", pid, total_pss); + + return 0; +} -- 2.7.4 From bd2006221b4336fd527a0a09984f1c35e6034942 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 25 Feb 2020 09:43:15 +0900 Subject: [PATCH 12/16] Add memory management feature on app-defined-loader If PSS of app-defined-loader process is over the threshold, app-defined-loader process stops loading the libraries. The platform developer can change the threshold using app-defined-loader.conf file. Change-Id: Id2476dbcfbce5d3c272028a883ec6a509cfa310f Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 1 + src/CMakeLists.txt | 2 +- .../CMakeLists.txt | 13 ++- .../conf/app-defined-loader.conf.in | 2 + .../src/app-defined-loader.cc} | 96 ++++++++++++++-------- src/app-defined-loader/src/config.cc | 36 ++++++++ src/app-defined-loader/src/config.hh | 40 +++++++++ src/app-defined-loader/src/log-private.hh | 47 +++++++++++ src/app-defined-loader/src/proc.cc | 50 +++++++++++ src/app-defined-loader/src/proc.hh | 37 +++++++++ 10 files changed, 284 insertions(+), 40 deletions(-) rename src/{app_defined_loader => app-defined-loader}/CMakeLists.txt (89%) create mode 100644 src/app-defined-loader/conf/app-defined-loader.conf.in rename src/{app_defined_loader/src/app_defined_loader.cc => app-defined-loader/src/app-defined-loader.cc} (79%) create mode 100644 src/app-defined-loader/src/config.cc create mode 100644 src/app-defined-loader/src/config.hh create mode 100644 src/app-defined-loader/src/log-private.hh create mode 100644 src/app-defined-loader/src/proc.cc create mode 100644 src/app-defined-loader/src/proc.hh diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 5935833..581b221 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -172,6 +172,7 @@ ln -sf ../launchpad-process-pool.service %{buildroot}%{_unitdir_user}/basic.targ %files -n app-defined-loader %manifest app-defined-loader.manifest %license LICENSE +%{_prefix}/share/aul/app-defined-loader.conf %{_bindir}/app-defined-loader %files -n liblaunchpad diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dbab7f3..352038e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8) ADD_SUBDIRECTORY(launchpad) ADD_SUBDIRECTORY(lib) ADD_SUBDIRECTORY(loader) -ADD_SUBDIRECTORY(app_defined_loader) +ADD_SUBDIRECTORY(app-defined-loader) ADD_SUBDIRECTORY(hydra) ADD_SUBDIRECTORY(parser) diff --git a/src/app_defined_loader/CMakeLists.txt b/src/app-defined-loader/CMakeLists.txt similarity index 89% rename from src/app_defined_loader/CMakeLists.txt rename to src/app-defined-loader/CMakeLists.txt index b0f869e..3410782 100644 --- a/src/app_defined_loader/CMakeLists.txt +++ b/src/app-defined-loader/CMakeLists.txt @@ -4,13 +4,14 @@ SET(APP_DEFINED_LOADER "app-defined-loader") INCLUDE(FindPkgConfig) PKG_CHECK_MODULES(APP_DEFINED_LOADER_PKGS REQUIRED + aul + bundle + dbus-1 dlog ecore ecore-core - bundle - aul gio-2.0 - dbus-1 + iniparser libsystemd ) @@ -66,4 +67,8 @@ SET_TARGET_PROPERTIES(${APP_DEFINED_LOADER} PROPERTIES COMPILE_FLAGS ${EXTRA_CFL SET_TARGET_PROPERTIES(${APP_DEFINED_LOADER} PROPERTIES SKIP_BUILD_RPATH TRUE ) # remove rpath option that is automatically generated by cmake. -INSTALL(TARGETS ${APP_DEFINED_LOADER} DESTINATION bin) \ No newline at end of file +INSTALL(TARGETS ${APP_DEFINED_LOADER} DESTINATION bin) + +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/conf/app-defined-loader.conf.in + ${CMAKE_CURRENT_SOURCE_DIR}/conf/app-defined-loader.conf @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/app-defined-loader.conf DESTINATION share/aul) diff --git a/src/app-defined-loader/conf/app-defined-loader.conf.in b/src/app-defined-loader/conf/app-defined-loader.conf.in new file mode 100644 index 0000000..8381685 --- /dev/null +++ b/src/app-defined-loader/conf/app-defined-loader.conf.in @@ -0,0 +1,2 @@ +[Memory] +Threshold=25600 diff --git a/src/app_defined_loader/src/app_defined_loader.cc b/src/app-defined-loader/src/app-defined-loader.cc similarity index 79% rename from src/app_defined_loader/src/app_defined_loader.cc rename to src/app-defined-loader/src/app-defined-loader.cc index 39ba7d1..873f52b 100644 --- a/src/app_defined_loader/src/app_defined_loader.cc +++ b/src/app-defined-loader/src/app-defined-loader.cc @@ -14,11 +14,12 @@ * limitations under the License. */ -#include -#include -#include #include #include +#include +#include +#include +#include #include #include @@ -26,15 +27,14 @@ #include #include +#include "key.h" +#include "launchpad.h" #include "launchpad_common.h" #include "launchpad_types.h" -#include "launchpad.h" -#include "key.h" -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "APP_DEFINED_LOADER" +#include "config.hh" +#include "log-private.hh" +#include "proc.hh" #ifndef PR_TASK_PERF_USER_TRACE #define PR_TASK_PERF_USER_TRACE 666 @@ -44,35 +44,49 @@ #define C_EXPORT extern "C" __attribute__((visibility("default"))) #endif -using namespace tizen_base; -using namespace std; 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 + class AppDefinedLoader { public: AppDefinedLoader(int argc, char** argv) : argc_(argc), argv_(argv) { - lifecycle_cb_ = shared_ptr(new loader_lifecycle_callback_s()); + lifecycle_cb_ = std::shared_ptr( + new loader_lifecycle_callback_s()); lifecycle_cb_->create = OnCreate; lifecycle_cb_->launch = OnLaunch; lifecycle_cb_->terminate = OnTerminate; - adapter_ = shared_ptr(new loader_adapter_s()); + adapter_ = std::shared_ptr(new loader_adapter_s()); adapter_->loop_begin = OnLoopBegin; adapter_->loop_quit = OnLoopQuit; adapter_->add_fd = OnAddFd; adapter_->remove_fd = OnRemoveFd; + + proc_ = std::unique_ptr(new Proc(getpid())); + + Config conf(PATH_CONF); + int threshold = conf.GetIntValue(SECTION_MEMORY, KEY_THRESHOLD); + if (threshold > 0) { + threshold_ = static_cast(threshold); + } else { + _W("Failed to get threshold"); + } } ~AppDefinedLoader() { _W("app defined loader destroyed"); } - shared_ptr GetLifeCycle() { + std::shared_ptr GetLifeCycle() { return lifecycle_cb_; } - shared_ptr GetAdapter() { + std::shared_ptr GetAdapter() { return adapter_; } @@ -109,10 +123,11 @@ class AppDefinedLoader { } private: - static void PreloadLib(Bundle data) { - vector so_array = data.GetStringArray("preload"); + void PreloadLib(tizen_base::Bundle data) { + std::vector so_array = data.GetStringArray("preload"); if (so_array.size() == 0) return; + for (auto& i : so_array) { if (i.empty()) continue; @@ -121,14 +136,20 @@ class AppDefinedLoader { _E("fail to load : %s, err : %s", i.c_str(), dlerror()); else _D("preload %s# - handle : %p", i.c_str(), handle); + + uint32_t pss = proc_->GetPss(); + if (pss > threshold_) { + _W("Pss(%u) is over threshold(%u)", pss, threshold_); + break; + } } } static void OnCreate(bundle *extra, int type, void *user_data) { _I("on create"); AppDefinedLoader* loader = (AppDefinedLoader*)user_data; - Bundle ex = Bundle(extra, false, false); - string loader_type = ex.GetString(KEY_LOADER_TYPE); + tizen_base::Bundle ex = tizen_base::Bundle(extra, false, false); + std::string loader_type = ex.GetString(KEY_LOADER_TYPE); if (loader_type.empty()) { _E("No loader type"); return; @@ -147,7 +168,8 @@ class AppDefinedLoader { } static int OnLaunch(int argc, char **argv, const char *app_path, - const char *appid, const char *pkgid, const char *pkg_type, void *user_data) { + const char *appid, const char *pkgid, const char *pkg_type, + void *user_data) { _I("on launch"); AppDefinedLoader* loader = (AppDefinedLoader*)user_data; if (!loader->IsPriorityChangeEnabled()) @@ -157,19 +179,20 @@ class AppDefinedLoader { if (kb == nullptr) return 0; - Bundle data(kb, false, false); - string high_priority = data.GetString(AUL_K_HIGHPRIORITY); + tizen_base::Bundle data(kb, false, false); + std::string high_priority = data.GetString(AUL_K_HIGHPRIORITY); if (high_priority == "true") launchpad_loader_set_priority(-12); data.Delete(AUL_K_HIGHPRIORITY); return 0; } - void DoExec(string libdir) { + void DoExec(std::string libdir) { _I("do exec"); char err_str[MAX_LOCAL_BUFSZ]; if (access(argv_[LOADER_ARG_PATH], F_OK | R_OK)) { - SECURE_LOGE("access() failed for file: \"%s\", error: %d (%s)", argv_[LOADER_ARG_PATH], errno, + SECURE_LOGE("access() failed for file: \"%s\", error: %d (%s)", + argv_[LOADER_ARG_PATH], errno, strerror_r(errno, err_str, sizeof(err_str))); } else { SECURE_LOGD("[candidate] Exec application (%s)", @@ -187,9 +210,10 @@ class AppDefinedLoader { } } - int DoDlOpen(bool restore, string old_cwd, string libdir) { + int DoDlOpen(bool restore, std::string old_cwd, std::string libdir) { _I("do dlopen"); - string hwc_message = "" + 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()); void* handle = dlopen(argv_[LOADER_ARG_PATH], RTLD_LAZY | RTLD_GLOBAL | RTLD_NODELETE); @@ -199,7 +223,7 @@ class AppDefinedLoader { return -1; } - hwc_message = "" + 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())) @@ -218,7 +242,8 @@ class AppDefinedLoader { } static int OnTerminate(int argc, char **argv, void *user_data) { - SECURE_LOGD("[candidate] Launch real application (%s)", argv[LOADER_ARG_PATH]); + SECURE_LOGD("[candidate] Launch real application (%s)", + argv[LOADER_ARG_PATH]); char old_cwd[PATH_MAX] = {0, }; AppDefinedLoader* loader = (AppDefinedLoader*)user_data; if (getcwd(old_cwd, sizeof(old_cwd)) == nullptr) { @@ -237,7 +262,7 @@ class AppDefinedLoader { _E("failed to chdir: %d", errno); else restore = true; - string libdir_str = string(libdir); + std::string libdir_str = std::string(libdir); free(libdir); return loader->DoDlOpen(restore, old_cwd, libdir_str); } @@ -302,20 +327,21 @@ class AppDefinedLoader { } private: - shared_ptr lifecycle_cb_ = nullptr; - shared_ptr adapter_ = nullptr; + std::shared_ptr lifecycle_cb_ = nullptr; + std::shared_ptr adapter_ = nullptr; bool loader_priority_enabled_ = false; bool priority_change_enabled_ = false; - loader_receiver_cb receiver_cb_; + loader_receiver_cb receiver_cb_ = nullptr; Ecore_Fd_Handler* fd_handler_ = nullptr; + std::unique_ptr proc_; + uint32_t threshold_ = DEFAULT_THRESHOLD; int argc_; char** argv_; }; } -C_EXPORT int main(int argc, char **argv) -{ +C_EXPORT int main(int argc, char **argv) { launchpad::AppDefinedLoader loader(argc, argv); #ifdef TIZEN_FEATURE_LOADER_PRIORITY @@ -327,4 +353,4 @@ C_EXPORT int main(int argc, char **argv) return launchpad_loader_main(argc, argv, loader.GetLifeCycle().get(), loader.GetAdapter().get(), &loader); -} \ No newline at end of file +} diff --git a/src/app-defined-loader/src/config.cc b/src/app-defined-loader/src/config.cc new file mode 100644 index 0000000..2a03202 --- /dev/null +++ b/src/app-defined-loader/src/config.cc @@ -0,0 +1,36 @@ +/* + * 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. + */ + +#include + +#include "config.hh" + +namespace launchpad { + +Config::Config(const std::string& path) + : d_(iniparser_load(path.c_str()), iniparser_freedict) { +} + +Config::~Config() = default; + +int Config::GetIntValue(const std::string& section, + const std::string& key) const { + std::string section_key = section + ":" + key; + + return iniparser_getint(d_.get(), section_key.c_str(), INT_MIN); +} + +} // namespace launchpad diff --git a/src/app-defined-loader/src/config.hh b/src/app-defined-loader/src/config.hh new file mode 100644 index 0000000..3e12bdf --- /dev/null +++ b/src/app-defined-loader/src/config.hh @@ -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 CONFIG_HH_ +#define CONFIG_HH_ + +#include + +#include + +namespace launchpad { + +class Config { + public: + Config(const std::string& path); + virtual ~Config(); + + public: + int GetIntValue(const std::string& section, const std::string& key) const; + + private: + std::unique_ptr d_; +}; + +} // namespace launchpad + +#endif // CONFIG_HH_ diff --git a/src/app-defined-loader/src/log-private.hh b/src/app-defined-loader/src/log-private.hh new file mode 100644 index 0000000..ee448ce --- /dev/null +++ b/src/app-defined-loader/src/log-private.hh @@ -0,0 +1,47 @@ +/* + * 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 LOG_PRIVATE_HH_ +#define LOG_PRIVATE_HH_ + +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "APP_DEFINED_LOADER" + +#ifdef _E +#undef _E +#endif +#define _E LOGE + +#ifdef _W +#undef _W +#endif +#define _W LOGW + +#ifdef _I +#undef _I +#endif +#define _I LOGI + +#ifdef _D +#undef _D +#endif +#define _D LOGD + +#endif // LOG_PRIVATE_HH_ diff --git a/src/app-defined-loader/src/proc.cc b/src/app-defined-loader/src/proc.cc new file mode 100644 index 0000000..9719cea --- /dev/null +++ b/src/app-defined-loader/src/proc.cc @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#include +#include + +#include "log-private.hh" +#include "proc.hh" + +namespace launchpad { + +Proc::Proc(int pid) : pid_(pid) { +} + +Proc::~Proc() = default; + +uint32_t Proc::GetPss() const { + uint32_t total_pss = 0; + std::string path = "/proc/" + std::to_string(pid_) + "/smaps"; + std::ifstream stream(path); + if (stream.is_open()) { + std::string line; + while (std::getline(stream, line)) { + uint32_t pss = 0; + if (std::sscanf(line.c_str(), "Pss: %u kB", &pss) == 1) { + total_pss += pss; + pss = 0; + } + } + stream.close(); + } + + _I("Pss: %u kB", total_pss); + return total_pss; +} + +} // namespace launchpad diff --git a/src/app-defined-loader/src/proc.hh b/src/app-defined-loader/src/proc.hh new file mode 100644 index 0000000..4ffb1a5 --- /dev/null +++ b/src/app-defined-loader/src/proc.hh @@ -0,0 +1,37 @@ +/* + * 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 PROC_HH_ +#define PROC_HH_ + +#include + +namespace launchpad { + +class Proc { + public: + Proc(int pid); + virtual ~Proc(); + + uint32_t GetPss() const; + + private: + int pid_; +}; + +} // namespace launchpad + +#endif // PROC_HH_ -- 2.7.4 From 37df24dab41b16c697e3e28d54b171d0e218c30e Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 25 Feb 2020 10:12:43 +0900 Subject: [PATCH 13/16] Fix memory management feature Change-Id: Icff15a3b5e9b16e3e3e0572a1cbdb8daa673e2b9 Signed-off-by: Hwankyu Jhun --- src/launchpad/src/launchpad.c | 15 ++++++++++----- src/launchpad/src/launchpad_memory_monitor.c | 8 ++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c index 487da6e..4d8bbd3 100644 --- a/src/launchpad/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -1958,8 +1958,12 @@ static void __update_slot_state(candidate_process_context_t *cpc, int method, __deactivate_slot(cpc); break; case METHOD_AVAILABLE_MEMORY: + if (force || cpc->activation_method & method) + __activate_slot(cpc); + break; case METHOD_REQUEST: - __update_slot_state(cpc, METHOD_OUT_OF_MEMORY, force); + if (force || cpc->activation_method & method) + __update_slot_state(cpc, METHOD_OUT_OF_MEMORY, force); break; default: __activate_slot(cpc); @@ -2805,16 +2809,17 @@ static int __memory_monitor_cb(bool low_memory, void *user_data) { candidate_process_context_t *cpc; + _W("low memory(%s)", low_memory ? "true" : "false"); cpc = __get_running_slot(false); if (!cpc && low_memory) return -1; - __update_slots_pss(); + if (low_memory) { + __update_slots_pss(); - candidate_slot_list = g_list_sort(candidate_slot_list, __compare_slot); + candidate_slot_list = g_list_sort(candidate_slot_list, + __compare_slot); - _W("low memory(%s)", low_memory ? "true" : "false"); - if (low_memory) { do { __pause_last_running_slot(false); diff --git a/src/launchpad/src/launchpad_memory_monitor.c b/src/launchpad/src/launchpad_memory_monitor.c index c6e0d2c..dacf3ab 100644 --- a/src/launchpad/src/launchpad_memory_monitor.c +++ b/src/launchpad/src/launchpad_memory_monitor.c @@ -57,15 +57,11 @@ static gboolean __memory_check_cb(gpointer data) } if (__monitor.callback) { - ret = __monitor.callback(mem_used_ratio > __monitor.threshold, + __monitor.callback(mem_used_ratio > __monitor.threshold, __monitor.user_data); - if (ret == 0) { - _W("Reset interval"); - __monitor.interval = __monitor.base_interval; - } } - _W("previous used ratio(%u), current used ratio(%u)", + _D("previous used ratio(%u), current used ratio(%u)", __monitor.prev_used_ratio, mem_used_ratio); __monitor.prev_used_ratio = mem_used_ratio; -- 2.7.4 From acc6be19d391a3d71c63ddbb8e4fa9b91aa91dfe Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 25 Feb 2020 10:46:17 +0900 Subject: [PATCH 14/16] Adjust coding style - Uses static_cast<...>(...) instead of C-style cast - Uses left alignment style - Adds C++ coding style check tool Change-Id: I5b0a7817fe9f523027b1a8ee4c2fe4eb5b05d236 Signed-off-by: Hwankyu Jhun --- src/app-defined-loader/src/app-defined-loader.cc | 44 +++++++++++------------- tools/check-coding-style | 28 +++++++++++++++ 2 files changed, 48 insertions(+), 24 deletions(-) create mode 100755 tools/check-coding-style diff --git a/src/app-defined-loader/src/app-defined-loader.cc b/src/app-defined-loader/src/app-defined-loader.cc index 873f52b..38ffb94 100644 --- a/src/app-defined-loader/src/app-defined-loader.cc +++ b/src/app-defined-loader/src/app-defined-loader.cc @@ -40,10 +40,6 @@ #define PR_TASK_PERF_USER_TRACE 666 #endif -#ifndef C_EXPORT -#define C_EXPORT extern "C" __attribute__((visibility("default"))) -#endif - namespace launchpad { static const char PATH_CONF[] = "/usr/share/aul/app-defined-loader.conf"; @@ -145,9 +141,9 @@ class AppDefinedLoader { } } - static void OnCreate(bundle *extra, int type, void *user_data) { + static void OnCreate(bundle* extra, int type, void* user_data) { _I("on create"); - AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + AppDefinedLoader* loader = static_cast(user_data); tizen_base::Bundle ex = tizen_base::Bundle(extra, false, false); std::string loader_type = ex.GetString(KEY_LOADER_TYPE); if (loader_type.empty()) { @@ -167,15 +163,15 @@ class AppDefinedLoader { setenv("AUL_HWACC", "hw", 1); } - static int OnLaunch(int argc, char **argv, const char *app_path, - const char *appid, const char *pkgid, const char *pkg_type, - void *user_data) { + static int OnLaunch(int argc, char** argv, const char* app_path, + const char* appid, const char* pkgid, const char* pkg_type, + void* user_data) { _I("on launch"); - AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + AppDefinedLoader* loader = static_cast(user_data); if (!loader->IsPriorityChangeEnabled()) return 0; - bundle *kb = launchpad_loader_get_bundle(); + bundle* kb = launchpad_loader_get_bundle(); if (kb == nullptr) return 0; @@ -229,7 +225,8 @@ class AppDefinedLoader { if (restore && chdir(old_cwd.c_str())) _E("failed to chdir: %d", errno); - void* dl_main = dlsym(handle, "main"); + auto dl_main = reinterpret_cast( + dlsym(handle, "main")); if (dl_main == nullptr) { _E("dlsym not founded(%s). Please export 'main' function", dlerror()); dlclose(handle); @@ -238,14 +235,14 @@ class AppDefinedLoader { } _I("call main"); - return ((int (*)(int, char**))dl_main)(argc_, argv_); + return dl_main(argc_, argv_); } - static int OnTerminate(int argc, char **argv, void *user_data) { + static int OnTerminate(int argc, char** argv, void* user_data) { SECURE_LOGD("[candidate] Launch real application (%s)", argv[LOADER_ARG_PATH]); char old_cwd[PATH_MAX] = {0, }; - AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + AppDefinedLoader* loader = static_cast(user_data); if (getcwd(old_cwd, sizeof(old_cwd)) == nullptr) { loader->DoDlOpen(false, old_cwd, ""); } else { @@ -280,9 +277,8 @@ class AppDefinedLoader { ecore_main_loop_quit(); } - static void OnAddFd(void* user_data, int fd, - loader_receiver_cb receiver) { - AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + static void OnAddFd(void* user_data, int fd, loader_receiver_cb receiver) { + AppDefinedLoader* loader = static_cast(user_data); Ecore_Fd_Handler* handler = ecore_main_fd_handler_add(fd, (Ecore_Fd_Handler_Flags)(ECORE_FD_READ | ECORE_FD_ERROR), FdHandler, loader, nullptr, nullptr); @@ -296,9 +292,9 @@ class AppDefinedLoader { loader->SetReceiver(receiver); } - static Eina_Bool FdHandler(void *user_data, Ecore_Fd_Handler *handler) { + static Eina_Bool FdHandler(void* user_data, Ecore_Fd_Handler* handler) { _I("fd handler"); - AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + AppDefinedLoader* loader = static_cast(user_data); int fd = ecore_main_fd_handler_fd_get(handler); if (fd == -1) { _E("[candidate] ECORE_FD_GET"); @@ -316,9 +312,9 @@ class AppDefinedLoader { return ECORE_CALLBACK_CANCEL; } - static void OnRemoveFd(void *user_data, int fd) { + static void OnRemoveFd(void* user_data, int fd) { _I("remove fd"); - AppDefinedLoader* loader = (AppDefinedLoader*)user_data; + AppDefinedLoader* loader = static_cast(user_data); if (loader->GetFdHandler() == nullptr) return; ecore_main_fd_handler_del(loader->GetFdHandler()); @@ -339,9 +335,9 @@ class AppDefinedLoader { char** argv_; }; -} +} // namespace launchpad -C_EXPORT int main(int argc, char **argv) { +int main(int argc, char** argv) { launchpad::AppDefinedLoader loader(argc, argv); #ifdef TIZEN_FEATURE_LOADER_PRIORITY diff --git a/tools/check-coding-style b/tools/check-coding-style new file mode 100755 index 0000000..fd60481 --- /dev/null +++ b/tools/check-coding-style @@ -0,0 +1,28 @@ +#!/bin/bash +# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +if [ ! `which cpplint.py` ]; then + echo -e "\nPlease make sure cpplint.py is in your PATH. It is part of depot_tools inside Chromium repository." + exit 1 +fi + +OLDPWD=$PWD +BASE=`dirname $0` +cd $BASE/.. + +# filters +FILTERS="-readability/streams,-build/c++11" + +cpplint.py --root=src --filter="$FILTERS" $(find . \( -name '*.h' -o -name '*.cc' \) ) +RET=$? + +JS_RET_VAL=$? +cd $OLDPWD + +if [ "x$RET" == "x0" ]; then + exit 0 +else + exit 1 +fi -- 2.7.4 From 726fdb6eb52f6e78912e59823a96a7f2a38bc058 Mon Sep 17 00:00:00 2001 From: Jusung Son Date: Tue, 25 Feb 2020 11:30:47 +0900 Subject: [PATCH 15/16] Fix char overflow char type_str[0] = '0' + LAUNCHPAD_LOADER_TYPE_DYNAMIC = 48 + 100 = -108 Change-Id: Ifebba27e34d303fcdbaf5205471d39c91c1dbcbc Signed-off-by: Jusung Son --- src/launchpad/src/launchpad.c | 6 +++--- src/lib/src/launchpad_lib.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c index 4d8bbd3..3032e22 100644 --- a/src/launchpad/src/launchpad.c +++ b/src/launchpad/src/launchpad.c @@ -828,8 +828,8 @@ static int __hydra_send_launch_candidate_request(int fd) static int __prepare_candidate_process(int type, int loader_id) { int pid; - char type_str[2] = {0, }; - char loader_id_str[10] = {0, }; + char type_str[12] = {0, }; + char loader_id_str[12] = {0, }; char argbuf[LOADER_ARG_LEN]; char *argv[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL}; candidate_process_context_t *cpt = __find_slot(type, loader_id); @@ -847,8 +847,8 @@ static int __prepare_candidate_process(int type, int loader_id) cpt->last_exec_time = time(NULL); - type_str[0] = '0' + type; snprintf(loader_id_str, sizeof(loader_id_str), "%d", loader_id); + snprintf(type_str, sizeof(type_str), "%d", type); argv[LOADER_ARG_PATH] = cpt->loader_path; argv[LOADER_ARG_TYPE] = type_str; argv[LOADER_ARG_ID] = loader_id_str; diff --git a/src/lib/src/launchpad_lib.c b/src/lib/src/launchpad_lib.c index e2a75bc..45a59f9 100644 --- a/src/lib/src/launchpad_lib.c +++ b/src/lib/src/launchpad_lib.c @@ -405,7 +405,7 @@ API int launchpad_loader_main(int argc, char **argv, return -1; } - __loader_type = argv[LOADER_ARG_TYPE][0] - '0'; + __loader_type = atoi(argv[LOADER_ARG_TYPE]); if (__loader_type < 0 || __loader_type >= LAUNCHPAD_TYPE_MAX) { _E("invalid argument. (type: %d)", __loader_type); return -1; -- 2.7.4 From 4507b214c81c33177919383cb31fc3f8e1165aab Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 25 Feb 2020 13:27:50 +0900 Subject: [PATCH 16/16] Release version 0.13.0 Changes: - Add app_defined_loader - Support memory management feature - Add memory management feature on app-defined-loader - Fix memory management feature - Adjust coding style - Fix char overflow Change-Id: Ib77043876d29015c78253717c0a15ea90373b7b4 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 581b221..42fb613 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.12.1 +Version: 0.13.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4