mirror of
https://gitee.com/openharmony/startup_appspawn
synced 2024-11-27 01:00:38 +00:00
appspawn log
Signed-off-by: cheng_jinsong <chengjinsong2@huawei.com> Change-Id: I62c83625d98c2689fef2cc14e766b99576a42312
This commit is contained in:
parent
f460cab0d3
commit
7380f35ba7
7
BUILD.gn
7
BUILD.gn
@ -61,6 +61,7 @@ ohos_executable("appspawn") {
|
||||
"ability_runtime:runtime",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"hilog_native:libhilog",
|
||||
"hitrace_native:hitrace_meter",
|
||||
"init:libbegetutil",
|
||||
]
|
||||
@ -105,6 +106,7 @@ ohos_static_library("appspawn_server") {
|
||||
]
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog_native:libhilog",
|
||||
"init:libbegetutil",
|
||||
]
|
||||
if (build_selinux) {
|
||||
@ -157,6 +159,7 @@ ohos_static_library("nwebspawn_server") {
|
||||
]
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog_native:libhilog",
|
||||
"init:libbegetutil",
|
||||
]
|
||||
if (build_selinux) {
|
||||
@ -189,9 +192,9 @@ ohos_executable("nwebspawn") {
|
||||
]
|
||||
configs = [ ":appspawn_config" ]
|
||||
deps = [ "${appspawn_path}:nwebspawn_server" ]
|
||||
|
||||
external_deps = [ "hilog_native:libhilog" ]
|
||||
if (build_selinux) {
|
||||
external_deps = [ "selinux:libhap_restorecon" ]
|
||||
external_deps += [ "selinux:libhap_restorecon" ]
|
||||
}
|
||||
|
||||
install_enable = true
|
||||
|
@ -34,8 +34,8 @@ void LoadExtendLib(AppSpawnContent *content)
|
||||
APPSPAWN_LOGI("LoadExtendLib: Start calling dlopen acelibdir.");
|
||||
void *aceAbilityLib = NULL;
|
||||
aceAbilityLib = dlopen(acelibdir, RTLD_NOW | RTLD_GLOBAL);
|
||||
APPSPAWN_CHECK(aceAbilityLib != NULL, return, "Fail to dlopen %s, [%s]", acelibdir, dlerror());
|
||||
APPSPAWN_LOGI("LoadExtendLib: Success to dlopen %s", acelibdir);
|
||||
APPSPAWN_CHECK(aceAbilityLib != NULL, return, "Fail to dlopen %{public}s, [%{public}s]", acelibdir, dlerror());
|
||||
APPSPAWN_LOGI("LoadExtendLib: Success to dlopen %{public}s", acelibdir);
|
||||
|
||||
bool preload = OHOS::system::GetBoolParameter("const.appspawn.preload", DEFAULT_PRELOAD_VALUE);
|
||||
if (!preload) {
|
||||
|
@ -30,7 +30,7 @@ void SetAppAccessToken(struct AppSpawnContent_ *content, AppSpawnClient *client)
|
||||
{
|
||||
AppSpawnClientExt *appProperty = reinterpret_cast<AppSpawnClientExt *>(client);
|
||||
int32_t ret = SetSelfTokenID(appProperty->property.accessTokenIdEx);
|
||||
APPSPAWN_LOGI("AppSpawnServer::set access token id = %d, ret = %d %d",
|
||||
APPSPAWN_LOGV("AppSpawnServer::set access token id = %{public}llu, ret = %{public}d %{public}d",
|
||||
appProperty->property.accessTokenIdEx, ret, getuid());
|
||||
}
|
||||
|
||||
@ -46,10 +46,10 @@ void SetSelinuxCon(struct AppSpawnContent_ *content, AppSpawnClient *client)
|
||||
hapDomainInfo.hapFlags = appProperty->property.hapFlags;
|
||||
int32_t ret = hapContext.HapDomainSetcontext(hapDomainInfo);
|
||||
if (ret != 0) {
|
||||
APPSPAWN_LOGE("AppSpawnServer::Failed to hap domain set context, errno = %d %s",
|
||||
APPSPAWN_LOGE("AppSpawnServer::Failed to hap domain set context, errno = %{public}d %{public}s",
|
||||
errno, appProperty->property.apl);
|
||||
} else {
|
||||
APPSPAWN_LOGI("AppSpawnServer::Success to hap domain set context, ret = %d", ret);
|
||||
APPSPAWN_LOGV("AppSpawnServer::Success to hap domain set context, ret = %{public}d", ret);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -77,12 +77,12 @@ int SetSeccompFilter(struct AppSpawnContent_ *content, AppSpawnClient *client)
|
||||
const char *appName = APP_NAME;
|
||||
#endif
|
||||
if (!SetSeccompPolicyWithName(appName)) {
|
||||
APPSPAWN_LOGE("Failed to set %s seccomp filter and exit", appName);
|
||||
APPSPAWN_LOGE("Failed to set %{public}s seccomp filter and exit", appName);
|
||||
#ifndef APPSPAWN_TEST
|
||||
return -EINVAL;
|
||||
#endif
|
||||
} else {
|
||||
APPSPAWN_LOGI("Success to set %s seccomp filter", appName);
|
||||
APPSPAWN_LOGI("Success to set %{public}s seccomp filter", appName);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
@ -91,7 +91,7 @@ int SetSeccompFilter(struct AppSpawnContent_ *content, AppSpawnClient *client)
|
||||
void HandleInternetPermission(const AppSpawnClient *client)
|
||||
{
|
||||
AppSpawnClientExt *appPropertyExt = (AppSpawnClientExt *)client;
|
||||
APPSPAWN_LOGI("HandleInternetPermission id %d setAllowInternet %hhu allowInternet %hhu",
|
||||
APPSPAWN_LOGV("HandleInternetPermission id %{public}d setAllowInternet %hhu allowInternet %hhu",
|
||||
client->id, appPropertyExt->setAllowInternet, appPropertyExt->allowInternet);
|
||||
if (appPropertyExt->setAllowInternet == 1 && appPropertyExt->allowInternet == 0) {
|
||||
DisallowInternet();
|
||||
|
@ -63,7 +63,7 @@ void *LoadWithRelroFile(const std::string &lib, const std::string &nsName,
|
||||
S_IRUSR | S_IRGRP | S_IROTH);
|
||||
if (relroFd < 0) {
|
||||
int tmpNo = errno;
|
||||
APPSPAWN_LOGE("LoadWithRelroFile open failed, error=[%s]", strerror(tmpNo));
|
||||
APPSPAWN_LOGE("LoadWithRelroFile open failed, error=[%{public}s]", strerror(tmpNo));
|
||||
return nullptr;
|
||||
}
|
||||
void *nwebReservedAddress = mmap(NULL, nwebReservedSize, PROT_NONE,
|
||||
@ -71,7 +71,7 @@ void *LoadWithRelroFile(const std::string &lib, const std::string &nsName,
|
||||
if (nwebReservedAddress == MAP_FAILED) {
|
||||
close(relroFd);
|
||||
int tmpNo = errno;
|
||||
APPSPAWN_LOGE("LoadWithRelroFile mmap failed, error=[%s]", strerror(tmpNo));
|
||||
APPSPAWN_LOGE("LoadWithRelroFile mmap failed, error=[%{public}s]", strerror(tmpNo));
|
||||
return nullptr;
|
||||
}
|
||||
Dl_namespace dlns;
|
||||
@ -119,7 +119,7 @@ void LoadExtendLib(AppSpawnContent *content)
|
||||
void *handle = dlopen(engineLibDir.c_str(), RTLD_NOW | RTLD_GLOBAL);
|
||||
#endif
|
||||
if (handle == nullptr) {
|
||||
APPSPAWN_LOGE("Fail to dlopen libweb_engine.so, [%s]", dlerror());
|
||||
APPSPAWN_LOGE("Fail to dlopen libweb_engine.so, [%{public}s]", dlerror());
|
||||
} else {
|
||||
APPSPAWN_LOGI("Success to dlopen libweb_engine.so");
|
||||
}
|
||||
@ -131,7 +131,7 @@ void LoadExtendLib(AppSpawnContent *content)
|
||||
g_nwebHandle = dlopen(renderLibDir.c_str(), RTLD_NOW | RTLD_GLOBAL);
|
||||
#endif
|
||||
if (g_nwebHandle == nullptr) {
|
||||
APPSPAWN_LOGE("Fail to dlopen libnweb_render.so, [%s]", dlerror());
|
||||
APPSPAWN_LOGE("Fail to dlopen libnweb_render.so, [%{public}s]", dlerror());
|
||||
} else {
|
||||
APPSPAWN_LOGI("Success to dlopen libnweb_render.so");
|
||||
}
|
||||
@ -144,7 +144,7 @@ void RunChildProcessor(AppSpawnContent *content, AppSpawnClient *client)
|
||||
|
||||
FuncType funcNWebRenderMain = reinterpret_cast<FuncType>(dlsym(g_nwebHandle, "NWebRenderMain"));
|
||||
if (funcNWebRenderMain == nullptr) {
|
||||
APPSPAWN_LOGI("webviewspawn dlsym ERROR=%s", dlerror());
|
||||
APPSPAWN_LOGI("webviewspawn dlsym ERROR=%{public}s", dlerror());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -156,8 +156,8 @@ static void DumpRenderProcessExitedMap()
|
||||
APPSPAWN_LOGI("dump render process exited array:");
|
||||
|
||||
for (auto& it : g_renderProcessMap) {
|
||||
APPSPAWN_LOGV("[pid, time, exitedStatus] = [%d, %ld, %d]",
|
||||
it.first, it.second.recordTime_, it.second.exitStatus_);
|
||||
APPSPAWN_LOGV("[pid, time, exitedStatus] = [%{public}d, %{public}ld, %{public}d]",
|
||||
it.first, static_cast<long>(it.second.recordTime_), it.second.exitStatus_);
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,7 +197,7 @@ int GetRenderProcessTerminationStatus(int32_t pid, int *status)
|
||||
return 0;
|
||||
}
|
||||
|
||||
APPSPAWN_LOGE("not find pid[%d] in render process exited map", pid);
|
||||
APPSPAWN_LOGE("not find pid[%{public}d] in render process exited map", pid);
|
||||
DumpRenderProcessExitedMap();
|
||||
return -1;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ static void NotifyResToParent(struct AppSpawnContent_ *content, AppSpawnClient *
|
||||
|
||||
static void ProcessSafeExit(int code)
|
||||
{
|
||||
APPSPAWN_LOGI("App exit: %d", code);
|
||||
APPSPAWN_LOGI("App exit: %{public}d", code);
|
||||
#ifdef OHOS_LITE
|
||||
_exit(0x7f); // 0x7f user exit
|
||||
#else
|
||||
@ -63,7 +63,7 @@ static void ProcessSafeExit(int code)
|
||||
int DoStartApp(struct AppSpawnContent_ *content, AppSpawnClient *client, char *longProcName, uint32_t longProcNameLen)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
APPSPAWN_LOGI("DoStartApp id %d longProcNameLen %u", client->id, longProcNameLen);
|
||||
APPSPAWN_LOGV("DoStartApp id %{public}d longProcNameLen %{public}u", client->id, longProcNameLen);
|
||||
if (content->handleInternetPermission != NULL) {
|
||||
content->handleInternetPermission(client);
|
||||
}
|
||||
@ -150,7 +150,7 @@ static int AppSpawnChildInternal(void *arg)
|
||||
}
|
||||
#ifdef OHOS_DEBUG
|
||||
long long diff = DiffTime(&tmStart);
|
||||
APPSPAWN_LOGI("App timeused %d %lld ns.", getpid(), diff);
|
||||
APPSPAWN_LOGI("App timeused %{public}d %lld ns.", getpid(), diff);
|
||||
#endif
|
||||
if (ret == 0 && content->runChildProcessor != NULL) {
|
||||
content->runChildProcessor(content, client);
|
||||
@ -181,7 +181,7 @@ int AppSpawnProcessMsg(AppSandboxArg *sandbox, pid_t *childPid)
|
||||
pid_t pid;
|
||||
APPSPAWN_CHECK(sandbox != NULL && sandbox->content != NULL, return -1, "Invalid content for appspawn");
|
||||
APPSPAWN_CHECK(sandbox->client != NULL && childPid != NULL, return -1, "Invalid client for appspawn");
|
||||
APPSPAWN_LOGI("AppSpawnProcessMsg id %d 0x%x", sandbox->client->id, sandbox->client->flags);
|
||||
APPSPAWN_LOGI("AppSpawnProcessMsg id %{public}d 0x%x", sandbox->client->id, sandbox->client->flags);
|
||||
|
||||
#ifndef OHOS_LITE
|
||||
AppSpawnClient *client = sandbox->client;
|
||||
@ -202,7 +202,7 @@ int AppSpawnProcessMsg(AppSandboxArg *sandbox, pid_t *childPid)
|
||||
}
|
||||
#endif
|
||||
*childPid = AppSpawnFork(AppSpawnChild, (void *)sandbox);
|
||||
APPSPAWN_CHECK(*childPid >= 0, return -errno, "fork child process error: %d", -errno);
|
||||
APPSPAWN_CHECK(*childPid >= 0, return -errno, "fork child process error: %{public}d", -errno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -15,14 +15,15 @@
|
||||
|
||||
#ifndef APPSPAWN_SERVER_H
|
||||
#define APPSPAWN_SERVER_H
|
||||
#include "beget_ext.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "beget_ext.h"
|
||||
#include "hilog/log.h"
|
||||
#include "securec.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -86,19 +87,40 @@ long long DiffTime(struct timespec *startTime);
|
||||
pid_t AppSpawnFork(int (*childFunc)(void *arg), void *args);
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
#ifndef OHOS_LITE
|
||||
#define APPSPAWN_LOG(logLevel, domain, tag, fmt, ...) \
|
||||
HiLogPrint(LOG_CORE, (LogLevel)logLevel, domain, tag, \
|
||||
"[%{public}s:%{public}d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
|
||||
|
||||
#ifndef APPSPAWN_LABEL
|
||||
#define APPSPAWN_LABEL "APPSPAWN"
|
||||
#endif
|
||||
#define APPSPAWN_DOMAIN (BASE_DOMAIN + 0x11)
|
||||
|
||||
#define APPSPAWN_LOGI(fmt, ...) STARTUP_LOGI(APPSPAWN_DOMAIN, APPSPAWN_LABEL, fmt, ##__VA_ARGS__)
|
||||
#define APPSPAWN_LOGE(fmt, ...) STARTUP_LOGE(APPSPAWN_DOMAIN, APPSPAWN_LABEL, fmt, ##__VA_ARGS__)
|
||||
#define APPSPAWN_LOGV(fmt, ...) STARTUP_LOGV(APPSPAWN_DOMAIN, APPSPAWN_LABEL, fmt, ##__VA_ARGS__)
|
||||
#define APPSPAWN_LOGW(fmt, ...) STARTUP_LOGW(APPSPAWN_DOMAIN, APPSPAWN_LABEL, fmt, ##__VA_ARGS__)
|
||||
#define APPSPAWN_LOGI(fmt, ...) \
|
||||
APPSPAWN_LOG(LOG_INFO, APPSPAWN_DOMAIN, APPSPAWN_LABEL, fmt, ##__VA_ARGS__)
|
||||
#define APPSPAWN_LOGE(fmt, ...) \
|
||||
APPSPAWN_LOG(LOG_ERROR, APPSPAWN_DOMAIN, APPSPAWN_LABEL, fmt, ##__VA_ARGS__)
|
||||
#define APPSPAWN_LOGV(fmt, ...) \
|
||||
APPSPAWN_LOG(LOG_DEBUG, APPSPAWN_DOMAIN, APPSPAWN_LABEL, fmt, ##__VA_ARGS__)
|
||||
#define APPSPAWN_LOGW(fmt, ...) \
|
||||
APPSPAWN_LOG(LOG_WARN, APPSPAWN_DOMAIN, APPSPAWN_LABEL, fmt, ##__VA_ARGS__)
|
||||
|
||||
#define APPSPAWN_CHECK(retCode, exper, ...) \
|
||||
#else
|
||||
|
||||
#define APPSPAWN_LOGI(fmt, ...) \
|
||||
HILOG_INFO(HILOG_MODULE_HIVIEW, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
|
||||
#define APPSPAWN_LOGE(fmt, ...) \
|
||||
HILOG_ERROR(HILOG_MODULE_HIVIEW, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
|
||||
#define APPSPAWN_LOGV(fmt, ...) \
|
||||
HILOG_DEBUG(HILOG_MODULE_HIVIEW, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
|
||||
#define APPSPAWN_LOGW(fmt, ...) \
|
||||
HILOG_FATAL(HILOG_MODULE_HIVIEW, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#define APPSPAWN_CHECK(retCode, exper, fmt, ...) \
|
||||
if (!(retCode)) { \
|
||||
APPSPAWN_LOGE(__VA_ARGS__); \
|
||||
APPSPAWN_LOGE(fmt, ##__VA_ARGS__); \
|
||||
exper; \
|
||||
}
|
||||
|
||||
@ -107,9 +129,9 @@ pid_t AppSpawnFork(int (*childFunc)(void *arg), void *args);
|
||||
exper; \
|
||||
} \
|
||||
|
||||
#define APPSPAWN_CHECK_ONLY_LOG(retCode, ...) \
|
||||
#define APPSPAWN_CHECK_ONLY_LOG(retCode, fmt, ...) \
|
||||
if (!(retCode)) { \
|
||||
APPSPAWN_LOGE(__VA_ARGS__); \
|
||||
APPSPAWN_LOGE(fmt, ##__VA_ARGS__); \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -57,7 +57,7 @@ int AppSpawnSocket::PackSocketAddr()
|
||||
}
|
||||
socklen_t pathSize = sizeof(socketAddr_.sun_path);
|
||||
if (pathLen >= pathSize) {
|
||||
APPSPAWN_LOGE("Invalid socket name: '%s' too long", socketName_.c_str());
|
||||
APPSPAWN_LOGE("Invalid socket name: '%{public}s' too long", socketName_.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -79,18 +79,18 @@ int AppSpawnSocket::PackSocketAddr()
|
||||
int AppSpawnSocket::CreateSocket()
|
||||
{
|
||||
int socketFd = socket(AF_UNIX, SOCK_STREAM, 0); // SOCK_SEQPACKET
|
||||
APPSPAWN_CHECK(socketFd >= 0, return -errno, "Failed to create socket: %d", errno);
|
||||
APPSPAWN_CHECK(socketFd >= 0, return -errno, "Failed to create socket: %{public}d", errno);
|
||||
|
||||
int flag = 1;
|
||||
int ret = setsockopt(socketFd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int));
|
||||
APPSPAWN_LOGV("Created socket with fd %d, setsockopt %d", socketFd, ret);
|
||||
APPSPAWN_LOGV("Created socket with fd %{public}d, setsockopt %{public}d", socketFd, ret);
|
||||
return socketFd;
|
||||
}
|
||||
|
||||
void AppSpawnSocket::CloseSocket(int &socketFd)
|
||||
{
|
||||
if (socketFd >= 0) {
|
||||
APPSPAWN_LOGV("Closed socket with fd %d", socketFd);
|
||||
APPSPAWN_LOGV("Closed socket with fd %{public}d", socketFd);
|
||||
int flag = 0;
|
||||
setsockopt(socketFd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int));
|
||||
close(socketFd);
|
||||
@ -101,7 +101,7 @@ void AppSpawnSocket::CloseSocket(int &socketFd)
|
||||
int AppSpawnSocket::ReadSocketMessage(int socketFd, void *buf, int len)
|
||||
{
|
||||
if (socketFd < 0 || len <= 0 || buf == nullptr) {
|
||||
APPSPAWN_LOGE("Invalid args: socket %d, len %d, buf might be nullptr", socketFd, len);
|
||||
APPSPAWN_LOGE("Invalid args: socket %{public}d, len %{public}d, buf might be nullptr", socketFd, len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -111,8 +111,8 @@ int AppSpawnSocket::ReadSocketMessage(int socketFd, void *buf, int len)
|
||||
while ((rLen < 0) && (errno == EAGAIN)) {
|
||||
rLen = TEMP_FAILURE_RETRY(read(socketFd, buf, len));
|
||||
}
|
||||
APPSPAWN_CHECK(rLen >= 0, return -EFAULT, "Read message from fd %d error %zd: %d",
|
||||
socketFd, rLen, errno);
|
||||
APPSPAWN_CHECK(rLen >= 0, return -EFAULT,
|
||||
"Read message from fd %{public}d error %{public}zd: %{public}d", socketFd, rLen, errno);
|
||||
|
||||
return rLen;
|
||||
}
|
||||
@ -120,7 +120,7 @@ int AppSpawnSocket::ReadSocketMessage(int socketFd, void *buf, int len)
|
||||
int AppSpawnSocket::WriteSocketMessage(int socketFd, const void *buf, int len)
|
||||
{
|
||||
if (socketFd < 0 || len <= 0 || buf == nullptr) {
|
||||
APPSPAWN_LOGE("Invalid args: socket %d, len %d, buf might be nullptr", socketFd, len);
|
||||
APPSPAWN_LOGE("Invalid args: socket %{public}d, len %{public}d, buf might be nullptr", socketFd, len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -129,10 +129,10 @@ int AppSpawnSocket::WriteSocketMessage(int socketFd, const void *buf, int len)
|
||||
const uint8_t *offset = reinterpret_cast<const uint8_t *>(buf);
|
||||
for (ssize_t wLen = 0; remain > 0; offset += wLen, remain -= wLen, written += wLen) {
|
||||
wLen = write(socketFd, offset, remain);
|
||||
APPSPAWN_LOGV("socket fd %d, wLen %zd", socketFd, wLen);
|
||||
APPSPAWN_LOGV("socket fd %{public}d, wLen %{public}zd", socketFd, wLen);
|
||||
bool isRet = (wLen <= 0) && (errno != EINTR);
|
||||
APPSPAWN_CHECK(!isRet, return -errno, "Failed to write message to fd %d, error %zd: %d",
|
||||
socketFd, wLen, errno);
|
||||
APPSPAWN_CHECK(!isRet, return -errno,
|
||||
"Failed to write message to fd %{public}d, error %{public}zd: %{public}d", socketFd, wLen, errno);
|
||||
}
|
||||
|
||||
return written;
|
||||
|
@ -40,14 +40,14 @@ int ClientSocket::CreateClient()
|
||||
|
||||
int opt = 1;
|
||||
int ret = setsockopt(socketFd_, SOL_SOCKET, SO_PASSCRED, &opt, sizeof(opt));
|
||||
APPSPAWN_LOGV("Client: CreateClient socket fd %d ret %d", socketFd_, ret);
|
||||
APPSPAWN_LOGV("Client: CreateClient socket fd %{public}d ret %{public}d", socketFd_, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ClientSocket::CloseClient()
|
||||
{
|
||||
if (socketFd_ < 0) {
|
||||
APPSPAWN_LOGE("Client: Invalid connectFd %d", socketFd_);
|
||||
APPSPAWN_LOGE("Client: Invalid connectFd %{public}d", socketFd_);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ void ClientSocket::CloseClient()
|
||||
int ClientSocket::ConnectSocket(int connectFd)
|
||||
{
|
||||
if (connectFd < 0) {
|
||||
APPSPAWN_LOGE("Client: Invalid socket fd: %d", connectFd);
|
||||
APPSPAWN_LOGE("Client: Invalid socket fd: %{public}d", connectFd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -69,13 +69,14 @@ int ClientSocket::ConnectSocket(int connectFd)
|
||||
if (value != TIMEOUT_DEF && value != 0) {
|
||||
timeout.tv_sec = value;
|
||||
}
|
||||
APPSPAWN_LOGI("Client: Connected on socket fd %d value %d", connectFd, value);
|
||||
APPSPAWN_LOGI("Client: Connected on socket fd %{public}d value %{public}d", connectFd, value);
|
||||
bool isRet = (setsockopt(connectFd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) != 0) ||
|
||||
(setsockopt(connectFd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)) != 0);
|
||||
APPSPAWN_CHECK(!isRet, return (-1), "Client: Failed to set opt of socket %d, err %d", connectFd, errno);
|
||||
APPSPAWN_CHECK(!isRet, return (-1),
|
||||
"Client: Failed to set opt of socket %{public}d, err %{public}d", connectFd, errno);
|
||||
|
||||
if (connect(connectFd, reinterpret_cast<struct sockaddr *>(&socketAddr_), socketAddrLen_) < 0) {
|
||||
APPSPAWN_LOGW("Client: Connect on socket fd %d, failed: %d", connectFd, errno);
|
||||
APPSPAWN_LOGW("Client: Connect on socket fd %{public}d, failed: %{public}d", connectFd, errno);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -77,11 +77,11 @@ static int SetProcessName(struct AppSpawnContent_ *content, AppSpawnClient *clie
|
||||
// process short name max length 16 bytes.
|
||||
size_t copyLen = (len >= MAX_LEN_SHORT_NAME) ? MAX_LEN_SHORT_NAME - 1 : len;
|
||||
isRet = strncpy_s(shortName, MAX_LEN_SHORT_NAME, appProperty->processName, copyLen) != EOK;
|
||||
APPSPAWN_CHECK(!isRet, return -EINVAL, "strncpy_s short name error: %d", errno);
|
||||
APPSPAWN_CHECK(!isRet, return -EINVAL, "strncpy_s short name error: %{public}d", errno);
|
||||
|
||||
// set short name
|
||||
isRet = prctl(PR_SET_NAME, shortName) == -1;
|
||||
APPSPAWN_CHECK(!isRet, return -errno, "prctl(PR_SET_NAME) error: %d", errno);
|
||||
APPSPAWN_CHECK(!isRet, return -errno, "prctl(PR_SET_NAME) error: %{public}d", errno);
|
||||
|
||||
// reset longProcName
|
||||
isRet = memset_s(longProcName, (size_t)longProcNameLen, 0, (size_t)longProcNameLen) != EOK;
|
||||
@ -89,7 +89,8 @@ static int SetProcessName(struct AppSpawnContent_ *content, AppSpawnClient *clie
|
||||
|
||||
// set long process name
|
||||
isRet = strncpy_s(longProcName, longProcNameLen, appProperty->processName, len) != EOK;
|
||||
APPSPAWN_CHECK(!isRet, return -EINVAL, "strncpy_s long name error: %d longProcNameLen %u", errno, longProcNameLen);
|
||||
APPSPAWN_CHECK(!isRet, return -EINVAL,
|
||||
"strncpy_s long name error: %{public}d longProcNameLen %{public}u", errno, longProcNameLen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -100,7 +101,7 @@ static int SetKeepCapabilities(struct AppSpawnContent_ *content, AppSpawnClient
|
||||
// set keep capabilities when user not root.
|
||||
if (appProperty->property.uid != 0) {
|
||||
bool isRet = prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) == -1;
|
||||
APPSPAWN_CHECK(!isRet, return -errno, "set keepcaps failed: %d", errno);
|
||||
APPSPAWN_CHECK(!isRet, return -errno, "set keepcaps failed: %{public}d", errno);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -140,7 +141,7 @@ static int SetCapabilities(struct AppSpawnContent_ *content, AppSpawnClient *cli
|
||||
|
||||
// set capabilities
|
||||
isRet = capset(&cap_header, &cap_data[0]) == -1;
|
||||
APPSPAWN_CHECK(!isRet, return -errno, "capset failed: %d", errno);
|
||||
APPSPAWN_CHECK(!isRet, return -errno, "capset failed: %{public}d", errno);
|
||||
SetSelinuxCon(content, client);
|
||||
return 0;
|
||||
}
|
||||
@ -155,15 +156,15 @@ static void InitDebugParams(struct AppSpawnContent_ *content, AppSpawnClient *cl
|
||||
const char *debugSoPath = "/system/lib/libhidebug.so";
|
||||
#endif
|
||||
bool isRet = access(debugSoPath, F_OK) != 0;
|
||||
APPSPAWN_CHECK(!isRet, return, "access failed, errno = %d", errno);
|
||||
APPSPAWN_CHECK(!isRet, return, "access failed, errno = %{public}d", errno);
|
||||
|
||||
void *handle = dlopen(debugSoPath, RTLD_LAZY);
|
||||
APPSPAWN_CHECK(handle != NULL, return, "Failed to dlopen libhidebug.so, %s", dlerror());
|
||||
APPSPAWN_CHECK(handle != NULL, return, "Failed to dlopen libhidebug.so, %{public}s", dlerror());
|
||||
|
||||
bool (*initParam)(const char *name);
|
||||
initParam = (bool (*)(const char *name))dlsym(handle, "InitEnvironmentParam");
|
||||
APPSPAWN_CHECK(initParam != NULL, dlclose(handle);
|
||||
return, "Failed to dlsym InitEnvironmentParam, %s", dlerror());
|
||||
return, "Failed to dlsym InitEnvironmentParam, %{public}s", dlerror());
|
||||
(*initParam)(appProperty->property.processName);
|
||||
dlclose(handle);
|
||||
#endif
|
||||
@ -171,7 +172,7 @@ static void InitDebugParams(struct AppSpawnContent_ *content, AppSpawnClient *cl
|
||||
|
||||
static void ClearEnvironment(AppSpawnContent *content, AppSpawnClient *client)
|
||||
{
|
||||
APPSPAWN_LOGI("ClearEnvironment id %d", client->id);
|
||||
APPSPAWN_LOGI("ClearEnvironment id %{public}d", client->id);
|
||||
sigset_t mask;
|
||||
sigemptyset(&mask);
|
||||
sigaddset(&mask, SIGCHLD);
|
||||
@ -190,7 +191,8 @@ static int SetUidGid(struct AppSpawnContent_ *content, AppSpawnClient *client)
|
||||
AppSpawnClientExt *appProperty = (AppSpawnClientExt *)client;
|
||||
// set gids
|
||||
bool isRet = setgroups(appProperty->property.gidCount, (const gid_t *)(&appProperty->property.gidTable[0])) == -1;
|
||||
APPSPAWN_CHECK(!isRet, return -errno, "setgroups failed: %d, gids.size=%u", errno, appProperty->property.gidCount);
|
||||
APPSPAWN_CHECK(!isRet, return -errno,
|
||||
"setgroups failed: %{public}d, gids.size=%{public}u", errno, appProperty->property.gidCount);
|
||||
|
||||
if (client->cloneFlags & CLONE_NEWPID) {
|
||||
/* setresuid and setresgid have multi-thread synchronous operations.
|
||||
@ -199,23 +201,27 @@ static int SetUidGid(struct AppSpawnContent_ *content, AppSpawnClient *client)
|
||||
// set gid
|
||||
long ret = syscall(SYS_setresgid, appProperty->property.gid,
|
||||
appProperty->property.gid, appProperty->property.gid);
|
||||
APPSPAWN_CHECK(ret == 0, return -errno, "setgid(%u) failed: %d", appProperty->property.gid, errno);
|
||||
APPSPAWN_CHECK(ret == 0, return -errno,
|
||||
"setgid(%{public}u) failed: %{public}d", appProperty->property.gid, errno);
|
||||
|
||||
/* If the effective user ID is changed from 0 to nonzero,
|
||||
* then all capabilities are cleared from the effective set
|
||||
*/
|
||||
ret = syscall(SYS_setresuid, appProperty->property.uid, appProperty->property.uid, appProperty->property.uid);
|
||||
APPSPAWN_CHECK(ret == 0, return -errno, "setuid(%u) failed: %d", appProperty->property.uid, errno);
|
||||
APPSPAWN_CHECK(ret == 0, return -errno,
|
||||
"setuid(%{public}u) failed: %{public}d", appProperty->property.uid, errno);
|
||||
} else {
|
||||
// set gid
|
||||
isRet = setresgid(appProperty->property.gid, appProperty->property.gid, appProperty->property.gid) == -1;
|
||||
APPSPAWN_CHECK(!isRet, return -errno, "setgid(%u) failed: %d", appProperty->property.gid, errno);
|
||||
APPSPAWN_CHECK(!isRet, return -errno,
|
||||
"setgid(%{public}u) failed: %{public}d", appProperty->property.gid, errno);
|
||||
|
||||
/* If the effective user ID is changed from 0 to nonzero,
|
||||
* then all capabilities are cleared from the effective set
|
||||
*/
|
||||
isRet = setresuid(appProperty->property.uid, appProperty->property.uid, appProperty->property.uid) == -1;
|
||||
APPSPAWN_CHECK(!isRet, return -errno, "setuid(%u) failed: %d", appProperty->property.uid, errno);
|
||||
APPSPAWN_CHECK(!isRet, return -errno,
|
||||
"setuid(%{public}u) failed: %{public}d", appProperty->property.uid, errno);
|
||||
}
|
||||
#endif
|
||||
if ((appProperty->property.flags & APP_DEBUGGABLE) != 0) {
|
||||
@ -224,7 +230,7 @@ static int SetUidGid(struct AppSpawnContent_ *content, AppSpawnClient *client)
|
||||
setenv("HAP_DEBUGGABLE", "true", 1);
|
||||
#endif
|
||||
if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
|
||||
APPSPAWN_LOGE("Failed to set app dumpable: %s", strerror(errno));
|
||||
APPSPAWN_LOGE("Failed to set app dumpable: %{public}s", strerror(errno));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -241,25 +247,25 @@ static int32_t SetFileDescriptors(struct AppSpawnContent_ *content, AppSpawnClie
|
||||
// redirect to /dev/null
|
||||
int dev_null_fd = open(DEVICE_NULL_STR, O_RDWR);
|
||||
if (dev_null_fd == -1) {
|
||||
APPSPAWN_LOGE("open dev_null error: %d", errno);
|
||||
APPSPAWN_LOGE("open dev_null error: %{public}d", errno);
|
||||
return (-errno);
|
||||
}
|
||||
|
||||
// stdin
|
||||
if (dup2(dev_null_fd, STDIN_FILENO) == -1) {
|
||||
APPSPAWN_LOGE("dup2 STDIN error: %d", errno);
|
||||
APPSPAWN_LOGE("dup2 STDIN error: %{public}d", errno);
|
||||
return (-errno);
|
||||
};
|
||||
|
||||
// stdout
|
||||
if (dup2(dev_null_fd, STDOUT_FILENO) == -1) {
|
||||
APPSPAWN_LOGE("dup2 STDOUT error: %d", errno);
|
||||
APPSPAWN_LOGE("dup2 STDOUT error: %{public}d", errno);
|
||||
return (-errno);
|
||||
};
|
||||
|
||||
// stderr
|
||||
if (dup2(dev_null_fd, STDERR_FILENO) == -1) {
|
||||
APPSPAWN_LOGE("dup2 STDERR error: %d", errno);
|
||||
APPSPAWN_LOGE("dup2 STDERR error: %{public}d", errno);
|
||||
return (-errno);
|
||||
};
|
||||
#endif
|
||||
@ -297,8 +303,8 @@ static int GetWrapBundleNameValue(struct AppSpawnContent_ *content, AppSpawnClie
|
||||
|
||||
int ret = GetParameter(wrapBundleNameKey, "", wrapBundleNameValue, WRAP_VALUE_MAX_LENGTH);
|
||||
APPSPAWN_CHECK(ret > 0 && (!strcmp(wrapBundleNameValue, "asan_wrapper")), return -1,
|
||||
"Not wrap %s.", appProperty->bundleName);
|
||||
APPSPAWN_LOGI("Asan: GetParameter %s the value is %s.", wrapBundleNameKey, wrapBundleNameValue);
|
||||
"Not wrap %{public}s.", appProperty->bundleName);
|
||||
APPSPAWN_LOGI("Asan: GetParameter %{public}s the value is %{public}s.", wrapBundleNameKey, wrapBundleNameValue);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@ -306,7 +312,7 @@ static int GetWrapBundleNameValue(struct AppSpawnContent_ *content, AppSpawnClie
|
||||
static int ColdStartApp(struct AppSpawnContent_ *content, AppSpawnClient *client)
|
||||
{
|
||||
AppParameter *appProperty = &((AppSpawnClientExt *)client)->property;
|
||||
APPSPAWN_LOGI("ColdStartApp::appName %s", appProperty->processName);
|
||||
APPSPAWN_LOGI("ColdStartApp::appName %{public}s", appProperty->processName);
|
||||
char buffer[32] = {0}; // 32 buffer for fd
|
||||
int len = sprintf_s(buffer, sizeof(buffer), "%d", ((AppSpawnClientExt *)client)->fd[1]);
|
||||
APPSPAWN_CHECK(len > 0, return -1, "Invalid to format fd");
|
||||
@ -374,7 +380,7 @@ static int ColdStartApp(struct AppSpawnContent_ *content, AppSpawnClient *client
|
||||
ret = -1;
|
||||
#endif
|
||||
if (ret) {
|
||||
APPSPAWN_LOGE("Failed to execv, errno = %d", errno);
|
||||
APPSPAWN_LOGE("Failed to execv, errno = %{public}d", errno);
|
||||
}
|
||||
}
|
||||
Free(argv, &appProperty->hspList);
|
||||
@ -383,10 +389,10 @@ static int ColdStartApp(struct AppSpawnContent_ *content, AppSpawnClient *client
|
||||
|
||||
int GetAppSpawnClientFromArg(int argc, char *const argv[], AppSpawnClientExt *client)
|
||||
{
|
||||
APPSPAWN_CHECK(argv != NULL && argc > PARAM_INDEX, return -1, "Invalid argv argc %d", argc);
|
||||
APPSPAWN_CHECK(argv != NULL && argc > PARAM_INDEX, return -1, "Invalid argv argc %{public}d", argc);
|
||||
|
||||
client->fd[1] = atoi(argv[FD_INDEX]);
|
||||
APPSPAWN_LOGV("GetAppSpawnClientFromArg %s ", argv[PARAM_INDEX]);
|
||||
APPSPAWN_LOGV("GetAppSpawnClientFromArg %{public}s ", argv[PARAM_INDEX]);
|
||||
char *end = NULL;
|
||||
char *start = strtok_r(argv[PARAM_INDEX], ":", &end);
|
||||
|
||||
|
@ -72,7 +72,7 @@ static void AppInfoHashNodeFree(const HashNode *node, void *context)
|
||||
{
|
||||
(void)context;
|
||||
AppInfo *testNode = HASHMAP_ENTRY(node, AppInfo, node);
|
||||
APPSPAWN_LOGI("AppInfoHashNodeFree %s\n", testNode->name);
|
||||
APPSPAWN_LOGI("AppInfoHashNodeFree %{public}s\n", testNode->name);
|
||||
free(testNode);
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ APPSPAWN_STATIC void AddAppInfo(pid_t pid, const char *processName)
|
||||
ret = OH_HashMapAdd(g_appSpawnContent->appMap, &node->node);
|
||||
APPSPAWN_CHECK(ret == 0, free(node);
|
||||
return, "Failed to add appinfo to hash");
|
||||
APPSPAWN_LOGI("Add %s, pid=%d success", processName, pid);
|
||||
APPSPAWN_LOGI("Add %{public}s, pid=%{public}d success", processName, pid);
|
||||
}
|
||||
|
||||
APPSPAWN_STATIC void ProcessTimer(const TimerHandle taskHandle, void *context)
|
||||
@ -103,9 +103,9 @@ APPSPAWN_STATIC void ProcessTimer(const TimerHandle taskHandle, void *context)
|
||||
static void RemoveAppInfo(pid_t pid)
|
||||
{
|
||||
HashNode *node = OH_HashMapGet(g_appSpawnContent->appMap, (const void *)&pid);
|
||||
APPSPAWN_CHECK(node != NULL, return, "Invalid node %d", pid);
|
||||
APPSPAWN_CHECK(node != NULL, return, "Invalid node %{public}d", pid);
|
||||
AppInfo *appInfo = HASHMAP_ENTRY(node, AppInfo, node);
|
||||
APPSPAWN_CHECK(appInfo != NULL, return, "Invalid node %d", pid);
|
||||
APPSPAWN_CHECK(appInfo != NULL, return, "Invalid node %{public}d", pid);
|
||||
OH_HashMapRemove(g_appSpawnContent->appMap, (const void *)&pid);
|
||||
free(appInfo);
|
||||
if ((g_appSpawnContent->flags & FLAGS_ON_DEMAND) != FLAGS_ON_DEMAND) {
|
||||
@ -124,7 +124,7 @@ static void KillProcess(const HashNode *node, const void *context)
|
||||
{
|
||||
AppInfo *hashNode = (AppInfo *)node;
|
||||
kill(hashNode->pid, SIGKILL);
|
||||
APPSPAWN_LOGI("kill app, pid = %d, processName = %s", hashNode->pid, hashNode->name);
|
||||
APPSPAWN_LOGI("kill app, pid = %{public}d, processName = %{public}s", hashNode->pid, hashNode->name);
|
||||
}
|
||||
|
||||
static void OnClose(const TaskHandle taskHandle)
|
||||
@ -136,11 +136,11 @@ static void SendMessageComplete(const TaskHandle taskHandle, BufferHandle handle
|
||||
{
|
||||
AppSpawnClientExt *client = (AppSpawnClientExt *)LE_GetUserData(taskHandle);
|
||||
APPSPAWN_CHECK(client != NULL, return, "Failed to get client");
|
||||
APPSPAWN_LOGI("SendMessageComplete client.id %d result %d pid %d",
|
||||
APPSPAWN_LOGI("SendMessageComplete client.id %{public}d result %{public}d pid %{public}d",
|
||||
client->client.id, LE_GetSendResult(handle), client->pid);
|
||||
if (LE_GetSendResult(handle) != 0 && client->pid > 0) {
|
||||
kill(client->pid, SIGKILL);
|
||||
APPSPAWN_LOGI("Send message fail err:%d kill app [ %d %s]",
|
||||
APPSPAWN_LOGI("Send message fail err:%{public}d kill app [ %{public}d %{public}s]",
|
||||
LE_GetSendResult(handle), client->pid, client->property.bundleName);
|
||||
}
|
||||
}
|
||||
@ -159,15 +159,17 @@ static int SendResponse(AppSpawnClientExt *client, const char *buff, size_t buff
|
||||
static void PrintProcessExitInfo(pid_t pid, uid_t uid, int status)
|
||||
{
|
||||
HashNode *node = OH_HashMapGet(g_appSpawnContent->appMap, (const void *)&pid);
|
||||
APPSPAWN_CHECK(node != NULL, return, "Handle SIGCHLD from pid:%d status:%d", pid, status);
|
||||
APPSPAWN_CHECK(node != NULL, return, "Handle SIGCHLD from pid:%{public}d status:%{public}d", pid, status);
|
||||
AppInfo *appInfo = HASHMAP_ENTRY(node, AppInfo, node);
|
||||
APPSPAWN_CHECK(appInfo != NULL, return, "Handle SIGCHLD from pid:%d status:%d", pid, status);
|
||||
APPSPAWN_CHECK(appInfo != NULL, return, "Handle SIGCHLD from pid:%{public}d status:%{public}d", pid, status);
|
||||
|
||||
if (WIFSIGNALED(status)) {
|
||||
APPSPAWN_LOGW("%s with pid %d exit with signal:%d", appInfo->name, pid, WTERMSIG(status));
|
||||
APPSPAWN_LOGW("%{public}s with pid %{public}d exit with signal:%{public}d",
|
||||
appInfo->name, pid, WTERMSIG(status));
|
||||
}
|
||||
if (WIFEXITED(status)) {
|
||||
APPSPAWN_LOGW("%s with pid %d exit with code:%d", appInfo->name, pid, WEXITSTATUS(status));
|
||||
APPSPAWN_LOGW("%{public}s with pid %{public}d exit with code:%{public}d",
|
||||
appInfo->name, pid, WEXITSTATUS(status));
|
||||
}
|
||||
|
||||
ReportProcessExitInfo(appInfo->name, pid, uid, status);
|
||||
@ -176,7 +178,7 @@ static void PrintProcessExitInfo(pid_t pid, uid_t uid, int status)
|
||||
|
||||
static void HandleDiedPid(pid_t pid, uid_t uid, int status)
|
||||
{
|
||||
APPSPAWN_LOGI("SignalHandler pid %d status %d", pid, status);
|
||||
APPSPAWN_LOGI("SignalHandler pid %{public}d status %{public}d", pid, status);
|
||||
#ifdef REPORT_EVENT
|
||||
PrintProcessExitInfo(pid, uid, status);
|
||||
#endif
|
||||
@ -190,7 +192,7 @@ static void HandleDiedPid(pid_t pid, uid_t uid, int status)
|
||||
|
||||
APPSPAWN_STATIC void SignalHandler(const struct signalfd_siginfo *siginfo)
|
||||
{
|
||||
APPSPAWN_LOGI("SignalHandler signum %d", siginfo->ssi_signo);
|
||||
APPSPAWN_LOGI("SignalHandler signum %{public}d", siginfo->ssi_signo);
|
||||
switch (siginfo->ssi_signo) {
|
||||
case SIGCHLD: { // delete pid from app map
|
||||
pid_t pid;
|
||||
@ -206,7 +208,7 @@ APPSPAWN_STATIC void SignalHandler(const struct signalfd_siginfo *siginfo)
|
||||
break;
|
||||
}
|
||||
default:
|
||||
APPSPAWN_LOGI("SigHandler, unsupported signal %d.", siginfo->ssi_signo);
|
||||
APPSPAWN_LOGI("SigHandler, unsupported signal %{public}d.", siginfo->ssi_signo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -249,10 +251,11 @@ static int WaitChild(int fd, int pid, const AppSpawnClientExt *appProperty)
|
||||
|
||||
int ret = select(fd + 1, &rd, NULL, NULL, &tv);
|
||||
if (ret == 0) { // timeout
|
||||
APPSPAWN_LOGI("Time out for child %s %d fd %d", appProperty->property.processName, pid, fd);
|
||||
APPSPAWN_LOGI("Time out for child %{public}s %{public}d fd %{public}d",
|
||||
appProperty->property.processName, pid, fd);
|
||||
result = 0;
|
||||
} else if (ret == -1) {
|
||||
APPSPAWN_LOGI("Error for child %s %d", appProperty->property.processName, pid);
|
||||
APPSPAWN_LOGI("Error for child %{public}s %{public}d", appProperty->property.processName, pid);
|
||||
result = 0;
|
||||
} else {
|
||||
(void)read(fd, &result, sizeof(result));
|
||||
@ -266,7 +269,7 @@ static void CheckColdAppEnabled(AppSpawnClientExt *appProperty)
|
||||
if ((appProperty->property.flags & 0x01) != 0) {
|
||||
char cold[10] = {0}; // 10 cold
|
||||
(void)GetParameter("startup.appspawn.cold.boot", "0", cold, sizeof(cold));
|
||||
APPSPAWN_LOGV("appspawn.cold.boot %s", cold);
|
||||
APPSPAWN_LOGV("appspawn.cold.boot %{public}s", cold);
|
||||
if (strcmp(cold, "1") == 0) {
|
||||
appProperty->client.flags |= APP_COLD_START;
|
||||
}
|
||||
@ -286,12 +289,13 @@ static int GetProcessTerminationStatusInner(int32_t pid, int *status)
|
||||
}
|
||||
|
||||
if (kill(pid, SIGKILL) != 0) {
|
||||
APPSPAWN_LOGE("unable to kill render process, pid: %d", pid);
|
||||
APPSPAWN_LOGE("unable to kill render process, pid: %{public}d", pid);
|
||||
}
|
||||
|
||||
pid_t exitPid = waitpid(pid, status, WNOHANG);
|
||||
if (exitPid != pid) {
|
||||
APPSPAWN_LOGE("waitpid failed, return : %d, pid: %d, status: %d", exitPid, pid, *status);
|
||||
APPSPAWN_LOGE("waitpid failed, return : %{public}d, pid: %{public}d, status: %{public}d",
|
||||
exitPid, pid, *status);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -308,7 +312,8 @@ static void GetProcessTerminationStatus(AppSpawnClientExt *appProperty)
|
||||
} else {
|
||||
SendResponse(appProperty, (char *)&exitStatus, sizeof(exitStatus));
|
||||
}
|
||||
APPSPAWN_LOGI("AppSpawnServer::get render process termination status, status = %d pid = %d uid %d %s %s",
|
||||
APPSPAWN_LOGI("AppSpawnServer::get render process termination status, \
|
||||
status = %{public}d pid = %{public}d uid %{public}d %{public}s %{public}s",
|
||||
exitStatus, appProperty->property.pid, appProperty->property.uid,
|
||||
appProperty->property.processName, appProperty->property.bundleName);
|
||||
}
|
||||
@ -335,18 +340,18 @@ static void FreeHspList(AppSpawnClientExt *client)
|
||||
APPSPAWN_STATIC bool ReceiveRequestData(const TaskHandle taskHandle, AppSpawnClientExt *client,
|
||||
const uint8_t *buffer, uint32_t buffLen)
|
||||
{
|
||||
APPSPAWN_LOGI("ReceiveRequestData: buffLen=%u", buffLen);
|
||||
APPSPAWN_LOGI("ReceiveRequestData: buffLen=%{public}u", buffLen);
|
||||
APPSPAWN_CHECK(buffer != NULL && buffLen > 0, LE_CloseTask(LE_GetDefaultLoop(), taskHandle);
|
||||
return false, "ReceiveRequestData: Invalid buff");
|
||||
|
||||
// 1. receive AppParamter
|
||||
if (client->property.hspList.totalLength == 0) {
|
||||
APPSPAWN_CHECK(buffLen >= sizeof(client->property), LE_CloseTask(LE_GetDefaultLoop(), taskHandle);
|
||||
return false, "ReceiveRequestData: Invalid buffLen %u", buffLen);
|
||||
return false, "ReceiveRequestData: Invalid buffLen %{public}u", buffLen);
|
||||
|
||||
int ret = memcpy_s(&client->property, sizeof(client->property), buffer, sizeof(client->property));
|
||||
APPSPAWN_CHECK(ret == 0, LE_CloseTask(LE_GetDefaultLoop(), taskHandle);
|
||||
return false, "ReceiveRequestData: memcpy failed %d:%u", ret, buffLen);
|
||||
return false, "ReceiveRequestData: memcpy failed %{public}d:%{public}u", ret, buffLen);
|
||||
|
||||
// reset hspList
|
||||
client->property.hspList.savedLength = 0;
|
||||
@ -359,10 +364,10 @@ APPSPAWN_STATIC bool ReceiveRequestData(const TaskHandle taskHandle, AppSpawnCli
|
||||
|
||||
// 2. check whether hspList exist
|
||||
if (client->property.hspList.totalLength == 0) { // no hspList
|
||||
APPSPAWN_LOGI("ReceiveRequestData: no hspList");
|
||||
APPSPAWN_LOGV("ReceiveRequestData: no hspList");
|
||||
return true;
|
||||
} else if (buffLen == 0) {
|
||||
APPSPAWN_LOGI("ReceiveRequestData: waiting for hspList");
|
||||
APPSPAWN_LOGV("ReceiveRequestData: waiting for hspList");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -377,10 +382,11 @@ APPSPAWN_STATIC bool ReceiveRequestData(const TaskHandle taskHandle, AppSpawnCli
|
||||
uint32_t saved = hspList->savedLength;
|
||||
uint32_t total = hspList->totalLength;
|
||||
char *data = hspList->data;
|
||||
APPSPAWN_LOGI("ReceiveRequestData: receiving hspList: (%u saved + %u incoming) / %u total", saved, buffLen, total);
|
||||
APPSPAWN_LOGV("Receiving hspList: (%{public}u saved + %{public}u incoming) / %{public}u total",
|
||||
saved, buffLen, total);
|
||||
|
||||
APPSPAWN_CHECK((total - saved) >= buffLen, FreeHspList(client); LE_CloseTask(LE_GetDefaultLoop(), taskHandle);
|
||||
return false, "ReceiveRequestData: too many data for hspList %u ", buffLen);
|
||||
return false, "ReceiveRequestData: too many data for hspList %{public}u ", buffLen);
|
||||
|
||||
int ret = memcpy_s(data + saved, buffLen, buffer, buffLen);
|
||||
APPSPAWN_CHECK(ret == 0, FreeHspList(client); LE_CloseTask(LE_GetDefaultLoop(), taskHandle);
|
||||
@ -415,7 +421,7 @@ static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer,
|
||||
|
||||
APPSPAWN_CHECK(appProperty->property.gidCount <= APP_MAX_GIDS && strlen(appProperty->property.processName) > 0,
|
||||
LE_CloseTask(LE_GetDefaultLoop(), taskHandle); FreeHspList(appProperty);
|
||||
return, "Invalid property %u", appProperty->property.gidCount);
|
||||
return, "Invalid property %{public}u", appProperty->property.gidCount);
|
||||
// special handle bundle name medialibrary and scanner
|
||||
HandleSpecial(appProperty);
|
||||
SetInternetPermission(appProperty);
|
||||
@ -427,13 +433,13 @@ static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer,
|
||||
CheckColdAppEnabled(appProperty);
|
||||
// create pipe for commication from child
|
||||
if (pipe(appProperty->fd) == -1) {
|
||||
APPSPAWN_LOGE("create pipe fail, errno = %d", errno);
|
||||
APPSPAWN_LOGE("create pipe fail, errno = %{public}d", errno);
|
||||
LE_CloseTask(LE_GetDefaultLoop(), taskHandle);
|
||||
FreeHspList(appProperty);
|
||||
return;
|
||||
}
|
||||
|
||||
APPSPAWN_LOGI("OnReceiveRequest client.id %d appProperty %d processname %s buffLen %d flags 0x%x",
|
||||
APPSPAWN_LOGI("Client.id %{public}d appProperty %{public}d processname %{public}s buffLen %{public}d flags 0x%x",
|
||||
appProperty->client.id, appProperty->property.uid, appProperty->property.processName,
|
||||
buffLen, appProperty->property.flags);
|
||||
fcntl(appProperty->fd[0], F_SETFL, O_NONBLOCK);
|
||||
@ -449,7 +455,7 @@ static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer,
|
||||
}
|
||||
close(appProperty->fd[0]);
|
||||
close(appProperty->fd[1]);
|
||||
APPSPAWN_LOGI("child process %s %s pid %d",
|
||||
APPSPAWN_LOGI("child process %{public}s %{public}s pid %{public}d",
|
||||
appProperty->property.processName, (result == 0) ? "success" : "fail", appProperty->pid);
|
||||
if (result == 0) {
|
||||
AddAppInfo(appProperty->pid, appProperty->property.processName);
|
||||
@ -482,7 +488,7 @@ APPSPAWN_STATIC TaskHandle AcceptClient(const LoopHandle loopHandle, const TaskH
|
||||
socklen_t credSize = sizeof(struct ucred);
|
||||
if ((getsockopt(LE_GetSocketFd(stream), SOL_SOCKET, SO_PEERCRED, &cred, &credSize) < 0) ||
|
||||
(cred.uid != DecodeUid("foundation") && cred.uid != DecodeUid("root"))) {
|
||||
APPSPAWN_LOGE("Failed to check uid %d", cred.uid);
|
||||
APPSPAWN_LOGE("Failed to check uid %{public}d", cred.uid);
|
||||
LE_CloseStreamTask(LE_GetDefaultLoop(), stream);
|
||||
return NULL;
|
||||
}
|
||||
@ -496,7 +502,7 @@ APPSPAWN_STATIC TaskHandle AcceptClient(const LoopHandle loopHandle, const TaskH
|
||||
client->property.hspList.totalLength = 0;
|
||||
client->property.hspList.savedLength = 0;
|
||||
client->property.hspList.data = NULL;
|
||||
APPSPAWN_LOGI("OnConnection client fd %d Id %d", LE_GetSocketFd(stream), client->client.id);
|
||||
APPSPAWN_LOGI("OnConnection client fd %{public}d Id %{public}d", LE_GetSocketFd(stream), client->client.id);
|
||||
return stream;
|
||||
}
|
||||
|
||||
@ -511,7 +517,8 @@ static void NotifyResToParent(struct AppSpawnContent_ *content, AppSpawnClient *
|
||||
{
|
||||
AppSpawnClientExt *appProperty = (AppSpawnClientExt *)client;
|
||||
int fd = appProperty->fd[1];
|
||||
APPSPAWN_LOGI("NotifyResToParent %s fd %d result %d", appProperty->property.processName, fd, result);
|
||||
APPSPAWN_LOGI("NotifyResToParent %{public}s fd %{public}d result %{public}d",
|
||||
appProperty->property.processName, fd, result);
|
||||
write(appProperty->fd[1], &result, sizeof(result));
|
||||
// close write
|
||||
close(fd);
|
||||
@ -551,15 +558,15 @@ void AppSpawnColdRun(AppSpawnContent *content, int argc, char *const argv[])
|
||||
int ret = GetAppSpawnClientFromArg(argc, argv, client);
|
||||
APPSPAWN_CHECK(ret == 0, free(client);
|
||||
return, "Failed to get client from arg");
|
||||
APPSPAWN_LOGI("Cold running %d processName %s %u ", getpid(), client->property.processName,
|
||||
content->longProcNameLen);
|
||||
APPSPAWN_LOGI("Cold running %{public}d processName %{public}s %{public}u ",
|
||||
getpid(), client->property.processName, content->longProcNameLen);
|
||||
|
||||
ret = DoStartApp(content, &client->client, content->longProcName, content->longProcNameLen);
|
||||
if (ret == 0 && content->runChildProcessor != NULL) {
|
||||
content->runChildProcessor(content, &client->client);
|
||||
}
|
||||
|
||||
APPSPAWN_LOGI("App exit %d.", getpid());
|
||||
APPSPAWN_LOGI("App exit %{public}d.", getpid());
|
||||
free(client);
|
||||
free(appSpawnContent);
|
||||
g_appSpawnContent = NULL;
|
||||
@ -614,9 +621,9 @@ static int CreateAppSpawnServer(AppSpawnContentExt *appSpawnContent, const char
|
||||
{
|
||||
char path[128] = {0}; // 128 max path
|
||||
int ret = snprintf_s(path, sizeof(path), sizeof(path) - 1, "%s%s", SOCKET_DIR, socketName);
|
||||
APPSPAWN_CHECK(ret >= 0, return -1, "Failed to snprintf_s %d", ret);
|
||||
APPSPAWN_CHECK(ret >= 0, return -1, "Failed to snprintf_s %{public}d", ret);
|
||||
int socketId = GetControlSocket(socketName);
|
||||
APPSPAWN_LOGI("get socket form env %s socketId %d", socketName, socketId);
|
||||
APPSPAWN_LOGI("get socket form env %{public}s socketId %{public}d", socketName, socketId);
|
||||
APPSPAWN_CHECK_ONLY_EXPER(socketId <= 0, appSpawnContent->flags |= FLAGS_ON_DEMAND);
|
||||
|
||||
CheckAndCreateDir(path);
|
||||
@ -628,15 +635,16 @@ static int CreateAppSpawnServer(AppSpawnContentExt *appSpawnContent, const char
|
||||
info.incommingConnect = OnConnection;
|
||||
|
||||
ret = LE_CreateStreamServer(LE_GetDefaultLoop(), &appSpawnContent->server, &info);
|
||||
APPSPAWN_CHECK(ret == 0, return -1, "Failed to create socket for %s", path);
|
||||
APPSPAWN_CHECK(ret == 0, return -1, "Failed to create socket for %{public}s", path);
|
||||
// create socket
|
||||
ret = chmod(path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
APPSPAWN_CHECK(ret == 0, return -1, "Failed to chmod %s, err %d. ", path, errno);
|
||||
APPSPAWN_CHECK(ret == 0, return -1, "Failed to chmod %{public}s, err %{public}d. ", path, errno);
|
||||
#ifndef APPSPAWN_CHECK_GID_UID
|
||||
ret = lchown(path, 0, 4000); // 4000 is appspawn gid
|
||||
APPSPAWN_CHECK(ret == 0, return -1, "Failed to lchown %s, err %d. ", path, errno);
|
||||
APPSPAWN_CHECK(ret == 0, return -1, "Failed to lchown %{public}s, err %{public}d. ", path, errno);
|
||||
#endif
|
||||
APPSPAWN_LOGI("CreateAppSpawnServer path %s fd %d", path, LE_GetSocketFd(appSpawnContent->server));
|
||||
APPSPAWN_LOGI("CreateAppSpawnServer path %{public}s fd %{public}d",
|
||||
path, LE_GetSocketFd(appSpawnContent->server));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -644,7 +652,7 @@ AppSpawnContent *AppSpawnCreateContent(const char *socketName, char *longProcNam
|
||||
{
|
||||
APPSPAWN_CHECK(LE_GetDefaultLoop() != NULL, return NULL, "Invalid default loop");
|
||||
APPSPAWN_CHECK(socketName != NULL && longProcName != NULL, return NULL, "Invalid name");
|
||||
APPSPAWN_LOGI("AppSpawnCreateContent %s %u mode %d", socketName, longProcNameLen, mode);
|
||||
APPSPAWN_LOGI("AppSpawnCreateContent %{public}s %{public}u mode %{public}d", socketName, longProcNameLen, mode);
|
||||
|
||||
AppSpawnContentExt *appSpawnContent = (AppSpawnContentExt *)malloc(sizeof(AppSpawnContentExt));
|
||||
APPSPAWN_CHECK(appSpawnContent != NULL, return NULL, "Failed to alloc memory for appspawn");
|
||||
|
@ -30,8 +30,6 @@ int main(int argc, char *const argv[])
|
||||
(void)signal(SIGPIPE, SIG_IGN);
|
||||
uint32_t argvSize = 0;
|
||||
int mode = 0;
|
||||
int32_t loglevel = GetIntParameter("persist.init.debug.loglevel", INIT_ERROR);
|
||||
SetInitLogLevel(loglevel);
|
||||
if ((argc > PARAM_INDEX) && (strcmp(argv[START_INDEX], "cold-start") == 0)) {
|
||||
argvSize = APP_LEN_PROC_NAME;
|
||||
mode = 1;
|
||||
@ -49,10 +47,10 @@ int main(int argc, char *const argv[])
|
||||
int isRet = memset_s(argv[0], argvSize, 0, (size_t)argvSize) != EOK;
|
||||
APPSPAWN_CHECK(!isRet, return -EINVAL, "Failed to memset argv[0]");
|
||||
isRet = strncpy_s(argv[0], argvSize, APPSPAWN_SERVER_NAME, strlen(APPSPAWN_SERVER_NAME)) != EOK;
|
||||
APPSPAWN_CHECK(!isRet, return -EINVAL, "strncpy_s appspawn server name error: %d", errno);
|
||||
APPSPAWN_CHECK(!isRet, return -EINVAL, "strncpy_s appspawn server name error: %{public}d", errno);
|
||||
}
|
||||
|
||||
APPSPAWN_LOGI("AppSpawnCreateContent argc %d mode %d %u", argc, mode, argvSize);
|
||||
APPSPAWN_LOGI("AppSpawnCreateContent argc %{public}d mode %{public}d %{public}u", argc, mode, argvSize);
|
||||
AppSpawnContent *content = AppSpawnCreateContent(APPSPAWN_SOCKET_NAME, argv[0], argvSize, mode);
|
||||
APPSPAWN_CHECK(content != NULL, return -1, "Invalid content for appspawn");
|
||||
APPSPAWN_CHECK(content->initAppSpawn != NULL, return -1, "Invalid content for appspawn");
|
||||
|
@ -44,7 +44,10 @@ unittest("AppSpawnLiteTest") {
|
||||
"app_spawn_lite_test.cpp",
|
||||
]
|
||||
|
||||
defines = [ "APPSPAWN_TEST" ]
|
||||
defines = [
|
||||
"APPSPAWN_TEST",
|
||||
"OHOS_LITE",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${aafwk_lite_path}/frameworks/ability_lite:aafwk_abilitykit_lite",
|
||||
|
@ -229,7 +229,7 @@ HWTEST_F(AppSpawnLiteTest, msgFuncFreeTest_002, TestSize.Level1)
|
||||
msgSt.capsCnt = MALLOC_TEST_LENGTH;
|
||||
FreeMessageSt(&msgSt);
|
||||
EXPECT_EQ(msgSt.capsCnt, 0);
|
||||
|
||||
|
||||
msgSt.uID = TEST_UID;
|
||||
FreeMessageSt(&msgSt);
|
||||
EXPECT_EQ(msgSt.uID, -1);
|
||||
@ -329,7 +329,7 @@ HWTEST_F(AppSpawnLiteTest, msgFuncSplitTest_001, TestSize.Level1)
|
||||
HWTEST_F(AppSpawnLiteTest, msgFuncSplitTest_002, TestSize.Level1)
|
||||
{
|
||||
MessageSt msgSt = {0};
|
||||
|
||||
|
||||
struct timespec tmStart = {0};
|
||||
GetCurrentTime(&tmStart);
|
||||
|
||||
@ -349,7 +349,7 @@ HWTEST_F(AppSpawnLiteTest, msgFuncSplitTest_002, TestSize.Level1)
|
||||
long timeUsed = (tmEnd.tv_sec - tmStart.tv_sec) * NANOSECONDS_PER_SECOND + (tmEnd.tv_nsec - tmStart.tv_nsec);
|
||||
printf("[----------] AppSpawnLiteTest, msgFuncSplitTest_002, total time %ld ns, strCnt %u.\n", \
|
||||
timeUsed, g_goodStrings.size());
|
||||
|
||||
|
||||
// parse one good string and check all results
|
||||
std::string validStr =
|
||||
"{\"bundleName\":\"validName\",\"identityID\":\"135\",\"uID\":999,\"gID\":888,\"capability\":[0, 1, 5]}";
|
||||
|
@ -34,12 +34,6 @@ public:
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void AppSpawnSocketTest::SetUpTestCase()
|
||||
{
|
||||
int32_t loglevel = GetIntParameter("persist.init.debug.loglevel", 0);
|
||||
SetInitLogLevel((InitLogLevel)loglevel);
|
||||
}
|
||||
|
||||
void AppSpawnSocketTest::TearDownTestCase()
|
||||
{}
|
||||
|
||||
|
@ -571,7 +571,7 @@ HWTEST(AppSpawnStandardTest, App_Spawn_Standard_07, TestSize.Level0)
|
||||
clock_gettime(CLOCK_REALTIME, &tmStart);
|
||||
tmStart.tv_nsec += 100000000; // 100000000 for test
|
||||
long long diff = DiffTime(&tmStart);
|
||||
APPSPAWN_LOGI("App timeused %d %lld ns.", getpid(), diff);
|
||||
APPSPAWN_LOGI("App timeused %{public}d %{public}lld ns.", getpid(), diff);
|
||||
|
||||
GTEST_LOG_(INFO) << "App_Spawn_Standard_07 end";
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ bool JsonUtils::GetStringFromJson(const nlohmann::json &json, const std::string
|
||||
bool isRet = json.find(key) != json.end() && json.at(key).is_string();
|
||||
if (isRet) {
|
||||
value = json.at(key).get<std::string>();
|
||||
APPSPAWN_LOGI("Find key[%s] : %s successful.", key.c_str(), value.c_str());
|
||||
APPSPAWN_LOGI("Find key[%{public}s] : %{public}s successful.", key.c_str(), value.c_str());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -187,7 +187,7 @@ static void MakeDirRecursive(const std::string &path, mode_t mode)
|
||||
std::string dir = path.substr(0, index);
|
||||
#ifndef APPSPAWN_TEST
|
||||
APPSPAWN_CHECK(!(access(dir.c_str(), F_OK) < 0 && mkdir(dir.c_str(), mode) < 0),
|
||||
return, "error is %d, mkdir %s failed", errno, dir.c_str());
|
||||
return, "error is %{public}d, mkdir %{public}s failed", errno, dir.c_str());
|
||||
#endif
|
||||
} while (index < size);
|
||||
}
|
||||
@ -202,10 +202,11 @@ int32_t SandboxUtils::DoAppSandboxMountOnce(const char *originPath, const char *
|
||||
int ret = 0;
|
||||
// to mount fs and bind mount files or directory
|
||||
ret = mount(originPath, destinationPath, fsType, mountFlags, options);
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "errno is: %d, bind mount %s to %s failed, just DEBUG MESSAGE here",
|
||||
errno, originPath, destinationPath);
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "errno is: %{public}d, bind mount %{public}s to %{public}s failed",
|
||||
errno, originPath, destinationPath);
|
||||
ret = mount(NULL, destinationPath, NULL, MS_SLAVE, NULL);
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "errno is: %d, private mount to %s failed", errno, destinationPath);
|
||||
APPSPAWN_CHECK(ret == 0, return ret,
|
||||
"errno is: %{public}d, private mount to %{public}s failed", errno, destinationPath);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@ -321,7 +322,7 @@ std::string SandboxUtils::GetSbxPathByConfig(const ClientSocket::AppProperty *ap
|
||||
} else {
|
||||
sandboxRoot = g_sandBoxDir + appProperty->bundleName;
|
||||
APPSPAWN_LOGE("read sandbox-root config failed, set sandbox-root to default root"
|
||||
"app name is %s", appProperty->bundleName);
|
||||
"app name is %{public}s", appProperty->bundleName);
|
||||
}
|
||||
|
||||
return sandboxRoot;
|
||||
@ -347,7 +348,7 @@ static bool CheckMountConfig(nlohmann::json &mntPoint, const ClientSocket::AppPr
|
||||
{
|
||||
bool istrue = mntPoint.find(g_srcPath) == mntPoint.end() || mntPoint.find(g_sandBoxPath) == mntPoint.end()
|
||||
|| mntPoint.find(g_sandBoxFlags) == mntPoint.end();
|
||||
APPSPAWN_CHECK(!istrue, return false, "read mount config failed, app name is %s", appProperty->bundleName);
|
||||
APPSPAWN_CHECK(!istrue, return false, "read mount config failed, app name is %{public}s", appProperty->bundleName);
|
||||
|
||||
if (mntPoint[g_appAplName] != nullptr) {
|
||||
std::string app_apl_name = mntPoint[g_appAplName].get<std::string>();
|
||||
@ -375,11 +376,11 @@ static int32_t DoDlpAppMountStrategy(const ClientSocket::AppProperty *appPropert
|
||||
const std::string &fsType, unsigned long mountFlags)
|
||||
{
|
||||
int fd = open("/dev/fuse", O_RDWR);
|
||||
APPSPAWN_CHECK(fd != -1, return -EINVAL, "open /dev/fuse failed, errno is %d", errno);
|
||||
APPSPAWN_CHECK(fd != -1, return -EINVAL, "open /dev/fuse failed, errno is %{public}d", errno);
|
||||
|
||||
char options[FUSE_OPTIONS_MAX_LEN];
|
||||
(void)sprintf_s(options, sizeof(options), "fd=%d,rootmode=40000,user_id=%d,group_id=%d,allow_other", fd,
|
||||
appProperty->uid, appProperty->gid);
|
||||
appProperty->uid, appProperty->gid);
|
||||
|
||||
// To make sure destinationPath exist
|
||||
MakeDirRecursive(sandboxPath, FILE_MODE);
|
||||
@ -387,16 +388,17 @@ static int32_t DoDlpAppMountStrategy(const ClientSocket::AppProperty *appPropert
|
||||
int ret = 0;
|
||||
#ifndef APPSPAWN_TEST
|
||||
ret = mount(srcPath.c_str(), sandboxPath.c_str(), fsType.c_str(), mountFlags, options);
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "DoDlpAppMountStrategy failed, bind mount %s to %s"
|
||||
"failed %d", srcPath.c_str(), sandboxPath.c_str(), errno);
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "DoDlpAppMountStrategy failed, bind mount %{public}s to %{public}s"
|
||||
"failed %{public}d", srcPath.c_str(), sandboxPath.c_str(), errno);
|
||||
|
||||
ret = mount(NULL, sandboxPath.c_str(), NULL, MS_PRIVATE, NULL);
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "errno is: %d, private mount to %s failed", errno, sandboxPath.c_str());
|
||||
APPSPAWN_CHECK(ret == 0, return ret,
|
||||
"errno is: %{public}d, private mount to %{public}s failed", errno, sandboxPath.c_str());
|
||||
#endif
|
||||
/* close DLP_FUSE_FD and dup FD to it */
|
||||
close(DLP_FUSE_FD);
|
||||
ret = dup2(fd, DLP_FUSE_FD);
|
||||
APPSPAWN_CHECK_ONLY_LOG(ret != -1, "dup fuse fd %d failed, errno is %d", fd, errno);
|
||||
APPSPAWN_CHECK_ONLY_LOG(ret != -1, "dup fuse fd %{public}d failed, errno is %{public}d", fd, errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -472,7 +474,7 @@ void SandboxUtils::CheckAndPrepareSrcPath(const ClientSocket::AppProperty *appPr
|
||||
chown(srcPath.c_str(), appProperty->uid, DATABASE_DIR_GID);
|
||||
SetSelinuxCondition(srcPath, appProperty);
|
||||
} else {
|
||||
APPSPAWN_LOGI("failed to access path: %s", srcPath.c_str());
|
||||
APPSPAWN_LOGI("failed to access path: %{public}s", srcPath.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@ -487,7 +489,7 @@ void SandboxUtils::CheckAndPrepareSrcPath(const ClientSocket::AppProperty *appPr
|
||||
chmod(srcPath.c_str(), DATABASE_FOLDER_FILE_MODE | S_ISGID);
|
||||
chown(srcPath.c_str(), appProperty->uid, DFS_GID);
|
||||
} else {
|
||||
APPSPAWN_LOGI("failed to access path: %s", srcPath.c_str());
|
||||
APPSPAWN_LOGI("failed to access path: %{public}s", srcPath.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -496,7 +498,7 @@ int SandboxUtils::DoAllMntPointsMount(const ClientSocket::AppProperty *appProper
|
||||
{
|
||||
std::string bundleName = appProperty->bundleName;
|
||||
if (appConfig.find(g_mountPrefix) == appConfig.end()) {
|
||||
APPSPAWN_LOGV("mount config is not found, app name is %s", bundleName.c_str());
|
||||
APPSPAWN_LOGV("mount config is not found, app name is %{public}s", bundleName.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -544,7 +546,7 @@ int SandboxUtils::DoAllMntPointsMount(const ClientSocket::AppProperty *appProper
|
||||
std::string actionStatus = g_statusCheck;
|
||||
(void)JsonUtils::GetStringFromJson(mntPoint, g_actionStatuc, actionStatus);
|
||||
if (actionStatus == g_statusCheck) {
|
||||
APPSPAWN_LOGE("DoAppSandboxMountOnce failed, %s", sandboxPath.c_str());
|
||||
APPSPAWN_LOGE("DoAppSandboxMountOnce failed, %{public}s", sandboxPath.c_str());
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@ -558,7 +560,7 @@ int SandboxUtils::DoAllMntPointsMount(const ClientSocket::AppProperty *appProper
|
||||
int SandboxUtils::DoAllSymlinkPointslink(const ClientSocket::AppProperty *appProperty, nlohmann::json &appConfig)
|
||||
{
|
||||
APPSPAWN_CHECK(appConfig.find(g_symlinkPrefix) != appConfig.end(), return 0, "symlink config is not found,"
|
||||
"maybe reuslt sandbox launch failed app name is %s", appProperty->bundleName);
|
||||
"maybe result sandbox launch failed app name is %{public}s", appProperty->bundleName);
|
||||
|
||||
nlohmann::json symlinkPoints = appConfig[g_symlinkPrefix];
|
||||
std::string sandboxRoot = GetSbxPathByConfig(appProperty, appConfig);
|
||||
@ -569,17 +571,17 @@ int SandboxUtils::DoAllSymlinkPointslink(const ClientSocket::AppProperty *appPro
|
||||
|
||||
// Check the validity of the symlink configuration
|
||||
if (symPoint.find(g_targetName) == symPoint.end() || symPoint.find(g_linkName) == symPoint.end()) {
|
||||
APPSPAWN_LOGE("read symlink config failed, app name is %s", appProperty->bundleName);
|
||||
APPSPAWN_LOGE("read symlink config failed, app name is %{public}s", appProperty->bundleName);
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string targetName = ConvertToRealPath(appProperty, symPoint[g_targetName].get<std::string>());
|
||||
std::string linkName = sandboxRoot + ConvertToRealPath(appProperty, symPoint[g_linkName].get<std::string>());
|
||||
APPSPAWN_LOGV("symlink, from %s to %s", targetName.c_str(), linkName.c_str());
|
||||
APPSPAWN_LOGV("symlink, from %{public}s to %{public}s", targetName.c_str(), linkName.c_str());
|
||||
|
||||
int ret = symlink(targetName.c_str(), linkName.c_str());
|
||||
if (ret && errno != EEXIST) {
|
||||
APPSPAWN_LOGE("errno is %d, symlink failed, %s", errno, linkName.c_str());
|
||||
APPSPAWN_LOGE("errno is %{public}d, symlink failed, %{public}s", errno, linkName.c_str());
|
||||
|
||||
std::string actionStatus = g_statusCheck;
|
||||
(void)JsonUtils::GetStringFromJson(symPoint, g_actionStatuc, actionStatus);
|
||||
@ -636,7 +638,7 @@ int32_t SandboxUtils::HandleFlagsPoint(const ClientSocket::AppProperty *appPrope
|
||||
return DoAllMntPointsMount(appProperty, flagPoint);
|
||||
}
|
||||
} else {
|
||||
APPSPAWN_LOGE("read flags config failed, app name is %s", appProperty->bundleName);
|
||||
APPSPAWN_LOGE("read flags config failed, app name is %{public}s", appProperty->bundleName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -730,13 +732,13 @@ int32_t SandboxUtils::SetRenderSandboxProperty(const ClientSocket::AppProperty *
|
||||
|
||||
if (privateAppConfig.find(g_ohosRender) != privateAppConfig.end()) {
|
||||
int ret = DoAllMntPointsMount(appProperty, privateAppConfig[g_ohosRender][0]);
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "DoAllMntPointsMount failed, %s",
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "DoAllMntPointsMount failed, %{public}s",
|
||||
appProperty->bundleName);
|
||||
ret = DoAllSymlinkPointslink(appProperty, privateAppConfig[g_ohosRender][0]);
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "DoAllSymlinkPointslink failed, %s",
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "DoAllSymlinkPointslink failed, %{public}s",
|
||||
appProperty->bundleName);
|
||||
ret = HandleFlagsPoint(appProperty, privateAppConfig[g_ohosRender][0]);
|
||||
APPSPAWN_CHECK_ONLY_LOG(ret == 0, "HandleFlagsPoint for render-sandbox failed, %s",
|
||||
APPSPAWN_CHECK_ONLY_LOG(ret == 0, "HandleFlagsPoint for render-sandbox failed, %{public}s",
|
||||
appProperty->bundleName);
|
||||
}
|
||||
#endif
|
||||
@ -763,12 +765,12 @@ int32_t SandboxUtils::SetCommonAppSandboxProperty_(const ClientSocket::AppProper
|
||||
int rc = 0;
|
||||
|
||||
rc = DoSandboxFileCommonBind(appProperty, config);
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "DoSandboxFileCommonBind failed, %s", appProperty->bundleName);
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "DoSandboxFileCommonBind failed, %{public}s", appProperty->bundleName);
|
||||
|
||||
// if sandbox switch is off, don't do symlink work again
|
||||
if (CheckAppSandboxSwitchStatus(appProperty) == true && (CheckTotalSandboxSwitchStatus(appProperty) == true)) {
|
||||
rc = DoSandboxFileCommonSymlink(appProperty, config);
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "DoSandboxFileCommonSymlink failed, %s", appProperty->bundleName);
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "DoSandboxFileCommonSymlink failed, %{public}s", appProperty->bundleName);
|
||||
}
|
||||
|
||||
rc = DoSandboxFileCommonFlagsPointHandle(appProperty, config);
|
||||
@ -785,13 +787,15 @@ int32_t SandboxUtils::SetCommonAppSandboxProperty(const ClientSocket::AppPropert
|
||||
int ret = 0;
|
||||
|
||||
ret = SetCommonAppSandboxProperty_(appProperty, jsonConfig);
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "parse appdata config for common failed, %s", sandboxPackagePath.c_str());
|
||||
APPSPAWN_CHECK(ret == 0, return ret,
|
||||
"parse appdata config for common failed, %{public}s", sandboxPackagePath.c_str());
|
||||
|
||||
ret = SetCommonAppSandboxProperty_(appProperty, productConfig);
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "parse product config for common failed, %s", sandboxPackagePath.c_str());
|
||||
APPSPAWN_CHECK(ret == 0, return ret,
|
||||
"parse product config for common failed, %{public}s", sandboxPackagePath.c_str());
|
||||
|
||||
ret = MountAllHsp(appProperty, sandboxPackagePath);
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "mount hspList failed, %s", sandboxPackagePath.c_str());
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "mount hspList failed, %{public}s", sandboxPackagePath.c_str());
|
||||
|
||||
if (strcmp(appProperty->apl, APL_SYSTEM_BASIC.data()) == 0 ||
|
||||
strcmp(appProperty->apl, APL_SYSTEM_CORE.data()) == 0 ||
|
||||
@ -827,7 +831,7 @@ int32_t SandboxUtils::MountAllHsp(const ClientSocket::AppProperty *appProperty,
|
||||
APPSPAWN_CHECK(bundles.is_array() && modules.is_array() && versions.is_array() && bundles.size() == modules.size()
|
||||
&& bundles.size() == versions.size(), return -1, "MountAllHsp: value is not arrary or sizes are not same");
|
||||
|
||||
APPSPAWN_LOGI("MountAllHsp: app = %s, cnt = %u", appProperty->bundleName, bundles.size());
|
||||
APPSPAWN_LOGI("MountAllHsp: app = %{public}s, cnt = %{public}u", appProperty->bundleName, bundles.size());
|
||||
for (uint32_t i = 0; i < bundles.size(); i++) {
|
||||
// elements in json arrary can be different type
|
||||
APPSPAWN_CHECK(bundles[i].is_string() && modules[i].is_string() && versions[i].is_string(),
|
||||
@ -842,7 +846,7 @@ int32_t SandboxUtils::MountAllHsp(const ClientSocket::AppProperty *appProperty,
|
||||
std::string libPhysicalPath = g_physicalAppInstallPath + libBundleName + "/" + libVersion + "/" + libModuleName;
|
||||
std::string mntPath = sandboxPackagePath + g_sandboxHspInstallPath + libBundleName + "/" + libModuleName;
|
||||
ret = DoAppSandboxMountOnce(libPhysicalPath.c_str(), mntPath.c_str(), "", BASIC_MOUNT_FLAGS, nullptr);
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "mount library failed %d", ret);
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "mount library failed %{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -859,7 +863,7 @@ int32_t SandboxUtils::DoSandboxRootFolderCreateAdapt(std::string &sandboxPackage
|
||||
// rootfs: to do more resources bind mount here to get more strict resources constraints
|
||||
#ifndef APPSPAWN_TEST
|
||||
rc = mount("/", sandboxPackagePath.c_str(), NULL, BASIC_MOUNT_FLAGS, NULL);
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "mount bind / failed, %d", errno);
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "mount bind / failed, %{public}d", errno);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@ -914,7 +918,7 @@ bool SandboxUtils::CheckAppSandboxSwitchStatus(const ClientSocket::AppProperty *
|
||||
if (privateAppConfig.find(appProperty->bundleName) != privateAppConfig.end()) {
|
||||
nlohmann::json appConfig = privateAppConfig[appProperty->bundleName][0];
|
||||
rc = GetSbxSwitchStatusByConfig(appConfig);
|
||||
APPSPAWN_LOGE("CheckAppSandboxSwitchStatus middle, %d", rc);
|
||||
APPSPAWN_LOGE("CheckAppSandboxSwitchStatus middle, %{public}d", rc);
|
||||
}
|
||||
|
||||
// default sandbox switch is on
|
||||
@ -946,7 +950,7 @@ int32_t SandboxUtils::SetAppSandboxProperty(const ClientSocket::AppProperty *app
|
||||
if (!(appProperty->cloneFlags & CLONE_NEWPID)) {
|
||||
// add pid to a new mnt namespace
|
||||
rc = unshare(CLONE_NEWNS);
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "unshare failed, packagename is %s", bundleName.c_str());
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "unshare failed, packagename is %{public}s", bundleName.c_str());
|
||||
}
|
||||
|
||||
// check app sandbox switch
|
||||
@ -956,14 +960,14 @@ int32_t SandboxUtils::SetAppSandboxProperty(const ClientSocket::AppProperty *app
|
||||
} else {
|
||||
rc = DoSandboxRootFolderCreate(appProperty, sandboxPackagePath);
|
||||
}
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "DoSandboxRootFolderCreate failed, %s", bundleName.c_str());
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "DoSandboxRootFolderCreate failed, %{public}s", bundleName.c_str());
|
||||
#ifndef NWEB_SPAWN
|
||||
rc = SetCommonAppSandboxProperty(appProperty, sandboxPackagePath);
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "SetCommonAppSandboxProperty failed, packagename is %s",
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "SetCommonAppSandboxProperty failed, packagename is %{public}s",
|
||||
bundleName.c_str());
|
||||
if (CheckBundleNameForPrivate(bundleName)) {
|
||||
rc = SetPrivateAppSandboxProperty(appProperty);
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "SetPrivateAppSandboxProperty failed, packagename is %s",
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "SetPrivateAppSandboxProperty failed, packagename is %{public}s",
|
||||
bundleName.c_str());
|
||||
}
|
||||
#else
|
||||
@ -972,21 +976,21 @@ int32_t SandboxUtils::SetAppSandboxProperty(const ClientSocket::AppProperty *app
|
||||
// so we can't use the method SetPrivateAppSandboxProperty
|
||||
// which mount dirs by using bundle name.
|
||||
rc = SetRenderSandboxProperty(appProperty, sandboxPackagePath);
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "SetRenderSandboxProperty failed, packagename is %s",
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "SetRenderSandboxProperty failed, packagename is %{public}s",
|
||||
sandboxPackagePath.c_str());
|
||||
#endif
|
||||
|
||||
#ifndef APPSPAWN_TEST
|
||||
rc = chdir(sandboxPackagePath.c_str());
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "chdir failed, packagename is %s, path is %s",
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "chdir failed, packagename is %{public}s, path is %{public}s",
|
||||
bundleName.c_str(), sandboxPackagePath.c_str());
|
||||
|
||||
rc = syscall(SYS_pivot_root, sandboxPackagePath.c_str(), sandboxPackagePath.c_str());
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "errno is %d, pivot root failed, packagename is %s",
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "errno is %{public}d, pivot root failed, packagename is %{public}s",
|
||||
errno, bundleName.c_str());
|
||||
|
||||
rc = umount2(".", MNT_DETACH);
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "MNT_DETACH failed, packagename is %s", bundleName.c_str());
|
||||
APPSPAWN_CHECK(rc == 0, return rc, "MNT_DETACH failed, packagename is %{public}s", bundleName.c_str());
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user