From 0fb2d36fe094a23ed6a343836f1bbc266a3e92be Mon Sep 17 00:00:00 2001 From: fan-jingle Date: Wed, 3 Sep 2025 11:46:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97=E6=80=BB?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fan-jingle --- common/appspawn_server.c | 4 ++-- modules/ace_adapter/ace_adapter.cpp | 2 +- modules/common/appspawn_begetctl.c | 2 +- modules/sandbox/normal/sandbox_common.cpp | 10 +++++----- modules/sandbox/normal/sandbox_core.cpp | 2 +- modules/sandbox/normal/sandbox_def.h | 2 +- modules/sandbox/normal/sandbox_shared_mount.cpp | 4 ++-- modules/sandbox/sandbox_dec.c | 10 +++++----- standard/appspawn_msgmgr.c | 10 +++++----- util/include/appspawn_utils.h | 10 ++++++++-- 10 files changed, 31 insertions(+), 25 deletions(-) diff --git a/common/appspawn_server.c b/common/appspawn_server.c index c1d41ccd..c33efde7 100644 --- a/common/appspawn_server.c +++ b/common/appspawn_server.c @@ -45,7 +45,7 @@ static void NotifyResToParent(struct AppSpawnContent *content, AppSpawnClient *c void ProcessExit(int code) { - APPSPAWN_LOGI("ExitCode:%{public}d", code); + APPSPAWN_DUMPI("ExitCode:%{public}d", code); #ifdef OHOS_LITE _exit(0x7f); // 0x7f user exit #else @@ -73,7 +73,7 @@ void exit(int code) int AppSpawnChild(AppSpawnContent *content, AppSpawnClient *client) { APPSPAWN_CHECK(content != NULL && client != NULL, return -1, "Invalid arg for appspawn child"); - APPSPAWN_LOGI("AppSpawnChild id %{public}u flags: 0x%{public}x", client->id, client->flags); + APPSPAWN_DUMPI("AppSpawnChild id %{public}u flags:0x%{public}x", client->id, client->flags); StartAppspawnTrace("AppSpawnExecuteClearEnvHook"); int ret = AppSpawnExecuteClearEnvHook(content, client); FinishAppspawnTrace(); diff --git a/modules/ace_adapter/ace_adapter.cpp b/modules/ace_adapter/ace_adapter.cpp index 9cd07426..804b7a19 100644 --- a/modules/ace_adapter/ace_adapter.cpp +++ b/modules/ace_adapter/ace_adapter.cpp @@ -231,7 +231,7 @@ APPSPAWN_STATIC void ClearEnvAndReturnSuccess(AppSpawnContent *content, AppSpawn int ret = 0; ssize_t written = write(fd, &ret, sizeof(ret)); (void)close(fd); - APPSPAWN_LOGI("ClearEnvAndReturnSuccess %{public}zd", written); + APPSPAWN_DUMPI("ClearEnvAndReturnSuccess %{public}zd", written); } APPSPAWN_STATIC int RunChildThread(const AppSpawnMgr *content, const AppSpawningCtx *property) diff --git a/modules/common/appspawn_begetctl.c b/modules/common/appspawn_begetctl.c index 3696bb8f..984af154 100755 --- a/modules/common/appspawn_begetctl.c +++ b/modules/common/appspawn_begetctl.c @@ -70,7 +70,7 @@ APPSPAWN_STATIC int RunBegetctlBootApp(AppSpawnMgr *content, AppSpawningCtx *pro APPSPAWN_CHECK_ONLY_EXPER(property != NULL, return -1); UNUSED(content); if ((property->client.flags & APP_BEGETCTL_BOOT) != APP_BEGETCTL_BOOT) { - APPSPAWN_LOGW("Enter begetctl boot without BEGETCTL_BOOT flag set"); + APPSPAWN_LOGV("Enter begetctl boot without BEGETCTL_BOOT flag set"); return 0; } uint32_t len = 0; diff --git a/modules/sandbox/normal/sandbox_common.cpp b/modules/sandbox/normal/sandbox_common.cpp index 0503c71a..3d728438 100644 --- a/modules/sandbox/normal/sandbox_common.cpp +++ b/modules/sandbox/normal/sandbox_common.cpp @@ -306,8 +306,8 @@ bool SandboxCommon::VerifyDirRecursive(const std::string &path) index = pathIndex == std::string::npos ? size : pathIndex + 1; std::string dir = path.substr(0, index); #ifndef APPSPAWN_TEST - APPSPAWN_CHECK_LOGW(access(dir.c_str(), F_OK) == 0, - return false, "check dir %{public}s failed, strerror: %{public}s", dir.c_str(), strerror(errno)); + APPSPAWN_CHECK_DUMPI(access(dir.c_str(), F_OK) == 0, + return false, "check dir %{public}s failed,strerror:%{public}s", dir.c_str(), strerror(errno)); #endif } while (index < size); return true; @@ -316,7 +316,7 @@ bool SandboxCommon::VerifyDirRecursive(const std::string &path) void SandboxCommon::CreateFileIfNotExist(const char *file) { if (access(file, F_OK) == 0) { - APPSPAWN_LOGI("file %{public}s already exist", file); + APPSPAWN_DUMPI("file %{public}s already exist", file); return; } std::string path = file; @@ -1006,7 +1006,7 @@ int32_t SandboxCommon::DoAppSandboxMountOnce(const AppSpawningCtx *appProperty, APPSPAWN_CHECK_ONLY_EXPER(diff < FUNC_REPORT_DURATION, ReportAbnormalDuration(arg->srcPath, diff)); #endif if (ret != 0) { - APPSPAWN_LOGI("errno is: %{public}d, bind mount %{public}s to %{public}s", errno, arg->srcPath, arg->destPath); + APPSPAWN_DUMPI("errno:%{public}d bind mount %{public}s to %{public}s", errno, arg->srcPath, arg->destPath); if (errno == ENOENT && IsNeededCheckPathStatus(appProperty, arg->srcPath)) { VerifyDirRecursive(arg->srcPath); } @@ -1015,7 +1015,7 @@ int32_t SandboxCommon::DoAppSandboxMountOnce(const AppSpawningCtx *appProperty, ret = mount(nullptr, arg->destPath, nullptr, arg->mountSharedFlag, nullptr); if (ret != 0) { - APPSPAWN_LOGI("errno is: %{public}d, private mount to %{public}s '%{public}u' failed", + APPSPAWN_DUMPI("errno:%{public}d private mount to %{public}s '%{public}u' failed", errno, arg->destPath, arg->mountSharedFlag); if (errno == EINVAL) { CheckMountStatus(arg->destPath); diff --git a/modules/sandbox/normal/sandbox_core.cpp b/modules/sandbox/normal/sandbox_core.cpp index ea47460d..d6598d10 100644 --- a/modules/sandbox/normal/sandbox_core.cpp +++ b/modules/sandbox/normal/sandbox_core.cpp @@ -434,7 +434,7 @@ int32_t SandboxCore::MountAllHsp(const AppSpawningCtx *appProperty, std::string APPSPAWN_CHECK(count == cJSON_GetArraySize(modules), return -1, "MountAllHsp: sizes are not same"); APPSPAWN_CHECK(count == cJSON_GetArraySize(versions), return -1, "MountAllHsp: sizes are not same"); - APPSPAWN_LOGI("MountAllHsp app: %{public}s, count: %{public}d", GetBundleName(appProperty), count); + APPSPAWN_LOGV("MountAllHsp app: %{public}s, count: %{public}d", GetBundleName(appProperty), count); for (int i = 0; i < count; i++) { if (!(cJSON_IsString(cJSON_GetArrayItem(bundles, i)) && cJSON_IsString(cJSON_GetArrayItem(modules, i)) && cJSON_IsString(cJSON_GetArrayItem(versions, i)))) { diff --git a/modules/sandbox/normal/sandbox_def.h b/modules/sandbox/normal/sandbox_def.h index e0dcfdc8..5a6d0469 100644 --- a/modules/sandbox/normal/sandbox_def.h +++ b/modules/sandbox/normal/sandbox_def.h @@ -30,7 +30,7 @@ constexpr int32_t FILE_ACCESS_COMMON_DIR_STATUS = 0; constexpr int32_t FILE_CROSS_APP_STATUS = 1; constexpr static mode_t FILE_MODE = 0711; constexpr static mode_t BASIC_MOUNT_FLAGS = MS_REC | MS_BIND; -constexpr int32_t MAX_MOUNT_TIME = 500; // 500us +constexpr int32_t MAX_MOUNT_TIME = 5000; // 5000us constexpr int32_t LOCK_STATUS_SIZE = 16; // 沙盒配置文件 diff --git a/modules/sandbox/normal/sandbox_shared_mount.cpp b/modules/sandbox/normal/sandbox_shared_mount.cpp index 6b68acae..d7b127ba 100644 --- a/modules/sandbox/normal/sandbox_shared_mount.cpp +++ b/modules/sandbox/normal/sandbox_shared_mount.cpp @@ -112,7 +112,7 @@ static bool IsUnlockStatus(uint32_t uid) std::string lockStatusParam = "startup.appspawn.lockstatus_" + std::to_string(uid); char userLockStatus[LOCK_STATUS_SIZE] = {0}; int ret = GetParameter(lockStatusParam.c_str(), "1", userLockStatus, sizeof(userLockStatus)); - APPSPAWN_LOGI("lockStatus %{public}u %{public}s", uid, userLockStatus); + APPSPAWN_DUMPI("lockStatus %{public}u %{public}s", uid, userLockStatus); if (ret > 0 && (strcmp(userLockStatus, "0") == 0)) { // 0:unlock status 1:lock status return true; } @@ -141,7 +141,7 @@ static int DoSharedMount(const SharedMountArgs *arg) APPSPAWN_LOGE("mount path %{public}s to shared failed, errno %{public}d", arg->destPath, errno); return ret; } - APPSPAWN_LOGI("mount path %{public}s to shared success", arg->destPath); + APPSPAWN_DUMPI("mount path %{public}s to shared success", arg->destPath); return 0; } diff --git a/modules/sandbox/sandbox_dec.c b/modules/sandbox/sandbox_dec.c index 72c0d4f8..f3ef0f2c 100644 --- a/modules/sandbox/sandbox_dec.c +++ b/modules/sandbox/sandbox_dec.c @@ -127,7 +127,7 @@ static int SetDenyConstraintDirs(AppSpawnMgr *content) } else { APPSPAWN_LOGI("set CONSTRAINT_DEC_POLICY_CMD sandbox policy success."); for (uint32_t i = 0; i < decPolicyInfos.pathNum; i++) { - APPSPAWN_LOGI("policy info: %{public}s", decPolicyInfos.path[i].path); + APPSPAWN_DUMPI("%{public}s", decPolicyInfos.path[i].path); } } close(fd); @@ -159,9 +159,9 @@ static int SetForcedPrefixDirs(AppSpawnMgr *content) if (ioctl(fd, SET_DEC_PREFIX_CMD, &decPolicyInfos) < 0) { APPSPAWN_LOGE("set sandbox forced prefix failed."); } else { - APPSPAWN_LOGI("set SET_DEC_PREFIX_CMD sandbox policy success."); + APPSPAWN_LOGV("set SET_DEC_PREFIX_CMD sandbox policy success."); for (uint32_t i = 0; i < decPolicyInfos.pathNum; i++) { - APPSPAWN_LOGI("policy info: %{public}s", decPolicyInfos.path[i].path); + APPSPAWN_DUMPI("%{public}s", decPolicyInfos.path[i].path); } } close(fd); @@ -190,9 +190,9 @@ void SetDecPolicy(void) if (ioctl(fd, SET_DEC_POLICY_CMD, g_decPolicyInfos) < 0) { APPSPAWN_LOGE("set sandbox policy failed."); } else { - APPSPAWN_LOGI("set SET_DEC_POLICY_CMD sandbox policy success. timestamp:%{public}" PRId64 "", timestamp); + APPSPAWN_LOGV("set SET_DEC_POLICY_CMD sandbox policy success. timestamp:%{public}" PRId64 "", timestamp); for (uint32_t i = 0; i < g_decPolicyInfos->pathNum; i++) { - APPSPAWN_LOGI("policy info: path %{public}s, mode 0x%{public}x", + APPSPAWN_DUMPI("path %{public}s mode 0x%{public}x", g_decPolicyInfos->path[i].path, g_decPolicyInfos->path[i].mode); } } diff --git a/standard/appspawn_msgmgr.c b/standard/appspawn_msgmgr.c index 51d9f8df..d576b350 100644 --- a/standard/appspawn_msgmgr.c +++ b/standard/appspawn_msgmgr.c @@ -349,7 +349,7 @@ int GetAppSpawnMsgFromBuffer(const uint8_t *buffer, uint32_t bufferLen, static inline void DumpMsgFlags(const char *processName, const char *info, const AppSpawnMsgFlags *msgFlags) { for (uint32_t i = 0; i < msgFlags->count; i++) { - APPSPAWN_DUMP("processName: %{public}s %{public}d %{public}s flags: 0x%{public}x", + APPSPAWN_DUMP("%{public}s %{public}d %{public}s flags:0x%{public}x", processName, i, info, msgFlags->flags[i]); } } @@ -372,7 +372,7 @@ static inline void DumpMsgExtInfo(const AppSpawnTlv *tlv) void DumpAppSpawnMsg(const AppSpawnMsgNode *message) { APPSPAWN_CHECK_ONLY_EXPER(message != NULL, return); - APPSPAWN_DUMP("App spawn msg msgId: %{public}u msgLen: %{public}u tlvCount: %{public}u processName: %{public}s", + APPSPAWN_DUMP("AppSpawn msgId:%{public}u msgLen:%{public}u tlvCount:%{public}u processName:%{public}s", message->msgHeader.msgId, message->msgHeader.msgLen, message->tlvCount, message->msgHeader.processName); AppSpawnMsgFlags *msgFlags = (AppSpawnMsgFlags *)GetAppSpawnMsgInfo(message, TLV_MSG_FLAGS); @@ -383,7 +383,7 @@ void DumpAppSpawnMsg(const AppSpawnMsgNode *message) AppSpawnMsgDacInfo *dacInfo = (AppSpawnMsgDacInfo *)GetAppSpawnMsgInfo(message, TLV_DAC_INFO); if (dacInfo != NULL) { - APPSPAWN_DUMP("App dac info uid: %{public}d gid: %{public}d count: %{public}d", + APPSPAWN_DUMP("uid:%{public}d gid:%{public}d count:%{public}d", dacInfo->uid, dacInfo->gid, dacInfo->gidCount); for (uint32_t i = 0; i < dacInfo->gidCount; i++) { APPSPAWN_LOGV("gid group[%{public}d]: %{public}d", i, dacInfo->gidTable[i]); @@ -391,12 +391,12 @@ void DumpAppSpawnMsg(const AppSpawnMsgNode *message) } AppSpawnMsgBundleInfo *bundleInfo = (AppSpawnMsgBundleInfo *)GetAppSpawnMsgInfo(message, TLV_BUNDLE_INFO); APPSPAWN_ONLY_EXPER(bundleInfo != NULL, - APPSPAWN_DUMP("App BundleName:\"%{public}s\" index: %{public}d", + APPSPAWN_DUMP("App BundleName:%{public}s index:%{public}d", bundleInfo->bundleName, bundleInfo->bundleIndex)); AppSpawnMsgDomainInfo *domainInfo = (AppSpawnMsgDomainInfo *)GetAppSpawnMsgInfo(message, TLV_DOMAIN_INFO); APPSPAWN_ONLY_EXPER(domainInfo != NULL, - APPSPAWN_DUMP("App DomainHap:0x%{public}x apl:\"%{public}s\"", domainInfo->hapFlags, domainInfo->apl)); + APPSPAWN_DUMP("apl:%{public}s 0x%{public}x", domainInfo->apl, domainInfo->hapFlags)); AppSpawnMgr *mgr = GetAppSpawnMgr(); if (mgr == NULL || ((mgr->flags & APP_DEVELOPER_MODE) != APP_DEVELOPER_MODE)) { diff --git a/util/include/appspawn_utils.h b/util/include/appspawn_utils.h index 7ce58c6d..32bf7fcf 100644 --- a/util/include/appspawn_utils.h +++ b/util/include/appspawn_utils.h @@ -182,7 +182,7 @@ int EnableNewNetNamespace(void); HILOG_WARN(LOG_CORE, "[%{public}s:%{public}d]" fmt, (APP_FILE_NAME), (__LINE__), ##__VA_ARGS__) #define APPSPAWN_LOGF(fmt, ...) \ HILOG_FATAL(LOG_CORE, "[%{public}s:%{public}d]" fmt, (APP_FILE_NAME), (__LINE__), ##__VA_ARGS__) -#define APPSPAWN_DUMP_LOGI(fmt, ...) \ +#define APPSPAWN_DUMPI(fmt, ...) \ HILOG_INFO(LOG_CORE, fmt, ##__VA_ARGS__) #define APPSPAWN_DUMP(fmt, ...) \ do { \ @@ -202,7 +202,7 @@ int EnableNewNetNamespace(void); HILOG_DEBUG(HILOG_MODULE_HIVIEW, "[%{public}s:%{public}d]" fmt, (APP_FILE_NAME), (__LINE__), ##__VA_ARGS__) #define APPSPAWN_LOGW(fmt, ...) \ HILOG_FATAL(HILOG_MODULE_HIVIEW, "[%{public}s:%{public}d]" fmt, (APP_FILE_NAME), (__LINE__), ##__VA_ARGS__) -#define APPSPAWN_DUMP_LOGI(fmt, ...) \ +#define APPSPAWN_DUMPI(fmt, ...) \ HILOG_INFO(HILOG_MODULE_HIVIEW, fmt, ##__VA_ARGS__) #define APPSPAWN_KLOGI(fmt, ...) \ HILOG_INFO(HILOG_MODULE_HIVIEW, "[%{public}s:%{public}d]" fmt, (APP_FILE_NAME), (__LINE__), ##__VA_ARGS__) @@ -226,6 +226,12 @@ int EnableNewNetNamespace(void); exper; \ } +#define APPSPAWN_CHECK_DUMPI(retCode, exper, fmt, ...) \ + if (!(retCode)) { \ + APPSPAWN_DUMPI(fmt, ##__VA_ARGS__); \ + exper; \ + } + #define APPSPAWN_CHECK_LOGI(retCode, exper, fmt, ...) \ if (!(retCode)) { \ APPSPAWN_LOGI(fmt, ##__VA_ARGS__); \ -- Gitee