mirror of
https://gitee.com/openharmony/startup_appspawn
synced 2024-11-23 15:10:44 +00:00
commit
a70132af38
1
BUILD.gn
1
BUILD.gn
@ -62,6 +62,7 @@ ohos_static_library("appspawn_server") {
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
external_deps = [
|
||||
"bytrace_standard:bytrace_core",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
|
@ -27,7 +27,10 @@ ohos_static_library("appspawn_socket_client") {
|
||||
include_dirs = [ "${appspawn_path}/include" ]
|
||||
public_configs = [ ":exported_header_files" ]
|
||||
deps = [ "//utils/native/base:utils" ]
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
external_deps = [
|
||||
"bytrace_standard:bytrace_core",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
|
||||
subsystem_name = "${subsystem_name}"
|
||||
part_name = "${part_name}"
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "bytrace.h"
|
||||
#include "hilog/log.h"
|
||||
#include "securec.h"
|
||||
|
||||
@ -48,6 +49,7 @@ int AppSpawnMsgPeer::GetConnectFd() const
|
||||
|
||||
int AppSpawnMsgPeer::Response(pid_t pid)
|
||||
{
|
||||
BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
if ((socket_ == nullptr) || (connectFd_ < 0)) {
|
||||
HiLog::Error(LABEL, "Invalid socket params: connectFd %d", connectFd_);
|
||||
return -1;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <sys/capability.h>
|
||||
#include <thread>
|
||||
|
||||
#include "bytrace.h"
|
||||
#include "errors.h"
|
||||
#include "hilog/log.h"
|
||||
#include "main_thread.h"
|
||||
@ -126,6 +127,7 @@ AppSpawnServer::AppSpawnServer(const std::string &socketName)
|
||||
|
||||
void AppSpawnServer::MsgPeer(int connectFd)
|
||||
{
|
||||
BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
char err_string[ERR_STRING_SZ];
|
||||
std::unique_ptr<AppSpawnMsgPeer> msgPeer = std::make_unique<AppSpawnMsgPeer>(socket_, connectFd);
|
||||
if (msgPeer == nullptr || msgPeer->MsgPeer() != 0) {
|
||||
@ -152,6 +154,7 @@ void AppSpawnServer::ConnectionPeer()
|
||||
continue;
|
||||
}
|
||||
|
||||
BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
mut_.lock(); // Ensure that mutex in SaveConnection is unlocked before being forked
|
||||
socket_->SaveConnection(connectFd);
|
||||
mut_.unlock();
|
||||
@ -188,6 +191,7 @@ bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen)
|
||||
dataCond_.wait(lock, [this] { return !this->appQueue_.empty(); });
|
||||
std::unique_ptr<AppSpawnMsgPeer> msg = std::move(appQueue_.front());
|
||||
appQueue_.pop();
|
||||
BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
int connectFd = msg->GetConnectFd();
|
||||
ClientSocket::AppProperty *appProperty = msg->GetMsg();
|
||||
if (!CheckAppProperty(appProperty)) {
|
||||
@ -212,6 +216,7 @@ bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen)
|
||||
msg->Response(-errno);
|
||||
continue;
|
||||
} else if (pid == 0) {
|
||||
BYTRACE_NAME(BYTRACE_TAG_APP, "fork MainThread");
|
||||
SpecialHandle(appProperty);
|
||||
SetAppProcProperty(connectFd, appProperty, longProcName, longProcNameLen, fd);
|
||||
_exit(0);
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <iostream>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "bytrace.h"
|
||||
#include "hilog/log.h"
|
||||
#include "securec.h"
|
||||
|
||||
@ -58,6 +59,7 @@ void ClientSocket::CloseClient()
|
||||
|
||||
int ClientSocket::ConnectSocket(int connectFd)
|
||||
{
|
||||
BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
char err_string[ERR_STRING_SZ];
|
||||
if (connectFd < 0) {
|
||||
HiLog::Error(LABEL, "Client: Invalid socket fd: %d", connectFd);
|
||||
@ -92,11 +94,13 @@ int ClientSocket::ConnectSocket()
|
||||
|
||||
int ClientSocket::WriteSocketMessage(const void *buf, int len)
|
||||
{
|
||||
BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
return WriteSocketMessage(socketFd_, buf, len);
|
||||
}
|
||||
|
||||
int ClientSocket::ReadSocketMessage(void *buf, int len)
|
||||
{
|
||||
BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
return ReadSocketMessage(socketFd_, buf, len);
|
||||
}
|
||||
} // namespace AppSpawn
|
||||
|
@ -29,7 +29,10 @@ ohos_unittest("AppSpawnMsgPeerTest") {
|
||||
|
||||
deps = [ "${appspawn_path}/test:appspawn_test_source" ]
|
||||
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
external_deps = [
|
||||
"bytrace_standard:bytrace_core",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
|
@ -34,6 +34,7 @@ ohos_unittest("AppSpawnServerOverrideTest") {
|
||||
deps = [ "${appspawn_path}/test:appspawn_test_source" ]
|
||||
|
||||
external_deps = [
|
||||
"bytrace_standard:bytrace_core",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
@ -59,6 +60,7 @@ ohos_unittest("AppSpawnServerMockTest") {
|
||||
deps = [ "${appspawn_path}/test:appspawn_test_source" ]
|
||||
|
||||
external_deps = [
|
||||
"bytrace_standard:bytrace_core",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
|
@ -30,7 +30,10 @@ ohos_unittest("ClientSocketTest") {
|
||||
|
||||
deps = [ "${appspawn_path}/test:appspawn_test_source" ]
|
||||
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
external_deps = [
|
||||
"bytrace_standard:bytrace_core",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
|
Loading…
Reference in New Issue
Block a user