Signed-off-by: nianyuu <zhouwenqiang12@huawei.com>
This commit is contained in:
nianyuu 2024-06-11 21:44:54 +08:00
parent a08db92651
commit 750849e6b5
8 changed files with 23 additions and 22 deletions

View File

@ -51,7 +51,7 @@ APPSPAWN_STATIC void RunAppSandbox(const char *ptyName)
APPSPAWN_CHECK(n == 0, free(realPath); _exit(1), "pts path %{public}s is invaild", realPath);
int fd = open(realPath, O_RDWR);
free(realPath);
APPSPAWN_CHECK(fd >= 0, _exit(1), "Failed open %s, err=%{public}d", ptyName, errno);
APPSPAWN_CHECK(fd >= 0, _exit(1), "Failed open %{public}s, err=%{public}d", ptyName, errno);
(void)dup2(fd, STDIN_FILENO);
(void)dup2(fd, STDOUT_FILENO);
(void)dup2(fd, STDERR_FILENO); // Redirect fd to 0, 1, 2

View File

@ -154,7 +154,7 @@ static int ProcessMgrRemoveApp(const AppSpawnMgr *content, const AppSpawnedProce
char path[PATH_MAX] = {};
APPSPAWN_LOGV("ProcessMgrRemoveApp %{public}d %{public}d to cgroup ", appInfo->pid, appInfo->uid);
int ret = GetCgroupPath(appInfo, path, sizeof(path));
APPSPAWN_CHECK(ret == 0, return -1, "Failed to get real path errno: %d", errno);
APPSPAWN_CHECK(ret == 0, return -1, "Failed to get real path errno: %{public}d", errno);
ret = strcat_s(path, sizeof(path), "cgroup.procs");
APPSPAWN_CHECK(ret == 0, return ret, "Failed to strcat_s errno: %{public}d", errno);
KillProcessesByCGroup(path, (AppSpawnMgr *)content, appInfo);
@ -171,7 +171,7 @@ static int ProcessMgrAddApp(const AppSpawnMgr *content, const AppSpawnedProcessI
char path[PATH_MAX] = {};
APPSPAWN_LOGV("ProcessMgrAddApp %{public}d %{public}d to cgroup ", appInfo->pid, appInfo->uid);
int ret = GetCgroupPath(appInfo, path, sizeof(path));
APPSPAWN_CHECK(ret == 0, return -1, "Failed to get real path errno: %d", errno);
APPSPAWN_CHECK(ret == 0, return -1, "Failed to get real path errno: %{public}d", errno);
(void)CreateSandboxDir(path, 0755); // 0755 default mode
uint32_t pathLen = strlen(path);
ret = strcat_s(path, sizeof(path), "cgroup.procs");

View File

@ -113,8 +113,8 @@ static int RunChildProcessor(AppSpawnContent *content, AppSpawnClient *client)
return -1;
}
AppSpawnEnvClear(content, client);
funcNWebRenderMain(renderStr.c_str());
APPSPAWN_LOGI("RunChildProcessorNweb %{public}s", renderStr.c_str());
funcNWebRenderMain(renderStr.c_str());
return 0;
}

View File

