The common library is implemented using C++ language.
Change-Id: I34759ccb4098af00bd484e77be6a63d67fb3c8dc
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
#include <stdio.h>
#include <sys/prctl.h>
#include <trust-anchor.h>
+#include <tzplatform_config.h>
#include <unistd.h>
#include <filesystem>
#include <aul_keys.hh>
#include <plugin.hh>
+#include <stdio.hh>
+#include <types.hh>
#include <util.hh>
#include "launchpad-process-pool/config.hh"
#include "launchpad-process-pool/log_private.hh"
#include "launchpad-process-pool/signal_manager.hh"
#include "launchpad-process-pool/user_tracer.hh"
-#include "lib/common/inc/launchpad_common.h"
-#include "lib/common/inc/launchpad_types.h"
namespace launchpad {
namespace fs = std::filesystem;
SECURE_LOGD("input argument %d : %s##", i, app_argv[i]);
}
- auto* lib_dir = _get_libdir(app_info_->GetAppPath().c_str());
- if (lib_dir != nullptr) {
- setenv("LD_LIBRARY_PATH", lib_dir, 1);
- free(lib_dir);
- }
+ auto lib_dir = Util::GetLibDirectory(app_info_);
+ if (!lib_dir.empty())
+ setenv("LD_LIBRARY_PATH", lib_dir.c_str(), 1);
- _close_all_fds();
- if (execv(app_argv[LOADER_ARG_PATH], app_argv) < 0) {
+ Util::CloseAllFds();
+ if (execv(app_argv[LoaderArg::Path], app_argv) < 0) {
char err_buf[1024];
fprintf(stderr, "Failed to exeucte a file. path: %s, errno: %d(%s)\n",
app_info_->GetAppPath().c_str(), errno,
}
int AppExecutor::StepEnableExternalPackage() {
- return _enable_external_pkg(app_info_->GetBundle().GetHandle(),
- app_info_->GetPkgId().c_str(),
- app_info_->IsGlobal() ? GLOBAL_USER : getuid());
+ return Util::EnableExternalPackage(app_info_);
}
int AppExecutor::StepEnableTrustAnchor() {
}
int AppExecutor::StepMountResDir() {
- return _mount_res_dir(app_info_->GetRootPath().c_str(),
- app_info_->GetBundle().GetHandle());
+ return Util::MountResourceDirectories(app_info_);
}
int AppExecutor::StepChangeMountNamespace() {
int AppExecutor::StepSetupStdio() {
if (app_info_->GetBundle().GetType(kAulSdk) == BUNDLE_TYPE_NONE)
- _setup_stdio(basename(const_cast<char*>(app_info_->GetAppPath().c_str())));
+ Stdio::Setup();
return 0;
}
}
int AppExecutor::StepWaitTepMount() {
- return _wait_tep_mount(app_info_->GetBundle().GetHandle());
+ return Util::WaitTepMount(app_info_);
}
int AppExecutor::StepPrepareAppSocketAndIdFile() {
if (app_info_->GetBundle().GetType(kAulSdk) != BUNDLE_TYPE_NONE)
return 0;
- if (_prepare_app_socket() < 0)
+ if (Util::PrepareAppSocket() < 0)
return -1;
- return _prepare_id_file();
+ return Util::PrepareAppIdFile(app_info_);
}
int AppExecutor::StepSendStartupSignal() {
- _send_cmd_to_amd(APP_STARTUP_SIGNAL);
+ Util::SendCmdToAmd(AmdCmd::AppStartupSignal);
return 0;
}
argv.insert(argv.end(), launcher_argv.begin(), launcher_argv.end());
auto exported_argv = b.Export();
- exported_argv[LOADER_ARG_PATH] = app_path;
+ exported_argv[LoaderArg::Path] = app_path;
if (!exported_argv.empty())
argv.insert(argv.end(), exported_argv.begin(), exported_argv.end());
#include <fstream>
#include <utility>
+#include <aul_keys.hh>
#include <exception.hh>
-#include "lib/common/inc/key.h"
-#include "lib/common/inc/launchpad_common.h"
+#include "launchpad-process-pool/log_private.hh"
namespace fs = std::filesystem;
}
void Debug::PrepareDebugger(const tizen_base::Bundle& b) {
- auto debugger = b.GetString(AUL_K_SDK);
+ auto debugger = b.GetString(kAulSdk);
if (debugger.empty())
return;
}
void Debug::CheckWebAppDebugging(const tizen_base::Bundle& b) {
- if (b.GetType(AUL_K_DEBUG) != BUNDLE_TYPE_NONE)
+ if (b.GetType(kAulDebug) != BUNDLE_TYPE_NONE)
setenv("TIZEN_DEBUGGING_PORT", "1", 1);
}
}
pid_t Debug::GetCallerPid(const tizen_base::Bundle& b) {
- auto pid_str = b.GetString(AUL_K_ORG_CALLER_PID);
+ auto pid_str = b.GetString(kAulOrgCallerPid);
if (pid_str.empty())
- pid_str = b.GetString(AUL_K_CALLER_PID);
+ pid_str = b.GetString(kAulCallerPid);
if (pid_str.empty())
return -1;
#include <sstream>
#include <utility>
+#include "launchpad-process-pool/log_private.hh"
#include "launchpad-process-pool/util.hh"
-#include "lib/common/inc/launchpad_common.h"
namespace launchpad {
namespace {
#include <cpu_boost_controller.hh>
#include <exception.hh>
#include <hydra_request.hh>
+#include <types.hh>
#include "launchpad-process-pool/log_private.hh"
-#include "lib/common/inc/launchpad_types.h"
namespace fs = std::filesystem;
void HydraLoaderContext::PrepareCandidateProcess() {
_W("Send launch request to hydra loader. fd(%d)", client_socket_->GetFd());
- HydraRequest request(LAUNCH_CANDIDATE, GetSchedPriority());
+ HydraRequest request(HydraCmd::LaunchCandidate, GetSchedPriority());
tizen_base::Parcel parcel;
parcel.WriteParcelable(request);
#include <util.hh>
+#include "launchpad-process-pool/log_private.hh"
#include "launchpad-process-pool/util.hh"
-#include "lib/common/inc/launchpad_common.h"
namespace launchpad {
namespace {
#include <exception.hh>
#include <executor.hh>
#include <procfs.hh>
+#include <types.hh>
#include <util.hh>
-#include "lib/common/inc/launchpad_common.h"
-#include "lib/common/inc/launchpad_plugin.h"
-#include "lib/common/inc/launchpad_types.h"
-
#include "launchpad-process-pool/config.hh"
#include "launchpad-process-pool/dbus.hh"
#include "launchpad-process-pool/debug.hh"
#include "launchpad-process-pool/loader_manager.hh"
#include "launchpad-process-pool/loader_executor.hh"
#include "launchpad-process-pool/log.hh"
+#include "launchpad-process-pool/log_private.hh"
#include "launchpad-process-pool/memory_monitor.hh"
#include "launchpad-process-pool/signal_manager.hh"
#include "launchpad-process-pool/tracer.hh"
loop_(g_main_loop_new(nullptr, FALSE)) {
LaunchpadArgs::GetInst().Set(argc_, argv_);
handlers_ = {
- { PAD_CMD_VISIBILITY,
+ { PadCmd::Visibility,
std::bind(&Launchpad::HandleVisibilityRequest, this,
std::placeholders::_1) },
- { PAD_CMD_ADD_LOADER,
+ { PadCmd::AddLoader,
std::bind(&Launchpad::HandleAddLoaderRequest, this,
std::placeholders::_1) },
- { PAD_CMD_REMOVE_LOADER,
+ { PadCmd::RemoveLoader,
std::bind(&Launchpad::HandleRemoveLoaderRequest, this,
std::placeholders::_1) },
- { PAD_CMD_MAKE_DEFAULT_SLOTS,
+ { PadCmd::MakeDefaultSlots,
std::bind(&Launchpad::HandleMakeDefaultSlotsRequest, this,
std::placeholders::_1) },
- { PAD_CMD_PREPARE_APP_DEFINED_LOADER,
+ { PadCmd::PrepareAppDefinedLoader,
std::bind(&Launchpad::HandlePrepareAppDefinedLoaderRequest, this,
std::placeholders::_1) },
- { PAD_CMD_DEMAND,
+ { PadCmd::Demand,
std::bind(&Launchpad::HandleDemandRequest, this,
std::placeholders::_1) },
- { PAD_CMD_PING,
+ { PadCmd::Ping,
std::bind(&Launchpad::HandlePingRequest, this,
std::placeholders::_1) },
- { PAD_CMD_UPDATE_APP_TYPE,
+ { PadCmd::UpdateAppType,
std::bind(&Launchpad::HandleUpdateAppTypeRequest, this,
std::placeholders::_1) },
- { PAD_CMD_CONNECT,
+ { PadCmd::Connect,
std::bind(&Launchpad::HandleConnectRequest, this,
std::placeholders::_1) },
- { PAD_CMD_LAUNCH,
+ { PadCmd::Launch,
std::bind(&Launchpad::HandleLaunchRequest, this,
std::placeholders::_1) },
};
LoaderManager::GetInst().SetEventListener(this);
launchpad::Debug::GetInst().Init();
- _send_cmd_to_amd(LAUNCHPAD_LAUNCH_SIGNAL);
+ Util::SendCmdToAmd(AmdCmd::LaunchpadLaunchSignal);
lang_config_.reset(new LanguageConfig());
region_format_config_.reset(new RegionFormatConfig());
lang_config_.reset();
pid_map_.clear();
- _send_cmd_to_amd(LAUNCHPAD_DEAD_SIGNAL);
+ Util::SendCmdToAmd(AmdCmd::LaunchpadDeadSignal);
Debug::GetInst().Dispose();
LoaderManager::GetInst().Dispose();
auto& comp_type = app_info->GetCompType();
if (comp_type == "svcapp") {
request->SetLoaderId(GetLoaderIdFromBundle(request->GetBundle()));
- if (request->GetLoaderId() > PAD_LOADER_ID_DYNAMIC_BASE) {
+ if (request->GetLoaderId() > PadLoaderId::DynamicBase) {
auto context = loader_manager.FindLoaderContext(LoaderType::Dynamic,
request->GetLoaderId());
if (context != nullptr && CanUseLoaderContext(context))
request->SetAvailableLoaderContext(std::move(context));
} else {
- request->SetLoaderId(PAD_LOADER_ID_DIRECT);
+ request->SetLoaderId(PadLoaderId::Direct);
}
} else if (comp_type == "widget" && app_info->GetAppType() == "webapp") {
- request->SetLoaderId(PAD_LOADER_ID_DIRECT);
+ request->SetLoaderId(PadLoaderId::Direct);
} else {
request->SetLoaderId(GetLoaderIdFromBundle(request->GetBundle()));
- if (request->GetLoaderId() <= PAD_LOADER_ID_STATIC) {
+ if (request->GetLoaderId() <= PadLoaderId::Static) {
auto context = loader_manager.FindAvailableLoaderContext(
app_info->GetHwacc(), app_info->GetAppType(),
app_info->GetLoaderName());
Launchpad::LaunchResult Launchpad::LaunchRequestDo(
std::shared_ptr<Request> request) {
auto loader_context = request->GetAvailableLoaderContext();
- if (request->GetLoaderId() == PAD_LOADER_ID_DIRECT ||
+ if (request->GetLoaderId() == PadLoaderId::Direct ||
loader_context == nullptr ||
launchpad::Debug::GetInst().CheckAsanApp(
request->GetAppInfo()->GetAppId())) {
_W("Launch %d type process. appid: %s",
static_cast<int>(loader_context->GetType()),
app_info->GetAppId().c_str());
- request->SetPid(loader_context->Deploy(app_info, request->GetAppPacket()));
+ request->SetPid(loader_context->Deploy(app_info));
return LaunchResult::Success;
}
}
void Launchpad::OnIOEventReceived(int fd, int condition) {
- struct ucred cr;
- int client_fd = -1;
- app_pkt_t* pkt = _accept_recv_pkt_raw(fd, &client_fd, &cr);
- if (pkt == nullptr)
- return;
-
- auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
- pkt, std::free);
- auto* kb = bundle_decode(pkt->data, pkt->len);
- if (kb == nullptr) {
- close(client_fd);
+ auto client_socket = socket_->Accept();
+ if (!client_socket) {
+ _E("Failed to accept the client request");
return;
}
- tizen_base::Bundle b(kb, false, true);
- auto request = std::make_shared<Request>(
- std::make_unique<ClientSocket>(client_fd), pkt_auto.release(),
- std::move(b));
- _W("cmd(%d), caller(%d)", request->GetCmd(), request->GetCallerPid());
- if (request->GetCallerUid() >= kRegularUidMin) {
- if (CheckCallerPermission(request->GetCallerPid()) < 0) {
- _E("Permission denied. pid(%d)", request->GetCallerPid());
- request->SendResult(-EPERM);
+ try {
+ auto request = std::make_shared<Request>(std::move(client_socket));
+ _W("cmd(%d), caller(%d)", request->GetCmd(), request->GetCallerPid());
+ if (request->GetCallerUid() >= kRegularUidMin) {
+ if (CheckCallerPermission(request->GetCallerPid()) < 0) {
+ _E("Permission denied. pid(%d)", request->GetCallerPid());
+ request->SendResult(-EPERM);
+ return;
+ }
+ }
+
+ auto found = handlers_.find(request->GetCmd());
+ if (found == handlers_.end()) {
+ _E("Unknown command: %d", request->GetCmd());
+ request->SendResult(-EINVAL);
return;
}
- }
- auto found = handlers_.find(request->GetCmd());
- if (found == handlers_.end()) {
- _E("Unknown command: %d", request->GetCmd());
- request->SendResult(-EINVAL);
- return;
+ auto method_handler = found->second;
+ method_handler(std::move(request));
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
}
-
- auto method_handler = found->second;
- method_handler(std::move(request));
}
void Launchpad::OnSigchldReceived(pid_t pid) {
#include <peer_credentials.hh>
#include <procfs.hh>
#include <util.hh>
+#include <types.hh>
#include "launchpad-process-pool/app_labels_monitor.hh"
#include "launchpad-process-pool/loader_executor.hh"
#include "launchpad-process-pool/log.hh"
+#include "launchpad-process-pool/log_private.hh"
#include "launchpad-process-pool/memory_monitor.hh"
#include "launchpad-process-pool/user_tracer.hh"
#include "launchpad-process-pool/util.hh"
-#include "lib/common/inc/key.h"
-#include "lib/common/inc/launchpad_common.h"
-#include "lib/common/inc/launchpad_types.h"
namespace fs = std::filesystem;
return pid_;
}
-pid_t LoaderContext::Deploy(const AppInfo* app_info, app_pkt_t* app_packet) {
+pid_t LoaderContext::Deploy(const AppInfo* app_info) {
Util::DeleteSocketPath(pid_, getuid());
tizen_base::Parcel parcel;
parcel.WriteParcelable(*app_info);
#include <io_channel.hh>
#include <server_socket.hh>
-#include "lib/common/inc/launchpad_common.h"
-
#include "launchpad-process-pool/cpu_checker.hh"
#include "launchpad-process-pool/loader_info.hh"
#include "launchpad-process-pool/launcher_info.hh"
virtual void Listen();
virtual void Dispose();
virtual pid_t Prepare();
- virtual pid_t Deploy(const AppInfo* app_info, app_pkt_t* request);
+ virtual pid_t Deploy(const AppInfo* app_info);
const std::string& GetLoaderName() const;
const std::string& GetLoaderPath() const;
#include <parcel.hh>
#include <sched_priority.hh>
+#include <stdio.hh>
+#include <types.hh>
+#include <util.hh>
#include "launchpad-process-pool/config.hh"
#include "launchpad-process-pool/log_private.hh"
#include "launchpad-process-pool/signal_manager.hh"
-#include "lib/common/inc/launchpad_common.h"
-#include "lib/common/inc/launchpad_types.h"
namespace launchpad {
namespace {
}
SignalManager::GetInst().UnblockSigchld();
- _close_all_fds();
- _setup_stdio(basename(loader_argv[LOADER_ARG_PATH]));
+ Util::CloseAllFds();
+ Stdio::Setup();
- if (execv(loader_argv[LOADER_ARG_PATH], loader_argv.data()) < 0) {
+ if (execv(loader_argv[LoaderArg::Path], loader_argv.data()) < 0) {
char err_buf[1024];
fprintf(stderr, "Failed to execute a file. path: %s, errno: %d:%s\n",
- loader_argv[LOADER_ARG_PATH], errno,
+ loader_argv[LoaderArg::Path], errno,
strerror_r(errno, err_buf, sizeof(err_buf)));
exit(EXIT_FAILURE);
}
std::vector<std::string> LoaderExecutor::CreateLoaderArgv(
const LoaderContext* loader_context) {
- std::string dummy(LOADER_ARG_LEN - 1, ' ');
- std::vector<std::string> argv(LOADER_ARG_DUMMY + 1);
- argv[LOADER_ARG_DUMMY] = std::move(dummy);
- argv[LOADER_ARG_PATH] = loader_context->GetLoaderPath();
- argv[LOADER_ARG_TYPE] = std::to_string(loader_context->GetType());
- argv[LOADER_ARG_ID] = std::to_string(loader_context->GetLoaderId());
- argv[LOADER_ARG_HYDRA] = loader_context->IsHydraMode() ? "1" : "0";
- argv[LOADER_ARG_EXTRA] = loader_context->GetLoaderExtra();
+ std::string dummy(kLoaderArgLength - 1, ' ');
+ std::vector<std::string> argv(LoaderArg::Dummy + 1);
+ argv[LoaderArg::Dummy] = std::move(dummy);
+ argv[LoaderArg::Path] = loader_context->GetLoaderPath();
+ argv[LoaderArg::Type] = std::to_string(loader_context->GetType());
+ argv[LoaderArg::Id] = std::to_string(loader_context->GetLoaderId());
+ argv[LoaderArg::Hydra] = loader_context->IsHydraMode() ? "1" : "0";
+ argv[LoaderArg::Extra] = loader_context->GetLoaderExtra();
return argv;
}
#include <utility>
#include <aul_keys.hh>
+#include <types.hh>
-#include "lib/common/inc/launchpad_common.h"
-
-#include "launchpad-process-pool/loader_context.hh"
#include "launchpad-process-pool/hydra_loader_context.hh"
+#include "launchpad-process-pool/loader_context.hh"
+#include "launchpad-process-pool/log_private.hh"
#include "launchpad-process-pool/user_tracer.hh"
namespace launchpad {
std::shared_ptr<LoaderContext> LoaderFactory::CreateLoaderContext(
LoaderInfoPtr info) {
auto app_types = GetAppTypeString(info);
- int loader_id = (info->GetExe() == "null") ? PAD_LOADER_ID_DIRECT :
- PAD_LOADER_ID_STATIC;
+ int loader_id = static_cast<int>((info->GetExe() == "null") ?
+ PadLoaderId::Direct : PadLoaderId::Static);
LoaderContext* context;
try {
if (info->IsHydraMode()) {
#include <memory>
#include <vector>
-#include "lib/common/inc/launchpad_types.h"
+#include <types.hh>
#include "launchpad-process-pool/loader_context.hh"
#include "launchpad-process-pool/loader_info.hh"
int MakeDynamicLoaderId();
private:
- int dynamic_loader_id_ = PAD_LOADER_ID_DYNAMIC_BASE;
+ int dynamic_loader_id_ = PadLoaderId::DynamicBase;
};
} // namespace launchpad
#include <sstream>
#include <utility>
+#include "launchpad-process-pool/log_private.hh"
#include "launchpad-process-pool/util.hh"
-#include "lib/common/inc/launchpad_common.h"
namespace fs = std::filesystem;
#include <unordered_map>
#include <vector>
+#include <types.hh>
+
#include "launchpad-process-pool/util.hh"
namespace launchpad {
-enum class LoaderType : int {
- None = 0,
- User = 1,
- Dynamic = 100,
-};
-
enum class LoaderMethod : int {
None = 0x0000,
Timeout = 0x0001,
#include <algorithm>
#include <utility>
+#include <types.hh>
+
#include "launchpad-process-pool/config.hh"
#include "launchpad-process-pool/loader_executor.hh"
#include "launchpad-process-pool/loader_factory.hh"
type = loader_info_manager_->FindSwType(app_type);
}
- return FindLoaderContext(type, PAD_LOADER_ID_STATIC);
+ return FindLoaderContext(type, PadLoaderId::Static);
}
std::shared_ptr<LoaderContext> LoaderManager::FindAlternativeLoaderContext(
LoaderType type) {
auto alternative_types = loader_info_manager_->GetAlternativeTypes(type);
for (auto& alternative_type : alternative_types) {
- auto context = FindLoaderContext(alternative_type, PAD_LOADER_ID_STATIC);
+ auto context = FindLoaderContext(alternative_type, PadLoaderId::Static);
if (context == nullptr)
continue;
#include "launchpad-process-pool/request.hh"
+#include <string>
#include <utility>
+#include <vector>
+
+#include <exception.hh>
+
+#include "launchpad-process-pool/log_private.hh"
namespace launchpad {
-Request::Request(std::unique_ptr<ClientSocket> client_socket, app_pkt_t* pkt,
- tizen_base::Bundle b)
+Request::Request(std::unique_ptr<ClientSocket> client_socket)
: client_socket_(std::move(client_socket)),
- pkt_(pkt, std::free),
- b_(std::move(b)),
peer_cred_(PeerCredentials::Get(client_socket_->GetFd())) {
+ char header[sizeof(int) + sizeof(int) + sizeof(int)] = { 0, };
+ int ret = client_socket_->Receive(header, sizeof(header));
+ if (ret != 0) {
+ _E("Failed to receive the packet header. error(%d)", ret);
+ THROW(ret);
+ }
+
+ memcpy(&cmd_, header, sizeof(int));
+ int datalen = 0;
+ memcpy(&datalen, header + sizeof(int), sizeof(int));
+ std::vector<char> buf(datalen);
+
+ ret = client_socket_->Receive(buf.data(), datalen);
+ if (ret != 0) {
+ _E("Failed to receive the packet. error(%d)", ret);
+ THROW(ret);
+ }
+
+ std::string raw(buf.begin(), buf.end());
+ b_ = tizen_base::Bundle(raw);
}
ClientSocket* Request::GetClientSocket() const {
return client_socket_.get();
}
-app_pkt_t* Request::GetAppPacket() const {
- return pkt_.get();
-}
-
const tizen_base::Bundle& Request::GetBundle() const {
return b_;
}
}
int Request::GetCmd() const {
- return pkt_->cmd;
+ return cmd_;
}
pid_t Request::GetCallerPid() const {
#include <client_socket.hh>
#include <peer_credentials.hh>
-#include "lib/common/inc/launchpad_common.h"
-
#include "launchpad-process-pool/loader_context.hh"
namespace launchpad {
class Request {
public:
- Request(std::unique_ptr<ClientSocket> client_socket, app_pkt_t* pkt,
- tizen_base::Bundle b);
+ explicit Request(std::unique_ptr<ClientSocket> client_socket);
ClientSocket* GetClientSocket() const;
- app_pkt_t* GetAppPacket() const;
const tizen_base::Bundle& GetBundle() const;
void SetAppInfo(std::unique_ptr<AppInfo> app_info);
const AppInfo* GetAppInfo() const;
private:
std::unique_ptr<ClientSocket> client_socket_;
- std::unique_ptr<app_pkt_t, decltype(std::free)*> pkt_;
- tizen_base::Bundle b_;
std::unique_ptr<PeerCredentials> peer_cred_;
+ int cmd_ = -1;
+ tizen_base::Bundle b_;
std::unique_ptr<AppInfo> app_info_;
std::shared_ptr<LoaderContext> context_;
std::shared_ptr<LoaderContext> available_context_;
#include <utility>
#include "launchpad-process-pool/config.hh"
-#include "lib/common/inc/launchpad_common.h"
+#include "launchpad-process-pool/log_private.hh"
namespace launchpad {
#include <string>
#include <vector>
-#include "lib/common/inc/launchpad_common.h"
-
#include "launchpad-process-pool/dbus.hh"
#include "launchpad-process-pool/log_private.hh"
void Do() override {
_W("pid: %d", pid_);
- _delete_sock_path(pid_, getuid());
try {
+ std::string path = "/run/aul/apps/" + std::to_string(getuid()) + "/" +
+ std::to_string(pid_);
+ DeleteSocketPath(fs::path(path));
+
DeleteUnusedFiles();
SocketGarbadgeCollector();
} catch (const std::filesystem::filesystem_error& e) {
}
private:
+ void DeleteSocketPath(const fs::path& path) {
+ try {
+ fs::remove_all(path);
+ } catch (const fs::filesystem_error& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ }
+ }
+
void SocketGarbadgeCollector() {
std::string path = "/run/aul/apps/" + std::to_string(getuid());
for (const auto &entry : fs::directory_iterator(path)) {
std::string proc_path = "/proc/" + entry.path().filename().string();
if (!fs::exists(proc_path))
- _delete_sock_path(atoi(entry.path().filename().c_str()), getuid());
+ DeleteSocketPath(entry.path());
}
}
constexpr const char kAulApiVersion[] = "__AUL_API_VERSION__";
constexpr const char kAulLoaderName[] = "__AUL_LOADER_NAME__";
constexpr const char kAulSdk[] = "__AUL_SDK__";
-constexpr const char kAulOrgCallrPid[] = "__AUL_ORG_CALLER_PID__";
+constexpr const char kAulOrgCallerPid[] = "__AUL_ORG_CALLER_PID__";
constexpr const char kAulHighPriority[] = "__AUL_HIGHPRIORITY__";
constexpr const char kAulIsGlobal[] = "__AUL_IS_GLOBAL__";
constexpr const char kAulTepPath[] = "__AUL_TEP_PATH__";
return fd;
}
+void ServerSocket::SetCloseOnExec(bool do_close) {
+ int flags = fcntl(fd_, F_GETFD);
+ int ret = fcntl(fd_, F_SETFD,
+ do_close ? flags | FD_CLOEXEC : flags & ~FD_CLOEXEC);
+ if (ret != 0)
+ _E("fcntl() is failed. errno(%d)", errno);
+}
+
} // namespace launchpad
bool IsClosed() const;
int GetFd() const;
int RemoveFd();
+ void SetCloseOnExec(bool do_close);
private:
int fd_;
--- /dev/null
+/*
+ * Copyright (c) 2023 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 LIB_LAUNCHPAD_COMMON_TYPES_HH_
+#define LIB_LAUNCHPAD_COMMON_TYPES_HH_
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace launchpad {
+
+const int kLoaderArgLength = 1024;
+
+enum LoaderArg {
+ Path,
+ Type,
+ Id,
+ Hydra,
+ Extra,
+ Dummy,
+};
+
+enum HydraCmd {
+ LaunchCandidate,
+ LaunchCandidateWithArgs,
+};
+
+enum LoaderType {
+ Unsupported = -1,
+ None = 0,
+ User = 1,
+ Dynamic = 100,
+ Max,
+};
+
+enum PadCmd {
+ Launch = 0,
+ Visibility = 10,
+ AddLoader = 11,
+ RemoveLoader = 12,
+ MakeDefaultSlots = 13,
+ Demand = 14,
+ Ping = 15,
+ UpdateAppType = 16,
+ PrepareAppDefinedLoader = 17,
+ Connect = 18,
+};
+
+enum PadLoaderId {
+ Static = 0,
+ Direct = 1,
+ DynamicBase = 10,
+};
+
+enum AmdCmd {
+ LaunchpadDeadSignal = 61,
+ LaunchpadLaunchSignal = 83,
+ AppStartupSignal = 89,
+};
+
+} // namespace launchpad
+
+#endif // LIB_LAUNCHPAD_COMMON_TYPES_HH_
APPLY_PKG_CONFIG(${TARGET_LAUNCHPAD_GLIB} PUBLIC
BUNDLE_DEPS
+ DBUS_DEPS
DLOG_DEPS
GIO_DEPS
+ LIBTZPLATFORM_CONFIG_DEPS
VCONF_DEPS
)
#include "launchpad-glib/util.hh"
+#include <dbus/dbus.h>
#include <stdlib.h>
+#include <sys/mount.h>
#include <sys/personality.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
+#include <tzplatform_config.h>
#include <unistd.h>
#include <filesystem>
+#include <fstream>
+#include <memory>
#include <string>
+#include <utility>
+#include <vector>
#include <aul_keys.hh>
+#include <exception.hh>
+#include <parcel.hh>
+#include <parcelable.hh>
+#include <server_socket.hh>
+#include <socket.hh>
#include "launchpad-glib/log_private.hh"
+#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+
namespace fs = std::filesystem;
namespace launchpad {
namespace {
constexpr const char kDefaultLocale[] = "en_US.UTF-8";
+constexpr const char kTepBusName[] = "org.tizen.system.deviced";
+constexpr const char kTepObjectPath[] = "/Org/Tizen/System/DeviceD/Tzip";
+constexpr const char kTepInterfaceName[] = "org.tizen.system.deviced.Tzip";
+constexpr const char kTepIsMountedMethod[] = "IsMounted";
+const int kMaxTepIsMountRetryCount = 100;
+constexpr const char kApp2sdBusName[] = "org.tizen.app2sd";
+constexpr const char kApp2sdObjectPath[] = "/org/tizen/app2sd";
+constexpr const char kApp2sdInterfaceName[] = "org.tizen.app2sd";
+constexpr const char kApp2sdOndemandSetupInitMethod[] = "OndemandSetupInit";
+const int kApp2sdRetryMax = 5;
+const int kApp2sdWaitUsec = 1000000 / 2; // 0.5 sec
void SetLanguageEnvironments() {
const char* lang = getenv("LANG");
}
#endif // TIZEN_FEATURE_SET_PERSONALITY_32
+class DBus {
+ public:
+ DBus() {
+ DBusError error;
+ dbus_error_init(&error);
+ conn_ = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
+ if (conn_ == nullptr) {
+ _E("Failed to connect to D-Bus Daemon");
+ if (dbus_error_is_set(&error)) {
+ _E("D-Bus error: %s", error.message);
+ dbus_error_free(&error);
+ }
+ THROW(-ENOTCONN);
+ }
+ }
+
+ virtual ~DBus() {
+ if (conn_ != nullptr)
+ dbus_connection_close(conn_);
+ }
+
+ void SendMessage(DBusMessage* message, int timeout, int* result) {
+ if (message == nullptr) {
+ _E("Invalid parameter");
+ THROW(-EINVAL);
+ }
+
+ DBusPendingCall* pending = nullptr;
+ dbus_bool_t ret = dbus_connection_send_with_reply(conn_, message, &pending,
+ timeout);
+ if (!ret || pending == nullptr) {
+ _E("Failed to send message");
+ THROW(-EIO);
+ }
+
+ dbus_connection_flush(conn_);
+ dbus_pending_call_block(pending);
+ auto* reply = dbus_pending_call_steal_reply(pending);
+ dbus_pending_call_unref(pending);
+ if (reply == nullptr) {
+ _E("Failed to get reply message");
+ THROW(-EIO);
+ }
+
+ auto reply_auto =
+ std::unique_ptr<DBusMessage, decltype(dbus_message_unref)*>(
+ reply, dbus_message_unref);
+ DBusMessageIter iter;
+ if (!dbus_message_iter_init(reply, &iter)) {
+ _E("Message ha no argument");
+ THROW(-EIO);
+ }
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) {
+ _E("Argument is not interger. type(%d)",
+ dbus_message_iter_get_arg_type(&iter));
+ THROW(-EIO);
+ }
+
+ dbus_int32_t res;
+ dbus_message_iter_get_basic(&iter, &res);
+ *result = static_cast<int>(res);
+ _D("Result: %d", *result);
+ }
+
+ private:
+ DBusConnection* conn_ = nullptr;
+};
+
+class TepMountChecker : public DBus {
+ public:
+ explicit TepMountChecker(std::vector<std::string> paths)
+ : paths_(std::move(paths)) {}
+
+ bool IsMounted() {
+ for (auto& path : paths_) {
+ if (CheckTepMount(path) != 0)
+ return false;
+ }
+
+ return true;
+ }
+
+ private:
+ DBusMessage* CreateTepMountMessage(const std::string& path) {
+ DBusMessage* message = dbus_message_new_method_call(kTepBusName,
+ kTepObjectPath, kTepInterfaceName, kTepIsMountedMethod);
+ if (message == nullptr) {
+ _E("dbus_message_new_method_call() is failed");
+ return nullptr;
+ }
+
+ DBusMessageIter iter;
+ dbus_message_iter_init_append(message, &iter);
+ auto* tep_path = path.c_str();
+ auto ret = dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
+ &tep_path);
+ if (!ret) {
+ _E("dbus_message_iter_append_basic() is failed");
+ dbus_message_unref(message);
+ return nullptr;
+ }
+
+ return message;
+ }
+
+ int IsTepMountDone(const std::string& path) {
+ int result = -1;
+ auto message = std::unique_ptr<DBusMessage, decltype(dbus_message_unref)*>(
+ CreateTepMountMessage(path), dbus_message_unref);
+ SendMessage(message.get(), 500, &result);
+ return result;
+ }
+
+ int CheckTepMount(const std::string& path) {
+ if (path.empty())
+ return 0;
+
+ int count = 0;
+ while (count < kMaxTepIsMountRetryCount) {
+ if (IsTepMountDone(path) == 1)
+ return 0;
+
+ usleep(50 * 1000);
+ count++;
+ }
+
+ _E("Not able to mount within 5 seconds. path(%s", path.c_str());
+ return -1;
+ }
+
+ private:
+ std::vector<std::string> paths_;
+};
+
+void MountDirectories(const std::vector<std::string>& srcs,
+ const std::string& dest) {
+ std::string opt = "lowerdir=" + dest;
+ for (auto& src : srcs)
+ opt += ":" + src;
+
+ _D("mount opt: %s", opt.c_str());
+ int ret = mount(nullptr, dest.c_str(), "overlay", MS_RDONLY, opt.c_str());
+ if (ret != 0)
+ _E("mount() is failed. dest(%s), errno(%d)", dest.c_str(), errno);
+}
+
+class ExternalPackage : public DBus {
+ public:
+ ExternalPackage(std::string package, uid_t uid)
+ : package_(std::move(package)), uid_(uid) {
+ _D("package(%s), uid(%u)", package_.c_str(), uid_);
+ }
+
+ void Enable() {
+ int result = -1;
+ int retry_count = 0;
+ auto message = std::unique_ptr<DBusMessage, decltype(dbus_message_unref)*>(
+ CreateApp2sdMessage(), dbus_message_unref);
+ while (retry_count <= kApp2sdRetryMax) {
+ try {
+ SendMessage(message.get(), 500, &result);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ retry_count++;
+ continue;
+ }
+
+ break;
+ }
+
+ _D("Result: %d", result);
+ if (result < 0)
+ THROW(-EIO);
+ }
+
+ private:
+ DBusMessage* CreateApp2sdMessage() {
+ DBusMessage* message = dbus_message_new_method_call(kApp2sdBusName,
+ kApp2sdObjectPath, kApp2sdInterfaceName,
+ kApp2sdOndemandSetupInitMethod);
+ if (message == nullptr) {
+ _E("dbus_message_new_method_call() is failed");
+ return nullptr;
+ }
+
+ DBusMessageIter iter;
+ dbus_message_iter_init_append(message, &iter);
+ if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
+ package_.c_str())) {
+ _E("dbus_message_iter_append_basic() is failed");
+ dbus_message_unref(message);
+ return nullptr;
+ }
+
+ return message;
+ }
+
+ private:
+ std::string package_;
+ uid_t uid_;
+};
+
+class AmdPacket : public tizen_base::Parcelable {
+ public:
+ explicit AmdPacket(int cmd) : cmd_(cmd) {}
+
+ void WriteToParcel(tizen_base::Parcel* parcel) const {
+ parcel->WriteInt32(cmd_);
+ parcel->WriteInt32(0);
+ parcel->WriteInt32(0);
+ }
+
+ void ReadFromParcel(tizen_base::Parcel* parcel) {
+ parcel->ReadInt32(&cmd_);
+ }
+
+ private:
+ int cmd_;
+};
+
} // namespace
void Util::SetEnvironments(const AppInfo* app_info) {
}
}
+int Util::EnableExternalPackage(const AppInfo* app_info) {
+ auto installed_storage = app_info->GetBundle().GetString(
+ kAulInstalledStorage);
+ if (installed_storage != "external")
+ return 0;
+
+ try {
+ ExternalPackage external_package(app_info->GetPkgId(),
+ app_info->IsGlobal() ? GLOBAL_USER : getuid());
+ external_package.Enable();
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ return -1;
+ }
+
+ return 0;
+}
+
+int Util::MountResourceDirectories(const AppInfo* app_info) {
+ auto& root_path = app_info->GetRootPath();
+ auto& b = app_info->GetBundle();
+ auto global_res_dir = b.GetStringArray(kAulMountGlobalResDir);
+ if (!global_res_dir.empty())
+ MountDirectories(global_res_dir, root_path + "/res/mount/global");
+
+ auto allowed_res_dir = b.GetStringArray(kAulMountAllowedResDir);
+ if (!allowed_res_dir.empty())
+ MountDirectories(allowed_res_dir, root_path + "/res/mount/allowed");
+
+ auto res_pkgids = b.GetStringArray(kAulMountResPkgIds);
+ if (!res_pkgids.empty()) {
+ std::string pkgids;
+ for (auto& pkgid : res_pkgids) {
+ if (!pkgids.empty())
+ pkgids += ":";
+
+ pkgids += pkgid;
+ }
+
+ setenv("RES_PKGIDS", pkgids.c_str(), 1);
+ }
+
+ return 0;
+}
+
+int Util::WaitTepMount(const AppInfo* app_info) {
+ if (app_info->GetBundle().GetType(kAulTepPath) == BUNDLE_TYPE_NONE)
+ return 0;
+
+ try {
+ auto paths = app_info->GetBundle().GetStringArray(kAulTepPath);
+ TepMountChecker checker(std::move(paths));
+ if (!checker.IsMounted())
+ return -1;
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ return e.GetErrorCode();
+ }
+
+ _I("TEP Mount has been done");
+ return 0;
+}
+
+std::string Util::GetLibDirectory(const AppInfo* app_info) {
+ std::filesystem::path path(app_info->GetAppPath());
+ auto lib_dir = path.relative_path().string() + "/../lib/";
+ if (std::filesystem::exists(lib_dir))
+ return lib_dir;
+
+ return "";
+}
+
+void Util::CloseAllFds() {
+ int aul_fd = -1;
+ const char* aul_listen_fd = getenv("AUL_LISTEN_FD");
+ if (aul_listen_fd != nullptr)
+ aul_fd = atoi(aul_listen_fd);
+
+ try {
+ fs::path proc_path("/proc/self/fd");
+ for (const auto& entry : fs::directory_iterator(proc_path)) {
+ if (!isdigit(entry.path().filename().string()[0]))
+ continue;
+
+ int fd = std::stoi(entry.path().filename().string());
+ if (fd < 3 || fd == aul_fd)
+ continue;
+
+ close(fd);
+ }
+ } catch (const fs::filesystem_error& e) {
+ _E("Execption occurs. error(%s)", e.what());
+ }
+}
+
+int Util::PrepareAppSocket() {
+ try {
+ std::string path = "/run/aul/apps/" + std::to_string(getuid()) + "/" +
+ std::to_string(getpid());
+ ServerSocket socket;
+ if (!fs::exists(path))
+ fs::create_directory(path);
+
+ path += "/.app-sock";
+ socket.Bind(path);
+ socket.Listen(128);
+ socket.SetReceiveBufferSize(Socket::kSocketMaxBufferSize);
+ socket.SetSendBufferSize(Socket::kSocketMaxBufferSize);
+ socket.SetCloseOnExec(false);
+ int fd = socket.RemoveFd();
+ setenv("AUL_LISTEN_FD", std::to_string(fd).c_str(), 1);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ return e.GetErrorCode();
+ }
+
+ return 0;
+}
+
+int Util::PrepareAppIdFile(const AppInfo* app_info) {
+ std::string path = "/run/aul/apps/" + std::to_string(getuid()) + "/" +
+ std::to_string(getpid()) + "/" + app_info->GetAppId();
+ std::ofstream stream(path);
+ stream.close();
+ return 0;
+}
+
+int Util::SendCmdToAmd(enum AmdCmd cmd) {
+ try {
+ std::string endpoint = "/run/aul/daemons/.amd-sock";
+ ClientSocket socket;
+ socket.Connect(endpoint);
+ socket.SetReceiveBufferSize(Socket::kSocketMaxBufferSize);
+ socket.SetReceiveTimeout(5000);
+
+ AmdPacket packet(static_cast<int>(cmd));
+ tizen_base::Parcel parcel;
+ parcel.WriteParcelable(packet);
+
+ int ret = socket.Send(parcel.GetData(), parcel.GetDataSize());
+ if (ret != 0) {
+ _E("Failed to send cmd(%d), error(%d)", static_cast<int>(cmd), ret);
+ return -ECOMM;
+ }
+ } catch (const Exception& e) {
+ _E("Exception occrus. error(%s)", e.what());
+ return e.GetErrorCode();
+ }
+
+ return 0;
+}
+
} // namespace launchpad
#ifndef LIB_LAUNCHPAD_GLIB_UTIL_HH_
#define LIB_LAUNCHPAD_GLIB_UTIL_HH_
+#include <sys/types.h>
+#include <tzplatform_config.h>
+
+#include <string>
+
#include <app_info.hh>
+#include <types.hh>
#undef EXPORT_API
#define EXPORT_API __attribute__((visibility("default")))
+#undef GLOBAL_USER
+#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+
namespace launchpad {
class EXPORT_API Util {
public:
static void SetEnvironments(const AppInfo* app_info);
static void DeleteSocketPath(pid_t pid, uid_t uid);
+ static int EnableExternalPackage(const AppInfo* app_info);
+ static int MountResourceDirectories(const AppInfo* app_info);
+ static int WaitTepMount(const AppInfo* app_info);
+ static std::string GetLibDirectory(const AppInfo* app_info);
+ static void CloseAllFds();
+ static int PrepareAppSocket();
+ static int PrepareAppIdFile(const AppInfo* app_info);
+ static int SendCmdToAmd(enum AmdCmd cmd);
};
} // namespace launchpad
#include <parcel.hh>
#include <sched_priority.hh>
#include <sigchld_info.hh>
-
-#include "common/inc/launchpad_common.h"
-#include "common/inc/launchpad_types.h"
+#include <types.hh>
#include "launchpad-hydra/log_private.hh"
#include "launchpad-hydra/event_loop.hh"
THROW(-EINVAL);
}
- type_ = argv[LOADER_ARG_TYPE][0] - '0';
- if (type_ < 0 || type_ >= LAUNCHPAD_LOADER_TYPE_MAX) {
+ type_ = argv[LoaderArg::Type][0] - '0';
+ if (type_ < 0 || type_ >= LoaderType::Max) {
_E("Invalid argument. type(%d)", type_);
THROW(-EINVAL);
}
- int hydra_mode = argv[LOADER_ARG_HYDRA][0] - '0';
+ int hydra_mode = argv[LoaderArg::Hydra][0] - '0';
_D("Hydra mode: %d", hydra_mode);
if (!hydra_mode) {
_W("Run in non hydra mode");
THROW(-EINVAL);
}
- argv[LOADER_ARG_HYDRA] = const_cast<char*>("0");
- loader_id_ = atoi(argv[LOADER_ARG_ID]);
+ argv[LoaderArg::Hydra] = const_cast<char*>("0");
+ loader_id_ = atoi(argv[LoaderArg::Id]);
HydraArgs::GetInst().Set(argc, argv);
std::string env = std::to_string(
void LaunchpadHydra::HandleLaunchEvent(const HydraRequest& request) {
pid_t pid = -1;
- if (request.GetCommand() == LAUNCH_CANDIDATE) {
+ if (request.GetCommand() == HydraCmd::LaunchCandidate) {
_W("LAUNCH_CANDIDATE");
pid = executor_->Execute(argc_, argv_, request.GetPriority());
- } else if (request.GetCommand() == LAUNCH_CANDIDATE_WITH_ARGS) {
+ } else if (request.GetCommand() == HydraCmd::LaunchCandidateWithArgs) {
_W("LAUNCH_CANDIDATE_WITH_ARGS");
pid = executor_->Execute(request.GetArgc(), request.GetArgv(),
request.GetPriority());
#include <sched_priority.hh>
#include <socket.hh>
#include <util.hh>
+#include <types.hh>
-#include "common/inc/launchpad_common.h"
-#include "common/inc/launchpad_types.h"
#include "launchpad/log_private.hh"
#include "launchpad/step_prepare_execution.hh"
#include "launchpad/thread_control.hh"
THROW(-EINVAL);
}
- int is_hydra = argv_[LOADER_ARG_HYDRA][0] - '0';
+ int is_hydra = argv_[LoaderArg::Hydra][0] - '0';
if (is_hydra) {
_E("Cannot run in hydra mode");
THROW(-EINVAL);
}
- loader_type_ = atoi(argv_[LOADER_ARG_TYPE]);
- if (loader_type_ < 0 || loader_type_ >= LAUNCHPAD_TYPE_MAX) {
+ loader_type_ = atoi(argv_[LoaderArg::Type]);
+ if (loader_type_ < 0 || loader_type_ >= LoaderType::Max) {
_E("Invalid argument. type: %d", loader_type_);
THROW(-EINVAL);
}
- loader_id_ = atoi(argv_[LOADER_ARG_ID]);
+ loader_id_ = atoi(argv_[LoaderArg::Id]);
_W("loader type: %d, loader id: %d", loader_type_, loader_id_);
context = this;
}
}
void LaunchpadLoader::ResetArgs() {
- memset(argv_[LOADER_ARG_TYPE], 0, strlen(argv_[LOADER_ARG_TYPE]));
- memset(argv_[LOADER_ARG_ID], 0, strlen(argv_[LOADER_ARG_ID]));
- memset(argv_[LOADER_ARG_EXTRA], 0, strlen(argv_[LOADER_ARG_EXTRA]));
+ memset(argv_[LoaderArg::Type], 0, strlen(argv_[LoaderArg::Type]));
+ memset(argv_[LoaderArg::Id], 0, strlen(argv_[LoaderArg::Id]));
+ memset(argv_[LoaderArg::Extra], 0, strlen(argv_[LoaderArg::Extra]));
}
void LaunchpadLoader::WaitForThreads(int threads) {
bool LaunchpadLoader::OnCreate() {
setsid();
- tizen_base::Bundle extra(argv_[LOADER_ARG_EXTRA]);
+ tizen_base::Bundle extra(argv_[LoaderArg::Extra]);
ResetArgs();
if (callback_.create == nullptr) {
}
memset(argv_[0], '\0', strlen(argv_[0]));
- snprintf(argv_[0], LOADER_ARG_LEN, "%s", argv[0]);
+ snprintf(argv_[0], kLoaderArgLength, "%s", argv[0]);
}
int LaunchpadLoader::OnLaunch(int argc, char** argv, AppInfo* app_info) {
#include <app_info.hh>
#include <aul_keys.hh>
+#include <stdio.hh>
+#include <util.hh>
-#include "common/inc/launchpad_common.h"
-#include "common/inc/launchpad_types.h"
#include "launchpad/log_private.hh"
#include "launchpad/thread_control.hh"
}
int StepPrepareExecution::EnableExternalPackage(AppInfo* app_info) {
- int ret = _enable_external_pkg(app_info->GetBundle().GetHandle(),
- app_info->GetPkgId().c_str(),
- app_info->IsGlobal() ? GLOBAL_USER : getuid());
+ int ret = Util::EnableExternalPackage(app_info);
if (ret < 0) {
_E("Failed to enable external package. error: %d", ret);
return -1;
}
int StepPrepareExecution::MountResourceDirectories(AppInfo* app_info) {
- int ret = _mount_res_dir(app_info->GetRootPath().c_str(),
- app_info->GetBundle().GetHandle());
+ int ret = Util::MountResourceDirectories(app_info);
if (ret < 0) {
_E("Failed to mount resource direstories. error: %d", ret);
return -1;
}
int StepPrepareExecution::SetupStdio(AppInfo* app_info) {
- _setup_stdio(basename(app_info->GetAppPath().c_str()));
+ Stdio::Setup();
return 0;
}
}
int StepPrepareExecution::SetProcessName(AppInfo* app_info) {
+ char* name = basename(const_cast<char*>(app_info->GetAppPath().c_str()));
char process_name[16] = { 0, };
- snprintf(process_name, sizeof(process_name), "%s",
- basename(app_info->GetAppPath().c_str()));
+ snprintf(process_name, sizeof(process_name), "%s", name);
prctl(PR_SET_NAME, process_name);
return 0;
}
int StepPrepareExecution::WaitTepMount(AppInfo* app_info) {
- int ret = _wait_tep_mount(app_info->GetBundle().GetHandle());
+ int ret = Util::WaitTepMount(app_info);
if (ret < 0) {
_E("Failed to wait tep mount. error: %d", ret);
return -1;
}
int StepPrepareExecution::PrepareAppSocket(AppInfo* app_info) {
- int ret = _prepare_app_socket();
+ int ret = Util::PrepareAppSocket();
if (ret < 0) {
_E("Failed to prepare app socket. error: %d", ret);
return -1;
}
int StepPrepareExecution::PrepareIdFile(AppInfo* app_info) {
- int ret = _prepare_id_file();
+ int ret = Util::PrepareAppIdFile(app_info);
if (ret < 0) {
_E("Failed to prepare id file. error: %d", ret);
return -1;
}
int StepPrepareExecution::SendStartupSignal(AppInfo* app_info) {
- if (_send_cmd_to_amd(APP_STARTUP_SIGNAL) != 0)
+ if (Util::SendCmdToAmd(AmdCmd::AppStartupSignal) != 0)
_W("Failed to send startup signal");
return 0;