From 13c89f1b5ec1d3f8f5af12229fec9ce26afc205b Mon Sep 17 00:00:00 2001 From: fan-jingle Date: Mon, 4 Aug 2025 16:29:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97=E7=BA=A7?= =?UTF-8?q?=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fan-jingle --- common/appspawn_server.c | 2 +- modules/asan/asan_detector.c | 2 +- modules/common/appspawn_common.c | 2 +- modules/common/appspawn_encaps.c | 4 ++-- modules/common/appspawn_silk.c | 13 ++++------ modules/sandbox/modern/sandbox_load.c | 2 +- modules/sandbox/normal/sandbox_common.cpp | 4 ++-- modules/sandbox/normal/sandbox_core.cpp | 1 + .../sandbox/normal/sandbox_shared_mount.cpp | 2 +- standard/appspawn_main.c | 2 +- util/include/appspawn_utils.h | 24 +++++++++++++++++++ util/include/json_utils.h | 2 +- 12 files changed, 40 insertions(+), 20 deletions(-) diff --git a/common/appspawn_server.c b/common/appspawn_server.c index cf942d3f..2b7b2cea 100644 --- a/common/appspawn_server.c +++ b/common/appspawn_server.c @@ -168,7 +168,7 @@ static void AppSpawnForkChildProcess(AppSpawnContent *content, AppSpawnClient *c struct timespec forkEnd = {0}; clock_gettime(CLOCK_MONOTONIC, &forkEnd); uint64_t diff = DiffTime(&forkStart, &forkEnd); - APPSPAWN_CHECK_ONLY_LOG(diff < MAX_FORK_TIME, "fork time %{public}" PRId64 " us", diff); + APPSPAWN_CHECK_ONLY_LOGW(diff < MAX_FORK_TIME, "fork time %{public}" PRId64 " us", diff); #ifndef OHOS_LITE // Inherit the error level of the original process (void)fdsan_set_error_level(errorLevel); diff --git a/modules/asan/asan_detector.c b/modules/asan/asan_detector.c index 3bbecf98..bdeb7cb9 100644 --- a/modules/asan/asan_detector.c +++ b/modules/asan/asan_detector.c @@ -125,7 +125,7 @@ static int CheckSupportColdStart(const char *bundleName) APPSPAWN_CHECK(len > 0 && (len < WRAP_VALUE_MAX_LENGTH), return -1, "Invalid to format wrapBundleNameKey"); int ret = GetParameter(wrapBundleNameKey, "", wrapBundleNameValue, WRAP_VALUE_MAX_LENGTH); - APPSPAWN_CHECK(ret > 0 && (!strcmp(wrapBundleNameValue, "asan_wrapper")), return -1, + APPSPAWN_CHECK_LOGV(ret > 0 && (!strcmp(wrapBundleNameValue, "asan_wrapper")), return -1, "Not wrap %{public}s.", bundleName); APPSPAWN_LOGI("Asan: GetParameter %{public}s the value is %{public}s.", wrapBundleNameKey, wrapBundleNameValue); return 0; diff --git a/modules/common/appspawn_common.c b/modules/common/appspawn_common.c index 57342e19..300d0352 100644 --- a/modules/common/appspawn_common.c +++ b/modules/common/appspawn_common.c @@ -682,7 +682,7 @@ APPSPAWN_STATIC int SetFdEnv(AppSpawnMgr *content, AppSpawningCtx *property) APPSPAWN_CHECK_ONLY_EXPER(message->tlvOffset != NULL, return -1); int findFdIndex = 0; AppSpawnMsgReceiverCtx recvCtx = message->connection->receiverCtx; - APPSPAWN_CHECK(recvCtx.fds != NULL && recvCtx.fdCount > 0, return 0, + APPSPAWN_CHECK_LOGV(recvCtx.fds != NULL && recvCtx.fdCount > 0, return 0, "no need set fd info %{public}d, %{public}d", recvCtx.fds != NULL, recvCtx.fdCount); char keyBuffer[APP_FDNAME_MAXLEN + sizeof(APP_FDENV_PREFIX)]; char value[sizeof(int)]; diff --git a/modules/common/appspawn_encaps.c b/modules/common/appspawn_encaps.c index f5c11a25..0250c65f 100644 --- a/modules/common/appspawn_encaps.c +++ b/modules/common/appspawn_encaps.c @@ -365,7 +365,7 @@ APPSPAWN_STATIC int SpawnSetPermissions(AppSpawningCtx *property, UserEncaps *en // Get Permissions obejct cJSON *extInfoJson = GetJsonObjFromExtInfo(property, MSG_EXT_NAME_JIT_PERMISSIONS); if (extInfoJson == NULL) { - APPSPAWN_LOGW("GetJsonObjFromExtInfo failed"); + APPSPAWN_LOGV("GetJsonObjFromExtInfo failed"); return APPSPAWN_ARG_INVALID; } @@ -411,7 +411,7 @@ APPSPAWN_STATIC int SpawnSetEncapsPermissions(AppSpawnMgr *content, AppSpawningC if (ret != 0) { close(encapsFileFd); FreeEncapsInfo(&encapsInfo); - APPSPAWN_LOGW("Build encaps info failed, ret: %{public}d", ret); + APPSPAWN_LOGV("Build encaps info failed, ret: %{public}d", ret); return 0; // Can't set permission encpas ability } diff --git a/modules/common/appspawn_silk.c b/modules/common/appspawn_silk.c index ee349404..2f8d9141 100644 --- a/modules/common/appspawn_silk.c +++ b/modules/common/appspawn_silk.c @@ -118,15 +118,10 @@ void LoadSilkConfig(void) bool LoadSilkLibrary(const char *packageName) { bool isSuccess = false; - if (g_silkConfig.configItems == NULL) { - APPSPAWN_LOGV("ConfigItems is NULL"); - return isSuccess; - } - if (packageName == NULL) { - APPSPAWN_LOGV("PackageName is NULL"); - FreeAllSilkConfig(); - return isSuccess; - } + APPSPAWN_CHECK_LOGV(g_silkConfig.configItems != NULL, return isSuccess, + "ConfigItems is NULL"); + APPSPAWN_CHECK_LOGV(packageName != NULL, FreeAllSilkConfig(); return isSuccess, + "PackageName is NULL"); char **appName = NULL; void *handle = NULL; for (int i = 0; i < g_silkConfig.configCursor; i++) { diff --git a/modules/sandbox/modern/sandbox_load.c b/modules/sandbox/modern/sandbox_load.c index 0af4536b..e8b10dd0 100644 --- a/modules/sandbox/modern/sandbox_load.c +++ b/modules/sandbox/modern/sandbox_load.c @@ -365,7 +365,7 @@ APPSPAWN_STATIC int ParseSymbolLinksConfig(AppSpawnSandboxCfg *sandbox, const cJ APPSPAWN_STATIC int ParseGidTableConfig(AppSpawnSandboxCfg *sandbox, const cJSON *configs, SandboxSection *section) { - APPSPAWN_CHECK(cJSON_IsArray(configs), return 0, "json is not array."); + APPSPAWN_CHECK_LOGV(cJSON_IsArray(configs), return 0, "json is not array."); uint32_t arrayLen = (uint32_t)cJSON_GetArraySize(configs); APPSPAWN_CHECK_ONLY_EXPER(arrayLen > 0, return 0); APPSPAWN_CHECK(arrayLen < APP_MAX_GIDS, arrayLen = APP_MAX_GIDS, "More gid in gids json."); diff --git a/modules/sandbox/normal/sandbox_common.cpp b/modules/sandbox/normal/sandbox_common.cpp index 5552befe..55f66802 100644 --- a/modules/sandbox/normal/sandbox_common.cpp +++ b/modules/sandbox/normal/sandbox_common.cpp @@ -304,7 +304,7 @@ 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(access(dir.c_str(), F_OK) == 0, + 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)); #endif } while (index < size); @@ -989,7 +989,7 @@ int32_t SandboxCommon::DoAppSandboxMountOnce(const AppSpawningCtx *appProperty, struct timespec mountEnd = {0}; clock_gettime(CLOCK_MONOTONIC_COARSE, &mountEnd); uint64_t diff = DiffTime(&mountStart, &mountEnd); - APPSPAWN_CHECK_ONLY_LOG(diff < SandboxCommonDef::MAX_MOUNT_TIME, "mount %{public}s time %{public}" PRId64 " us", + APPSPAWN_CHECK_ONLY_LOGW(diff < SandboxCommonDef::MAX_MOUNT_TIME, "mount %{public}s time %{public}" PRId64 " us", arg->srcPath, diff); #ifdef APPSPAWN_HISYSEVENT APPSPAWN_CHECK_ONLY_EXPER(diff < FUNC_REPORT_DURATION, ReportAbnormalDuration(arg->srcPath, diff)); diff --git a/modules/sandbox/normal/sandbox_core.cpp b/modules/sandbox/normal/sandbox_core.cpp index 9bd4c9d7..36da9271 100644 --- a/modules/sandbox/normal/sandbox_core.cpp +++ b/modules/sandbox/normal/sandbox_core.cpp @@ -1184,6 +1184,7 @@ EXIT: void SandboxCore::SetDecDenyWithDir(const AppSpawningCtx *appProperty) { int32_t userFileIndex = GetPermissionIndex(nullptr, SandboxCommonDef::READ_WRITE_USER_FILE_MODE.c_str()); + APPSPAWN_CHECK_LOGV(userFileIndex != -1, return, "userFileIndex Invalid index"); if (CheckAppPermissionFlagSet(appProperty, static_cast(userFileIndex)) == 0) { APPSPAWN_LOGV("The app doesn't have %{public}s, no need to set deny rules", SandboxCommonDef::READ_WRITE_USER_FILE_MODE.c_str()); diff --git a/modules/sandbox/normal/sandbox_shared_mount.cpp b/modules/sandbox/normal/sandbox_shared_mount.cpp index 63a02377..e168faa5 100644 --- a/modules/sandbox/normal/sandbox_shared_mount.cpp +++ b/modules/sandbox/normal/sandbox_shared_mount.cpp @@ -196,7 +196,7 @@ static int MountEl1Bundle(const AppSpawningCtx *property, const AppDacInfo *info ret = umount2(targetPath, MNT_DETACH); if (ret != 0) { - APPSPAWN_LOGE("umount2 %{public}s failed, errno %{public}d", targetPath, errno); + APPSPAWN_LOGW("umount2 %{public}s failed, errno %{public}d", targetPath, errno); } SharedMountArgs arg = { diff --git a/standard/appspawn_main.c b/standard/appspawn_main.c index df5fe79f..7fdb7f0f 100644 --- a/standard/appspawn_main.c +++ b/standard/appspawn_main.c @@ -92,7 +92,7 @@ static AppSpawnStartArgTemplate *GetAppSpawnStartArg(const char *serverName, App // appspawn -mode appspawn | cold | nwebspawn -param app_property -fd clientFd int main(int argc, char *const argv[]) { - APPSPAWN_LOGE("main argc: %{public}d", argc); + APPSPAWN_LOGI("main argc: %{public}d", argc); if (argc <= 0) { return 0; } diff --git a/util/include/appspawn_utils.h b/util/include/appspawn_utils.h index d8768344..7ce58c6d 100644 --- a/util/include/appspawn_utils.h +++ b/util/include/appspawn_utils.h @@ -214,6 +214,24 @@ int EnableNewNetNamespace(void); exper; \ } +#define APPSPAWN_CHECK_LOGV(retCode, exper, fmt, ...) \ + if (!(retCode)) { \ + APPSPAWN_LOGV(fmt, ##__VA_ARGS__); \ + exper; \ + } + +#define APPSPAWN_CHECK_LOGW(retCode, exper, fmt, ...) \ + if (!(retCode)) { \ + APPSPAWN_LOGW(fmt, ##__VA_ARGS__); \ + exper; \ + } + +#define APPSPAWN_CHECK_LOGI(retCode, exper, fmt, ...) \ + if (!(retCode)) { \ + APPSPAWN_LOGI(fmt, ##__VA_ARGS__); \ + exper; \ + } + #define APPSPAWN_CHECK_ONLY_EXPER(retCode, exper) \ if (!(retCode)) { \ exper; \ @@ -228,6 +246,12 @@ int EnableNewNetNamespace(void); if (!(retCode)) { \ APPSPAWN_LOGE(fmt, ##__VA_ARGS__); \ } + +#define APPSPAWN_CHECK_ONLY_LOGW(retCode, fmt, ...) \ + if (!(retCode)) { \ + APPSPAWN_LOGW(fmt, ##__VA_ARGS__); \ + } + #ifdef __cplusplus } #endif // __cplusplus diff --git a/util/include/json_utils.h b/util/include/json_utils.h index 41369b83..10fed0f8 100644 --- a/util/include/json_utils.h +++ b/util/include/json_utils.h @@ -34,7 +34,7 @@ cJSON *GetJsonObjFromFile(const char *jsonPath); __attribute__((always_inline)) inline char *GetStringFromJsonObj(const cJSON *json, const char *key) { APPSPAWN_CHECK_ONLY_EXPER(key != NULL && json != NULL, NULL); - APPSPAWN_CHECK(cJSON_IsObject(json), return NULL, "json is not object %{public}s", key); + APPSPAWN_CHECK_LOGV(cJSON_IsObject(json), return NULL, "json is not object %{public}s", key); cJSON *obj = cJSON_GetObjectItemCaseSensitive(json, key); APPSPAWN_CHECK_ONLY_EXPER(obj != NULL, return NULL); APPSPAWN_CHECK(cJSON_IsString(obj), return NULL, "json is not string %{public}s", key); -- Gitee