@ -1259,7 +1259,7 @@ int32_t SandboxUtils::MountAllGroup(const AppSpawningCtx *appProperty, std::stri
}
ret = DoAppSandboxMountOnce(libPhysicalPath.c_str(), mntPath.c_str(), "", mountFlags, nullptr,
mountSharedFlag);
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;
}
@ -1408,7 +1408,7 @@ int32_t SandboxUtils::SetOverlayAppSandboxProperty(const AppSpawningCtx *appProp
int32_t retMount = DoAppSandboxMountOnce(srcPath.c_str(), destPath.c_str(),
nullptr, BASIC_MOUNT_FLAGS, nullptr);
if (retMount != 0) {
APPSPAWN_LOGE("fail to mount overlay path, src is %s.", hapPath.c_str());
APPSPAWN_LOGE("fail to mount overlay path, src is %{public}s.", hapPath.c_str());
ret = retMount;
}
@ -1458,11 +1458,11 @@ int32_t SandboxUtils::SetSandboxProperty(AppSpawningCtx *appProperty, std::strin
bundleName.c_str());
ret = SetOverlayAppSandboxProperty(appProperty, sandboxPackagePath);
APPSPAWN_CHECK(ret == 0, return ret, "SetOverlayAppSandboxProperty failed, packagename is %s",
APPSPAWN_CHECK(ret == 0, return ret, "SetOverlayAppSandboxProperty failed, packagename is %{public}s",
bundleName.c_str());
ret = SetBundleResourceAppSandboxProperty(appProperty, sandboxPackagePath);
APPSPAWN_CHECK(ret == 0, return ret, "SetBundleResourceAppSandboxProperty failed, packagename is %s",
APPSPAWN_CHECK(ret == 0, return ret, "SetBundleResourceAppSandboxProperty failed, packagename is %{public}s",
bundleName.c_str());
APPSPAWN_LOGI("Set appsandbox property success");
return ret;
@ -1590,11 +1590,11 @@ int32_t SandboxUtils::SetAppSandboxPropertyNweb(AppSpawningCtx *appProperty, uin
sandboxPackagePath.c_str());
rc = SetOverlayAppSandboxProperty(appProperty, sandboxPackagePath);
APPSPAWN_CHECK(rc == 0, return rc, "SetOverlayAppSandboxProperty failed, packagename is %s",
APPSPAWN_CHECK(rc == 0, return rc, "SetOverlayAppSandboxProperty failed, packagename is %{public}s",
bundleName.c_str());
rc = SetBundleResourceAppSandboxProperty(appProperty, sandboxPackagePath);
APPSPAWN_CHECK(rc == 0, return rc, "SetBundleResourceAppSandboxProperty failed, packagename is %s",
APPSPAWN_CHECK(rc == 0, return rc, "SetBundleResourceAppSandboxProperty failed, packagename is %{public}s",
bundleName.c_str());
#ifndef APPSPAWN_TEST

View File

@ -589,16 +589,16 @@ int AppSpawnTestCommander::InitPtyInterface()
{
// open master pty and get slave pty
int pfd = open("/dev/ptmx", O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK);
APPSPAWN_CHECK(pfd >= 0, return -1, "Failed open pty err=%d", errno);
APPSPAWN_CHECK(pfd >= 0, return -1, "Failed open pty err=%{public}d", errno);
APPSPAWN_CHECK(grantpt(pfd) >= 0, close(pfd); return -1, "Failed to call grantpt");
APPSPAWN_CHECK(unlockpt(pfd) >= 0, close(pfd); return -1, "Failed to call unlockpt");
char ptsbuffer[PTY_PATH_SIZE] = {0};
int ret = ptsname_r(pfd, ptsbuffer, sizeof(ptsbuffer));
APPSPAWN_CHECK(ret >= 0, close(pfd);
return -1, "Failed to get pts name err=%d", errno);
APPSPAWN_LOGI("ptsbuffer is %s", ptsbuffer);
return -1, "Failed to get pts name err=%{public}d", errno);
APPSPAWN_LOGI("ptsbuffer is %{public}s", ptsbuffer);
APPSPAWN_CHECK(chmod(ptsbuffer, S_IRWXU | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) == 0, close(pfd);
return -1, "Failed to chmod %s, err=%d", ptsbuffer, errno);
return -1, "Failed to chmod %{public}s, err=%{public}d", ptsbuffer, errno);
ptyFd_ = pfd;
ptyName_ = std::string(ptsbuffer);
return 0;

View File

@ -54,15 +54,16 @@ public:
static void InitPtyInterface()
{
int pfd = open("/dev/ptmx", O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK);
APPSPAWN_CHECK(pfd >= 0, return, "Failed open pty err=%d", errno);
APPSPAWN_CHECK(pfd >= 0, return, "Failed open pty err=%{public}d", errno);
APPSPAWN_CHECK(grantpt(pfd) >= 0, close(pfd); return, "Failed to call grantpt");
APPSPAWN_CHECK(unlockpt(pfd) >= 0, close(pfd); return, "Failed to call unlockpt");
char ptsbuffer[128] = {0};
int ret = ptsname_r(pfd, ptsbuffer, sizeof(ptsbuffer));
APPSPAWN_CHECK(ret >= 0, close(pfd); return, "Failed to get pts name err=%d", errno);
APPSPAWN_CHECK(ret >= 0, close(pfd);
return, "Failed to get pts name err=%{public}d", errno);
APPSPAWN_LOGI("ptsbuffer is %{public}s", ptsbuffer);
APPSPAWN_CHECK(chmod(ptsbuffer, S_IRWXU | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) == 0, close(pfd);
return, "Failed to chmod %{public}s, err=%d", ptsbuffer, errno);
return, "Failed to chmod %{public}s, err=%{public}d", ptsbuffer, errno);
g_ptyName = std::string(ptsbuffer);
}

View File

@ -89,7 +89,7 @@ HWTEST(AppSpawnCGroupTest, App_Spawn_CGroup_001, TestSize.Level0)
APPSPAWN_CHECK(appInfo != nullptr, break, "Failed to create appInfo");
char path[PATH_MAX] = {};
ret = GetCgroupPath(appInfo, path, sizeof(path));
APPSPAWN_CHECK(ret == 0, break, "Failed to get real path errno: %d", errno);
APPSPAWN_CHECK(ret == 0, break, "Failed to get real path errno: %{public}d", errno);
APPSPAWN_CHECK(strstr(path, "200") != nullptr && strstr(path, "33") != nullptr && strstr(path, name) != nullptr,
break, "Invalid path: %s", path);
ret = 0;
@ -133,7 +133,7 @@ HWTEST(AppSpawnCGroupTest, App_Spawn_CGroup_002, TestSize.Level0)
pid_t pid = 0;
ret = -1;
while (fscanf_s(file, "%d\n", &pid) == 1 && pid > 0) {
APPSPAWN_LOGV("pid %d %d", pid, appInfo->pid);
APPSPAWN_LOGV("pid %{public}d %{public}d", pid, appInfo->pid);
if (pid == appInfo->pid) {
ret = 0;
break;
@ -319,7 +319,7 @@ HWTEST(AppSpawnCGroupTest, App_Spawn_CGroup_007, TestSize.Level0)
uint32_t max = 0;
ret = -1;
while (fscanf_s(file, "%d\n", &max) == 1 && max > 0) {
APPSPAWN_LOGV("max %d %d", max, appInfo->max);
APPSPAWN_LOGV("max %{public}d %{public}d", max, appInfo->max);
if (max == appInfo->max) {
ret = 0;
break;

View File

@ -342,7 +342,7 @@ static int TestParseAppSandboxConfig(AppSpawnSandboxCfg *sandbox, const char *bu
{
cJSON *config = cJSON_Parse(buffer);
if (config == nullptr) {
APPSPAWN_LOGE("TestParseAppSandboxConfig config %s", buffer);
APPSPAWN_LOGE("TestParseAppSandboxConfig config %{public}s", buffer);
return -1;
}
int ret = 0;
@ -1285,7 +1285,7 @@ HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_mount_003, TestSize.Level0)
PathMountNode *pathNode = reinterpret_cast<PathMountNode *>(GetFirstSandboxMountPathNode(section));
pathNode->checkErrorFlag = 1; // 设置错误检查
APPSPAWN_LOGV("pathNode %s => %s \n", pathNode->source, pathNode->target);
APPSPAWN_LOGV("pathNode %{public}s => %{public}s \n", pathNode->source, pathNode->target);
// set check point
MountArg args = {};
args.originPath = "/config";