diff --git a/common/appspawn_server.c b/common/appspawn_server.c index cf942d3fa0b598c2c5a94f52c757d989d1b49f9e..2b7b2ceacbc0390fa0600a3ffa60646e6d5077b1 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 3bbecf98ed17fc39f8362689d17a5a1eeb4bfaeb..bdeb7cb922f4059d9c3b6e99b469b940c5fb8df7 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 57342e197ba358ef5563d82c736168036960ff7f..300d0352005d7ed4c591ea04d78905216d525407 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 f5c11a25a624e14ac5cb13132bd419b4c3c3c538..0250c65f4ae8f56e23c94171941ca6b912549eb7 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 ee349404fe7624bdbd5b0c0fee48be4cb3d9b1ee..2f8d9141062478031e78286e85cd0aede4c30a75 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 0af4536b5e63a047749991e8db55556877f0d119..e8b10dd07d829db1ff0e95ed905a1e53c9e18088 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 5552befe9b3abd258c54a9da4c363a64f6eec2d8..2b93a7d356f3cb95c21ea2d5a87c8f752eb10d86 100644 --- a/modules/sandbox/normal/sandbox_common.cpp +++ b/modules/sandbox/normal/sandbox_common.cpp @@ -238,6 +238,8 @@ std::string SandboxCommon::GetSandboxRootPath(const AppSpawningCtx *appProperty, const std::string variableSandboxRoot = SandboxCommonDef::g_sandBoxRootDir + std::to_string(dacInfo->uid / UID_BASE) + "/" + isolatedFlagText.c_str() + tmpBundlePath; + APPSPAWN_CHECK_ONLY_EXPER(config != nullptr, sandboxRoot = variableSandboxRoot; + return sandboxRoot); const char *sandboxRootChr = GetStringFromJsonObj(config, SandboxCommonDef::g_sandboxRootPrefix); if (sandboxRootChr != nullptr) { sandboxRoot = sandboxRootChr; @@ -304,7 +306,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 +991,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 9bd4c9d794460f3c0e5beca107cfc9f8ceb4fa0f..36da9271cf22761d8869d089664556a4498eb9b0 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 63a023775d60d38b0c4fcb29105da543e48a4238..e168faa5885cf710a9587ecfc827a0cfd9e53538 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 df5fe79f011b8e226c2ca7380164794f9226c2c4..7fdb7f0f2a22803d03f1be59b3a6bd702cb7816d 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 d876834432fcea828a05a31b11043baab734a6ce..7ce58c6d08016ba393c05b5ef3c1a673960eb954 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