diff --git a/begetd.gni b/begetd.gni index 4d6864cb8cdf9ba0ec3fc3810c4fe3aaf54bba3b..62fc2c29518053fb43b0b5d489651f33dabaa68a 100644 --- a/begetd.gni +++ b/begetd.gni @@ -33,9 +33,13 @@ declare_args() { # boot_kernel_extended_cmdline for extend cmdline - startup_init_feature_decode_group_file = true + startup_init_feature_decode_group_file = false + + startup_init_test_performance = true + startup_init_with_param_base = false if (!use_musl) { startup_init_with_param_base = true + startup_init_feature_decode_group_file = true } } diff --git a/services/begetctl/BUILD.gn b/services/begetctl/BUILD.gn index c2737d3cb9ca9329a1d2ce0e5d7c3bd650d4b8ec..80c281055da4c040fc4ef13d207cb97fb4145806 100755 --- a/services/begetctl/BUILD.gn +++ b/services/begetctl/BUILD.gn @@ -160,6 +160,9 @@ if (defined(ohos_lite)) { ] } + if (startup_init_test_performance) { + defines += [ "PARAM_TEST_PERFORMANCE" ] + } install_images = [ "system" ] install_enable = true diff --git a/services/begetctl/param_cmd.c b/services/begetctl/param_cmd.c index 01658d2b8e8ca8674761b901b6698cb0e838a47c..55b701fc6be947dd7c04f2b7d8079151eedaaf95 100644 --- a/services/begetctl/param_cmd.c +++ b/services/begetctl/param_cmd.c @@ -358,7 +358,7 @@ static int32_t BShellParamCmdWait(BShellHandle shell, int32_t argc, char *argv[] static int32_t BShellParamCmdDump(BShellHandle shell, int32_t argc, char *argv[]) { BSH_CHECK(shell != NULL, return BSH_INVALID_PARAM, "Invalid shell env"); - if (argc >= 2) { + if (argc >= 2) { // 2 min parameter if (strcmp(argv[1], "verbose") == 0) { SystemDumpParameters(1, -1, printf); return 0; diff --git a/services/etc/BUILD.gn b/services/etc/BUILD.gn index c0e3e42a12086533a9d510df2bf69af97ab5690f..159081b9927643779eb5eb20cd4f0bc8ed5b0251 100755 --- a/services/etc/BUILD.gn +++ b/services/etc/BUILD.gn @@ -119,8 +119,26 @@ if (defined(ohos_lite)) { ] part_name = "init" subsystem_name = "startup" + extra_paras = [] if (target_cpu == "arm64") { - extra_paras = [ "const.product.cpu.abilist=arm64-v8a" ] + extra_paras += [ "const.product.cpu.abilist=arm64-v8a" ] + } + if (build_variant == "user") { + extra_paras += [ + "const.secure=1", + "const.debuggable=0", + ] + } else if (build_variant == "root") { + extra_paras += [ + "const.secure=0", + "const.debuggable=1", + ] + } + if (device_type != "default") { + extra_paras += [ + "const.product.devicetype=${device_type}", + "const.build.characteristics=${device_type}", + ] } module_install_dir = "etc/param" } diff --git a/services/etc/group b/services/etc/group index 2af0932b9d1972ba7c2946f1b1e7905b3c6611d0..dde6bd51be60115b311d58bd9362c6b46c15002c 100644 --- a/services/etc/group +++ b/services/etc/group @@ -46,7 +46,7 @@ ddms:x:3012: access_token:x:3020: blue_host:x:3021: sample_host:x:3022: -usb_host:x:3023: +usb_host:x:3023:shell usbfnMaster_host:x:3024: power_host:x:3025: wifi_host:x:3026: @@ -119,6 +119,7 @@ memmgr:x:1111: ispserver:x:3821: dfs_share:x:3822: appspawn:x:4000: +print:x:3823: security_guard:x:3520: tee:x:6668: dsserver:x:3068: diff --git a/services/etc/param/ohos.para b/services/etc/param/ohos.para index e93bbaca0e21de7751f8998c6d5e395acb42c403..c29bfc768fa8a35fe80bf71f3ab7804a1e2119b0 100755 --- a/services/etc/param/ohos.para +++ b/services/etc/param/ohos.para @@ -13,7 +13,7 @@ const.actionable_compatible_property.enabled=false const.postinstall.fstab.prefix=/system -const.secure=1 +const.secure=0 security.perf_harden=1 const.allow.mock.location=0 const.debuggable=1 @@ -29,7 +29,7 @@ const.build.product=default const.product.hardwareversion=default const.product.bootloader.version=bootloader const.product.cpu.abilist=default -const.product.software.version=OpenHarmony 3.2.9.1 +const.product.software.version=OpenHarmony 4.0.1.1 const.product.incremental.version=default const.product.firstapiversion=1 const.product.build.type=default diff --git a/services/etc/param/ohos_const/ohos.para b/services/etc/param/ohos_const/ohos.para index 0c432820ec1233adbb5286e54a98979e2e8392f5..1a64861b5b82f3774e31307da85a0b98f63bbc9f 100755 --- a/services/etc/param/ohos_const/ohos.para +++ b/services/etc/param/ohos_const/ohos.para @@ -12,5 +12,5 @@ # limitations under the License. const.ohos.version.security_patch=2022-03-30 const.ohos.releasetype=Canary1 -const.ohos.apiversion=9 -const.ohos.fullname=OpenHarmony-3.2.0.0 +const.ohos.apiversion=10 +const.ohos.fullname=OpenHarmony-4.0.0.0 diff --git a/services/etc/passwd b/services/etc/passwd index d85b157694afb9003d9ec5cf6e8ea9dcc6986ef4..1346981b1bf395ef83cd2278f5e9a9551a557aa1 100644 --- a/services/etc/passwd +++ b/services/etc/passwd @@ -115,6 +115,7 @@ motion_host:x:3065:3065:::/bin/false memmgr:x:1111:1111:::/bin/false ispserver:x:3821:3821:::/bin/false dfs_share:x:3822:3822:::/bin/false +print:x:3823:3823:::/bin/false security_guard:x:3520:3520:::/bin/false tee:x:6668:6668:::/bin/false dsserver:x:3068:3068:::/bin/false diff --git a/services/etc_lite/param/ohos_const/ohos.para b/services/etc_lite/param/ohos_const/ohos.para index b85c86d7e748b2efa20c12cad699a263793e497d..0c9c262237507fd95dc5c252a289211162fc3684 100755 --- a/services/etc_lite/param/ohos_const/ohos.para +++ b/services/etc_lite/param/ohos_const/ohos.para @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -const.ohos.releasetype=Beta3 -const.ohos.apiversion=9 +const.ohos.releasetype=Canary1 +const.ohos.apiversion=10 const.ohos.version.security_patch=2022-09-01 -const.ohos.fullname=OpenHarmony-3.2.9.1 \ No newline at end of file +const.ohos.fullname=OpenHarmony-4.0.1.1 \ No newline at end of file diff --git a/services/include/param/sys_param.h b/services/include/param/sys_param.h index 396f945fb45383855790fb220755419b8419202e..06f420b34e88f31712aa7b4218ebc04c714742a7 100644 --- a/services/include/param/sys_param.h +++ b/services/include/param/sys_param.h @@ -24,7 +24,7 @@ extern "C" { #endif typedef uint32_t ParamHandle; -typedef void * CachedHandle; +typedef void *CachedHandle; typedef struct { uint8_t updaterMode; diff --git a/services/init/standard/init.c b/services/init/standard/init.c index 3f7772b9687f28048cd33ce4c95ebba9e27664f0..d3d9d467d8d2402f793f0cf429cc62c63554623e 100755 --- a/services/init/standard/init.c +++ b/services/init/standard/init.c @@ -94,6 +94,10 @@ static int FdHolderSockInit(void) void SystemInit(void) { SignalInit(); + + // Set up a session keyring that all processes will have access to. + KeyCtrlGetKeyringId(KEY_SPEC_SESSION_KEYRING, 1); + // umask call always succeeds and return the previous mask value which is not needed here (void)umask(DEFAULT_UMASK_INIT); MakeDirRecursive("/dev/unix/socket", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); @@ -199,9 +203,6 @@ static void StartInitSecondStage(void) // It will panic if close stdio before execv("/bin/sh", NULL) CloseStdio(); - // Set up a session keyring that all processes will have access to. - KeyCtrlGetKeyringId(KEY_SPEC_SESSION_KEYRING, 1); - #ifndef DISABLE_INIT_TWO_STAGES INIT_LOGI("Start init second stage."); SwitchRoot("/usr"); diff --git a/services/modules/selinux/selinux_adp.c b/services/modules/selinux/selinux_adp.c index e62fc96724d530646e3a8275b8461dcfef358ad1..aa446a30a575ba0ce5d640ec0cdf63a24758d217 100755 --- a/services/modules/selinux/selinux_adp.c +++ b/services/modules/selinux/selinux_adp.c @@ -19,6 +19,7 @@ #include "init_hook.h" #include "init_module_engine.h" #include "plugin_adapter.h" +#include "securec.h" #include #include @@ -30,8 +31,13 @@ enum { CMD_RESTORE_INDEX = 3, }; +extern char *__progname; + static int LoadSelinuxPolicy(int id, const char *name, int argc, const char **argv) { + int ret; + char process_context[MAX_SECON_LEN]; + UNUSED(id); UNUSED(name); UNUSED(argc); @@ -44,7 +50,12 @@ static int LoadSelinuxPolicy(int id, const char *name, int argc, const char **ar PLUGIN_LOGI("main, load_policy success."); } - setcon("u:r:init:s0"); + ret = snprintf_s(process_context, sizeof(process_context), sizeof(process_context) - 1, "u:r:%s:s0", __progname); + if (ret == -1) { + setcon("u:r:init:s0"); + } else { + setcon(process_context); + } (void)RestoreconRecurse("/dev"); return 0; } diff --git a/services/param/adapter/param_dac.c b/services/param/adapter/param_dac.c index ddfdef3aa2ce316d30a6cd0dac1430a5186eb03e..8e10e80f9891cb35221807ec3a208866197259d7 100644 --- a/services/param/adapter/param_dac.c +++ b/services/param/adapter/param_dac.c @@ -48,7 +48,11 @@ static void GetUserIdByName(uid_t *uid, const char *name) static void GetGroupIdByName(gid_t *gid, const char *name) { *gid = -1; - struct group *data = NULL; + struct group *data = getgrnam(name); + if (data != NULL) { + *gid = data->gr_gid; + return; + } while ((data = getgrent()) != NULL) { if ((data->gr_name != NULL) && (strcmp(data->gr_name, name) == 0)) { *gid = data->gr_gid; diff --git a/services/param/adapter/param_selinux.c b/services/param/adapter/param_selinux.c index 8c462918c16708ddbe45de6778d0fb976ae002ef..db5becf7609e11d0635861b5beccf96933cbd312 100644 --- a/services/param/adapter/param_selinux.c +++ b/services/param/adapter/param_selinux.c @@ -251,7 +251,7 @@ static int OpenPermissionWorkSpace(const char *path) ret = SelinuxGetAllLabel(1, HandleSelinuxLabel); } else if (strcmp(path, "open") == 0) { if (loadLabels == 0) { - ret = SelinuxGetAllLabel(2, HandleSelinuxLabel); + ret = SelinuxGetAllLabel(2, HandleSelinuxLabel); // 2 mean need to open workspace } loadLabels = 1; } diff --git a/services/param/base/BUILD.gn b/services/param/base/BUILD.gn index 8d1c52f7bbc8732c9b6d9d6d0ef9dc516627f783..167d7381ef8fc8df1870287eb99935e71ef84bcf 100644 --- a/services/param/base/BUILD.gn +++ b/services/param/base/BUILD.gn @@ -115,6 +115,10 @@ if (defined(ohos_lite)) { if (use_musl) { defines += [ "__MUSL__" ] } + + if (startup_init_test_performance) { + defines += [ "PARAM_TEST_PERFORMANCE" ] + } if (!startup_init_with_param_base) { ldflags = [ "-nostdlib" ] configs -= inherited_configs diff --git a/services/param/base/param_base.c b/services/param/base/param_base.c index 6406594b60eed5a21e29f97af45a3097a6e5f6f5..fd20f9dc9b29e47e25a5e104b91564b5f9661e59 100644 --- a/services/param/base/param_base.c +++ b/services/param/base/param_base.c @@ -38,28 +38,6 @@ STATIC_INLINE ParamTrieNode *BaseFindTrieNode(WorkSpace *workSpace, const char *key, uint32_t keyLen, uint32_t *matchLabel); STATIC_INLINE int ReadParamValue_(ParamNode *entry, uint32_t *commitId, char *value, uint32_t *length); -STATIC_INLINE int IsWorkSpaceReady(WorkSpace *workSpace) -{ - if (workSpace == NULL) { - return -1; - } - int ret = -1; - WORKSPACE_RD_LOCK(workSpace); - if (workSpace->area != NULL) { - if ((g_paramWorkSpace.flags & WORKSPACE_FLAGS_NEED_ACCESS) == WORKSPACE_FLAGS_NEED_ACCESS) { - char buffer[FILENAME_LEN_MAX] = {0}; - int size = ParamSprintf(buffer, sizeof(buffer), "%s/%s", PARAM_STORAGE_PATH, workSpace->fileName); - if (size > 0 && access(buffer, R_OK) == 0) { - ret = 0; - } - } else { - ret = 0; - } - } - WORKSPACE_RW_UNLOCK(workSpace); - return ret; -} - // return workspace no check valid STATIC_INLINE WorkSpace *GetWorkSpaceByName(const char *name) { @@ -241,7 +219,6 @@ INIT_INNER_API ParamWorkSpace *GetParamWorkSpace(void) int SystemReadParam(const char *name, char *value, uint32_t *len) { - InitParameterClient(); PARAM_WORKSPACE_CHECK(&g_paramWorkSpace, return -1, "Param workspace has not init."); PARAM_CHECK(name != NULL && len != NULL, return -1, "The name or value is null"); ParamTrieNode *node = NULL; @@ -410,7 +387,7 @@ INIT_LOCAL_API int OpenWorkSpace(uint32_t index, int readOnly) workSpace = paramSpace->workSpace[index]; } if (workSpace == NULL) { - return -1; + return 0; } int ret = 0; WORKSPACE_RW_LOCK(workSpace); @@ -534,7 +511,8 @@ STATIC_INLINE int DacCheckParamPermission(const ParamLabelIndex *labelIndex, if ((node->mode & localMode) != 0) { ret = DAC_RESULT_PERMISSION; } else { - PARAM_LOGW("Param '%s' label gid:%d uid:%d mode 0%o", name, srcLabel->cred.gid, srcLabel->cred.uid, localMode); + PARAM_LOGW("Param '%s' label gid:%d uid:%d mode 0%o", + name, srcLabel->cred.gid, srcLabel->cred.uid, localMode); PARAM_LOGW("Cfg label %u gid:%d uid:%d mode 0%o ", index, node->gid, node->uid, node->mode); #ifndef __MUSL__ #ifndef STARTUP_INIT_TEST @@ -547,6 +525,28 @@ STATIC_INLINE int DacCheckParamPermission(const ParamLabelIndex *labelIndex, } #ifdef PARAM_SUPPORT_SELINUX +STATIC_INLINE int IsWorkSpaceReady(WorkSpace *workSpace) +{ + if (workSpace == NULL) { + return -1; + } + int ret = -1; + WORKSPACE_RD_LOCK(workSpace); + if (workSpace->area != NULL) { + if ((g_paramWorkSpace.flags & WORKSPACE_FLAGS_NEED_ACCESS) == WORKSPACE_FLAGS_NEED_ACCESS) { + char buffer[FILENAME_LEN_MAX] = {0}; + int size = ParamSprintf(buffer, sizeof(buffer), "%s/%s", PARAM_STORAGE_PATH, workSpace->fileName); + if (size > 0 && access(buffer, R_OK) == 0) { + ret = 0; + } + } else { + ret = 0; + } + } + WORKSPACE_RW_UNLOCK(workSpace); + return ret; +} + STATIC_INLINE const char *GetSelinuxContent(const char *name) { SelinuxSpace *selinuxSpace = &g_paramWorkSpace.selinuxSpace; @@ -639,8 +639,7 @@ STATIC_INLINE ParamTrieNode *BaseFindTrieNode(WorkSpace *workSpace, PARAM_CHECK(key != NULL && keyLen > 0, return NULL, "Invalid key "); uint32_t tmpMatchLen = 0; - ParamTrieNode *node = NULL; - node = FindTrieNode_(workSpace, key, keyLen, &tmpMatchLen); + ParamTrieNode *node = FindTrieNode_(workSpace, key, keyLen, &tmpMatchLen); if (matchLabel != NULL) { *matchLabel = tmpMatchLen; } @@ -672,7 +671,8 @@ CachedHandle CachedParameterCreate(const char *name, const char *defValue) int ret = ReadParamWithCheck(workspace, name, DAC_READ, &node); PARAM_CHECK(ret == 0, return NULL, "Forbid to access parameter %s", name); - CachedParameter *param = malloc(sizeof(CachedParameter) + PARAM_ALIGN(nameLen) + 1 + PARAM_VALUE_LEN_MAX); + CachedParameter *param = (CachedParameter *)malloc( + sizeof(CachedParameter) + PARAM_ALIGN(nameLen) + 1 + PARAM_VALUE_LEN_MAX); PARAM_CHECK(param != NULL, return NULL, "Failed to create CachedParameter for %s", name); ret = ParamStrCpy(param->data, nameLen + 1, name); PARAM_CHECK(ret == 0, free(param); @@ -699,6 +699,7 @@ CachedHandle CachedParameterCreate(const char *name, const char *defValue) return NULL, "Failed to copy name %s", name); } param->spaceCommitId = ATOMIC_LOAD_EXPLICIT(&workspace->area->commitId, memory_order_acquire); + PARAM_LOGV("CachedParameterCreate %u %u %lld \n", param->dataIndex, param->dataCommitId, param->spaceCommitId); return (CachedHandle)param; } @@ -747,215 +748,107 @@ void CachedParameterDestroy(CachedHandle handle) } } -#if 1 // def PARAM_BASE +#ifdef PARAM_TEST_PERFORMANCE +#define MAX_TEST 10000 STATIC_INLINE long long DiffLocalTime(struct timespec *startTime) { struct timespec endTime; clock_gettime(CLOCK_MONOTONIC, &(endTime)); long long diff = (long long)((endTime.tv_sec - startTime->tv_sec) * 1000000); // 1000000 1000ms if (endTime.tv_nsec > startTime->tv_nsec) { - diff += (endTime.tv_nsec - startTime->tv_nsec) / 1000; + diff += (endTime.tv_nsec - startTime->tv_nsec) / 1000; // 1000 1ms } else { - diff -= (startTime->tv_nsec - endTime.tv_nsec) / 1000; + diff -= (startTime->tv_nsec - endTime.tv_nsec) / 1000; // 1000 1ms } return diff; } -void TestReader() +static void TestPermissionCheck(const char *testParamName) { struct timespec startTime; - const int max = 10000; - const char *testParamName = "startup.appspawn.randrom.read"; - (void)srand((unsigned)time(NULL)); - const uint32_t buffSize = 1024; - char buffer[1024] = {0}; - uint32_t size = buffSize; - int ret = SystemGetParameter(testParamName, buffer, &size); - int count = 0; - uint32_t spaceIndex = 0; clock_gettime(CLOCK_MONOTONIC, &(startTime)); - clock_gettime(CLOCK_MONOTONIC, &(startTime)); - printf("TestReader total time %lld us %s \n", DiffLocalTime(&startTime), __FILE__); - printf("TestReader total time %lld us %s \n", DiffLocalTime(&startTime), testParamName); ParamSecurityLabel *label = &(GetParamWorkSpace()->securityLabel); - - count = 0; - clock_gettime(CLOCK_MONOTONIC, &(startTime)); - while (count < max) { - size = buffSize; - ret = SystemReadParam(testParamName, buffer, &size); - count++; - } - printf("SystemReadParam total time %lld us \n", DiffLocalTime(&startTime)); - printf("SystemReadParam total buffer %s \n", buffer); - - count = 0; - WorkSpace *workspace = GetWorkSpaceByName(testParamName); - clock_gettime(CLOCK_MONOTONIC, &(startTime)); - while (count < max) { - ParamTrieNode *entry = NULL; - ReadParamWithCheck(workspace, testParamName, DAC_READ, &entry); - count++; - } - printf("ReadParamWithCheck total time %lld us \n", DiffLocalTime(&startTime)); - - count = 0; - clock_gettime(CLOCK_MONOTONIC, &(startTime)); - while (count < max) { - size = buffSize; - ret = SystemReadParam(testParamName, buffer, &size); - count++; - } - printf("SystemReadParam total time %lld us \n", DiffLocalTime(&startTime)); - printf("SystemReadParam total buffer %s \n", buffer); - - count = 0; - clock_gettime(CLOCK_MONOTONIC, &(startTime)); - while (count < max) { - ParamTrieNode *entry = NULL; - ReadParamWithCheck(workspace, testParamName, DAC_READ, &entry); - count++; - } - printf("ReadParamWithCheck total time %lld us \n", DiffLocalTime(&startTime)); - - count = 0; - clock_gettime(CLOCK_MONOTONIC, &(startTime)); - while (count < max) { - size = buffSize; - ret = SystemReadParam(testParamName, buffer, &size); - count++; - } - printf("SystemReadParam total time %lld us \n", DiffLocalTime(&startTime)); - printf("SystemReadParam total buffer %s \n", buffer); - - count = 0; - clock_gettime(CLOCK_MONOTONIC, &(startTime)); - while (count < max) { - ParamTrieNode *entry = NULL; - ReadParamWithCheck(workspace, testParamName, DAC_READ, &entry); - count++; - } - printf("ReadParamWithCheck total time %lld us \n", DiffLocalTime(&startTime)); - - count = 0; - clock_gettime(CLOCK_MONOTONIC, &(startTime)); - while (count < max) { - GetWorkSpaceByName(testParamName); - count++; - } - printf("GetWorkSpaceByName total time %lld us \n", DiffLocalTime(&startTime)); - - count = 0; ParamLabelIndex labelIndex = {0}; labelIndex.workspace = GetWorkSpaceByName(testParamName); labelIndex.selinuxLabelIndex = labelIndex.workspace->spaceIndex; BaseFindTrieNode(labelIndex.workspace, testParamName, strlen(testParamName), &labelIndex.dacLabelIndex); + clock_gettime(CLOCK_MONOTONIC, &(startTime)); - while (count < max) { + for (int i = 0; i < MAX_TEST; ++i) { CheckParamPermission_(&labelIndex, label, testParamName, DAC_READ); - count++; } printf("CheckParamPermission total time %lld us \n", DiffLocalTime(&startTime)); - count = 0; - spaceIndex = labelIndex.selinuxLabelIndex; - label = &(GetParamWorkSpace()->securityLabel); clock_gettime(CLOCK_MONOTONIC, &(startTime)); - while (count < max) { + for (int i = 0; i < MAX_TEST; ++i) { DacCheckParamPermission(&labelIndex, label, testParamName, DAC_READ); - count++; } printf("DacCheckParamPermission DAC total time %lld us \n", DiffLocalTime(&startTime)); #ifdef PARAM_SUPPORT_SELINUX - count = 0; - spaceIndex = GetWorkSpaceIndex(testParamName); clock_gettime(CLOCK_MONOTONIC, &(startTime)); - while (count < max) { + for (int i = 0; i < MAX_TEST; ++i) { SelinuxCheckParamPermission(&labelIndex, label, testParamName, DAC_READ); - count++; } printf("CheckParamPermission selinux total time %lld us \n", DiffLocalTime(&startTime)); #endif -#if 1 - count = 0; - clock_gettime(CLOCK_MONOTONIC, &(startTime)); - while (count < max) { - GetWorkSpaceByName(testParamName); - count++; - } - printf("GetWorkSpaceByName total time %lld us \n", DiffLocalTime(&startTime)); -#endif - -#if 1 - count = 0; ParamHandle handle = -1; uint32_t index = 0; - WorkSpace *space = labelIndex.workspace; clock_gettime(CLOCK_MONOTONIC, &(startTime)); - while (count < max) { - ParamTrieNode *node = BaseFindTrieNode(space, testParamName, strlen(testParamName), &index); + for (int i = 0; i < MAX_TEST; ++i) { + ParamTrieNode *node = BaseFindTrieNode(labelIndex.workspace, testParamName, strlen(testParamName), &index); if (node != NULL && node->dataIndex != 0) { - handle = PARAM_HANDLE(space, node->dataIndex); + handle = PARAM_HANDLE(labelIndex.workspace, node->dataIndex); } - count++; } - printf("BaseFindTrieNode total time %lld us spaceIndex %u %s\n", DiffLocalTime(&startTime), spaceIndex, space->fileName); - printf("BaseFindTrieNode handle %x \n", handle); -#endif + printf("BaseFindTrieNode total time %lld us handle %x \n", DiffLocalTime(&startTime), handle); -#if 1 - count = 0; + CachedHandle cacheHandle2 = CachedParameterCreate(testParamName, "true"); clock_gettime(CLOCK_MONOTONIC, &(startTime)); - while (count < max) { - index = 0; - // get dac label - space = g_paramWorkSpace.workSpace[0]; - (void)BaseFindTrieNode(space, testParamName, strlen(testParamName), &index); - GetTrieNode(space, index); - count++; - } - printf("BaseFindTrieNode dac time %lld us \n", DiffLocalTime(&startTime)); - printf("BaseFindTrieNode index %u \n", index); -#endif - - static CachedHandle cacheHandle = NULL; - if (cacheHandle == NULL) { - cacheHandle = CachedParameterCreate(testParamName, "true"); + const char *value = NULL; + for (int i = 0; i < MAX_TEST; ++i) { + value = CachedParameterGet(cacheHandle2); } - int result = 0; - count = 0; + CachedParameterDestroy(cacheHandle2); + printf("CachedParameterGet time %lld us value %s \n", DiffLocalTime(&startTime), value); + return; +} + +void TestParameterReaderPerformance(void) +{ + struct timespec startTime; + const char *testParamName = "persist.appspawn.randrom.read"; + const uint32_t buffSize = 1024; + char buffer[1024] = {0}; + uint32_t size = buffSize; clock_gettime(CLOCK_MONOTONIC, &(startTime)); - while (count < max) { - CachedParameter *param = (CachedParameter *)cacheHandle; - if (param != NULL) { - long long spaceCommitId = ATOMIC_LOAD_EXPLICIT(¶m->workspace->area->commitId, memory_order_acquire); - result = spaceCommitId == param->spaceCommitId; - if (param->dataIndex != 0) { - ParamNode *entry = (ParamNode *)GetTrieNode(param->workspace, param->dataIndex); - uint32_t dataCommitId = ATOMIC_LOAD_EXPLICIT(&entry->commitId, memory_order_acquire); - dataCommitId &= PARAM_FLAGS_COMMITID; - result = param->dataCommitId == dataCommitId; - } + printf("TestReader total time %lld us %s \n", DiffLocalTime(&startTime), testParamName); + for (int j = 0; j < 5; ++j) { // retry 5 + clock_gettime(CLOCK_MONOTONIC, &(startTime)); + for (int i = 0; i < MAX_TEST; ++i) { + size = buffSize; + SystemReadParam(testParamName, buffer, &size); + } + printf("SystemReadParam total time %lld us \n", DiffLocalTime(&startTime)); + printf("SystemReadParam result %s \n", buffer); + + WorkSpace *workspace = GetWorkSpaceByName(testParamName); + clock_gettime(CLOCK_MONOTONIC, &(startTime)); + for (int i = 0; i < MAX_TEST; ++i) { + ParamTrieNode *entry = NULL; + ReadParamWithCheck(workspace, testParamName, DAC_READ, &entry); } - count++; + printf("ReadParamWithCheck total time %lld us \n", DiffLocalTime(&startTime)); } - printf("CachedParameterGet time %lld us %d \n", DiffLocalTime(&startTime), result); - count = 0; - static CachedHandle cacheHandle2 = NULL; - if (cacheHandle2 == NULL) { - cacheHandle2 = CachedParameterCreate(testParamName, "true"); - } clock_gettime(CLOCK_MONOTONIC, &(startTime)); - const char *value = NULL; - while (count < max) { - value = CachedParameterGet(cacheHandle2); - count++; + for (int i = 0; i < MAX_TEST; ++i) { + GetWorkSpaceByName(testParamName); } - printf("CachedParameterGet time %lld us \n", DiffLocalTime(&startTime)); - printf("CachedParameterGet index %s \n", value); + printf("GetWorkSpaceByName total time %lld us \n", DiffLocalTime(&startTime)); + + TestPermissionCheck(testParamName); return; } #endif \ No newline at end of file diff --git a/services/param/base/param_base.h b/services/param/base/param_base.h index 151b3d6b1749b6c6adb543505e8c51f9825df500..3d595f21b06a52f6e2f23ffb46ad3b42b043fa4d 100644 --- a/services/param/base/param_base.h +++ b/services/param/base/param_base.h @@ -44,7 +44,9 @@ typedef struct CachedParameter_ { char *paramValue; char data[0]; } CachedParameter; - +#ifdef PARAM_TEST_PERFORMANCE +void TestParameterReaderPerformance(void); +#endif #ifdef __cplusplus #if __cplusplus } diff --git a/services/param/base/param_include.h b/services/param/base/param_include.h index c268139c4b6ea2ffe280a5c9c965d6f206ec8012..aab7e3b9dff6b753644e487e50ce63b91251575e 100755 --- a/services/param/base/param_include.h +++ b/services/param/base/param_include.h @@ -42,21 +42,27 @@ STATIC_INLINE int CompareParamTrieNode(const ParamTrieNode *node, const char *ke } else if (node->length < keyLen) { return 1; } - return strncmp(node->key, key, keyLen); + return memcmp(node->key, key, keyLen); } STATIC_INLINE ParamTrieNode *FindSubTrie(const WorkSpace *workSpace, ParamTrieNode *current, const char *key, uint32_t keyLen, uint32_t *matchLabel) { ParamTrieNode *subTrie = current; + int ret = 0; while (subTrie != NULL) { - int ret = CompareParamTrieNode(subTrie, key, keyLen); - if (ret == 0) { - if (subTrie->labelIndex != 0) { - *matchLabel = subTrie->labelIndex; + if (subTrie->length > keyLen) { + ret = -1; + } else if (subTrie->length < keyLen) { + ret = 1; + } else { + ret = memcmp(subTrie->key, key, keyLen); + if (ret == 0) { + *matchLabel = (subTrie->labelIndex != 0) ? subTrie->labelIndex : *matchLabel; + return subTrie; } - return subTrie; } + uint32_t offset = 0; if (ret < 0) { offset = subTrie->left; diff --git a/services/param/base/param_trie.c b/services/param/base/param_trie.c index 74d1ffe12acae24fb293b20453e71ff81a5b8c25..a57f009f5dd8ba5ac43b33cfbb5834604b7848dd 100644 --- a/services/param/base/param_trie.c +++ b/services/param/base/param_trie.c @@ -286,7 +286,7 @@ INIT_LOCAL_API void SaveIndex(uint32_t *index, uint32_t offset) INIT_LOCAL_API ParamTrieNode *FindTrieNode(WorkSpace *workSpace, const char *key, uint32_t keyLen, uint32_t *matchLabel) { - PARAM_CHECK(key != NULL && keyLen > 0, return NULL, "Invalid key "); + PARAM_ONLY_CHECK(key != NULL && keyLen > 0, return NULL); uint32_t tmpMatchLen = 0; ParamTrieNode *node = NULL; diff --git a/services/param/include/param_manager.h b/services/param/include/param_manager.h index b0af37e6991ddfea2d1858eff0d5966aef07c3b4..edae786ca509f5d8408beddde03f318070586c91 100644 --- a/services/param/include/param_manager.h +++ b/services/param/include/param_manager.h @@ -103,7 +103,7 @@ typedef struct { char *prefix; } ParamTraversalContext; -#define PARAM_HANDLE(workSpace, index) (ParamHandle)((workSpace)->spaceIndex << 24) | (index); +#define PARAM_HANDLE(workSpace, index) (ParamHandle)((workSpace)->spaceIndex << 24 | (index)) #define PARAM_GET_HANDLE_INFO(handle, label, index) \ do { \ (label) = (((handle) >> 24) & 0x000000ff); \ diff --git a/services/param/include/param_osadp.h b/services/param/include/param_osadp.h index 371f9c645fd8cbc29ae08ad857aab8b07de09674..7b0ca567a8691d6181e9acf832947404653be62f 100755 --- a/services/param/include/param_osadp.h +++ b/services/param/include/param_osadp.h @@ -60,32 +60,39 @@ extern "C" { data size strlen(xxxx.xxxx.xxxx.xxxx) + 96 */ -#if (defined __LITEOS_A__ || defined __LITEOS_M__) -#define DAC_DEFAULT_MODE 0777 +#define DAC_DEFAULT_GROUP 0 +#define DAC_DEFAULT_USER 0 + #ifdef STARTUP_INIT_TEST +#define DAC_DEFAULT_MODE 0777 +#define PARAM_WORKSPACE_DEF (1024 * 50) #define PARAM_WORKSPACE_MAX (1024 * 50) +#define PARAM_WORKSPACE_SMALL PARAM_WORKSPACE_MAX +#define PARAM_WORKSPACE_DEF PARAM_WORKSPACE_MAX #else + +#ifdef __LITEOS_M__ +#define DAC_DEFAULT_MODE 0777 #ifndef PARAM_WORKSPACE_MAX #define PARAM_WORKSPACE_MAX (1024 * 5) #endif -#endif #define PARAM_WORKSPACE_SMALL PARAM_WORKSPACE_MAX #define PARAM_WORKSPACE_DEF PARAM_WORKSPACE_MAX -#define DAC_DEFAULT_GROUP 0 -#define DAC_DEFAULT_USER 0 -#else -#define PARAM_WORKSPACE_MAX (80 * 1024) -#define PARAM_WORKSPACE_SMALL (1024 * 10) -#ifdef STARTUP_INIT_TEST +#else // __LITEOS_M__ + +#ifdef __LITEOS_A__ #define DAC_DEFAULT_MODE 0777 -#define PARAM_WORKSPACE_DEF (1024 * 50) -#else +#define PARAM_WORKSPACE_MAX (1024 * 10) +#define PARAM_WORKSPACE_SMALL PARAM_WORKSPACE_MAX +#define PARAM_WORKSPACE_DEF PARAM_WORKSPACE_MAX +#else // __LITEOS_A__ #define DAC_DEFAULT_MODE 0774 +#define PARAM_WORKSPACE_MAX (80 * 1024) +#define PARAM_WORKSPACE_SMALL (1024 * 10) #define PARAM_WORKSPACE_DEF (1024 * 30) -#endif -#define DAC_DEFAULT_GROUP 0 -#define DAC_DEFAULT_USER 0 -#endif +#endif // __LITEOS_A__ +#endif // __LITEOS_M__ +#endif // STARTUP_INIT_TEST // support futex #ifndef __NR_futex diff --git a/services/param/include/param_trie.h b/services/param/include/param_trie.h index 54b497dd8810e562066a27c6f28cfdf69b097d87..10b611b002455bc7b4a63f272653ae3198e6a93d 100644 --- a/services/param/include/param_trie.h +++ b/services/param/include/param_trie.h @@ -95,7 +95,7 @@ INIT_LOCAL_API int InitWorkSpace(WorkSpace *workSpace, int onlyRead, uint32_t sp INIT_LOCAL_API void CloseWorkSpace(WorkSpace *workSpace); #define GetTrieNode(workSpace, offset) \ - (ParamTrieNode *)((offset == 0 || offset > (workSpace)->area->dataSize) ? NULL : (workSpace)->area->data + offset) + (ParamTrieNode *)(((offset) == 0 || (offset) > (workSpace)->area->dataSize) ? NULL : (workSpace)->area->data + (offset)) #define GetTrieRoot(workSpace) \ (ParamTrieNode *)(((workSpace)->area == NULL) ? NULL : (workSpace)->area->data + (workSpace)->area->firstNode) diff --git a/services/param/linux/param_request.c b/services/param/linux/param_request.c index 6a559a1ac4c2047f2640c8c38314b2f472848cea..04a9af01ce3a19332969e494f0f88960f3b956a5 100644 --- a/services/param/linux/param_request.c +++ b/services/param/linux/param_request.c @@ -39,12 +39,10 @@ __attribute__((constructor)) static void ParameterInit(void) if (getpid() == 1) { return; } - EnableInitLog(INIT_INFO); + EnableInitLog(INIT_ERROR); PARAM_WORKSPACE_OPS ops = {0}; ops.updaterMode = 0; -#ifdef PARAM_BASE_LOG ops.logFunc = InitLog; -#endif #ifdef PARAM_SUPPORT_SELINUX ops.setfilecon = NULL; #endif diff --git a/services/param/liteos/BUILD.gn b/services/param/liteos/BUILD.gn index e5dbfc2244bc7ba5545450cce11b2f4f2e9b8791..788e8115ed7f76bf5bee7772790337eaac316ed7 100644 --- a/services/param/liteos/BUILD.gn +++ b/services/param/liteos/BUILD.gn @@ -115,10 +115,6 @@ static_library("param_client_lite") { defines = param_build_defines public_configs = [ ":exported_header_files" ] - if (use_musl) { - defines += [ "PARAM_BASE" ] - } - if (ohos_kernel_type == "liteos_a") { sources += [ "//base/startup/init/services/param/adapter/param_persistadp.c" ] diff --git a/services/param/liteos/param_litedac.c b/services/param/liteos/param_litedac.c index 08244c0ea9ce1badc9a12c85a7c5886ef9510343..1614c2cedcc8b79b82ecf549afeb69820612dfb6 100644 --- a/services/param/liteos/param_litedac.c +++ b/services/param/liteos/param_litedac.c @@ -52,7 +52,7 @@ static int CheckFilePermission(const ParamSecurityLabel *localLabel, const char return 0; } -INIT_LOCAL_API int DacCheckParamPermission(uint32_t index, +static int LiteDacCheckParamPermission(uint32_t index, const ParamSecurityLabel *srcLabel, const char *name, uint32_t mode) { UNUSED(index); @@ -74,7 +74,7 @@ INIT_LOCAL_API int RegisterSecurityDacOps(ParamSecurityOps *ops, int isInit) ops->securityGetLabel = NULL; ops->securityInitLabel = InitLocalSecurityLabel; ops->securityCheckFilePermission = CheckFilePermission; - ops->securityCheckParamPermission = DacCheckParamPermission; + ops->securityCheckParamPermission = LiteDacCheckParamPermission; ops->securityFreeLabel = FreeLocalSecurityLabel; if (isInit) { ops->securityGetLabel = DacGetParamSecurityLabel; diff --git a/services/param/liteos/param_service.c b/services/param/liteos/param_service.c index a7fa562561e3f55b2e4d14aa9590a4116fcd811b..946e406323291fd3745af6dd805080f0ad960203 100644 --- a/services/param/liteos/param_service.c +++ b/services/param/liteos/param_service.c @@ -121,87 +121,20 @@ int SystemWriteParam(const char *name, const char *value) #define OS_DELAY 1000 // * 30 // 30s #define STACK_SIZE 1024 - -typedef struct SysParaInfoItem_ { - char *infoName; - const char *(*getInfoValue)(void); -}SysParaInfoItem; - -static const SysParaInfoItem SYSPARA_LIST[] = { - {(char *)"DeviceType", GetDeviceType}, - {(char *)"Manufacture", GetManufacture}, - {(char *)"Brand", GetBrand}, - {(char *)"MarketName", GetMarketName}, - {(char *)"ProductSeries", GetProductSeries}, - {(char *)"ProductModel", GetProductModel}, - {(char *)"SoftwareModel", GetSoftwareModel}, - {(char *)"HardwareModel", GetHardwareModel}, - {(char *)"Serial", GetSerial}, - {(char *)"OSFullName", GetOSFullName}, - {(char *)"DisplayVersion", GetDisplayVersion}, - {(char *)"BootloaderVersion", GetBootloaderVersion}, - {(char *)"GetSecurityPatchTag", GetSecurityPatchTag}, - {(char *)"AbiList", GetAbiList}, - {(char *)"IncrementalVersion", GetIncrementalVersion}, - {(char *)"VersionId", GetVersionId}, - {(char *)"BuildType", GetBuildType}, - {(char *)"BuildUser", GetBuildUser}, - {(char *)"BuildHost", GetBuildHost}, - {(char *)"BuildTime", GetBuildTime}, - {(char *)"BuildRootHash", GetBuildRootHash}, - {(char *)"GetOsReleaseType", GetOsReleaseType}, - {(char *)"GetHardwareProfile", GetHardwareProfile}, -}; - -int32_t SysParaApiDumpCmd() -{ - int index = 0; - int dumpInfoItemNum = (sizeof(SYSPARA_LIST) / sizeof(SYSPARA_LIST[0])); - const char *temp = NULL; - printf("Begin dump syspara\r\n"); - printf("=======================\r\n"); - while (index < dumpInfoItemNum) { - temp = SYSPARA_LIST[index].getInfoValue(); - printf("%s:%s\r\n", SYSPARA_LIST[index].infoName, temp); - index++; - } - printf("FirstApiVersion:%d\r\n", GetFirstApiVersion()); - printf("GetSerial:%s\r\n", GetSerial()); - char udid[65] = {0}; - GetDevUdid(udid, sizeof(udid)); - printf("GetDevUdid:%s\r\n", udid); - printf("Version:%d.%d.%d.%d\r\n", - GetMajorVersion(), GetSeniorVersion(), GetFeatureVersion(), GetBuildVersion()); - printf("GetSdkApiVersion:%d\r\n", GetSdkApiVersion()); - printf("GetSystemCommitId:%lld\r\n", GetSystemCommitId()); - printf("=======================\r\n"); - printf("End dump syspara\r\n"); - return 0; -} - static void ParamServiceTask(int *arg) { (void)arg; PARAM_LOGI("ParamServiceTask start"); - SysParaApiDumpCmd(); while (1) { CheckAndSavePersistParam(); - PARAM_LOGI("CheckAndSavePersistParam"); - printf("CheckAndSavePersistParam \n"); osDelay(OS_DELAY); } } void LiteParamService(void) { - static init = 0; - if (init) { - printf("LiteParamService has been init \n"); - return; - } - init = 1; EnableInitLog(INIT_INFO); - printf("LiteParamService \n"); + PARAM_LOGI("LiteParamService"); InitParamService(); // get persist param LoadPersistParams(); diff --git a/services/utils/init_utils.c b/services/utils/init_utils.c index be951fbdd524bbd8ebe676239249360a5764ea02..eb48c348b799a2a4272cde29486093b560f2b910 100644 --- a/services/utils/init_utils.c +++ b/services/utils/init_utils.c @@ -107,7 +107,10 @@ gid_t DecodeGid(const char *name) return -1; } } - struct group *data = NULL; + struct group *data = getgrnam(name); + if (data != NULL) { + return data->gr_gid; + } while ((data = getgrent()) != NULL) { if ((data->gr_name != NULL) && (strcmp(data->gr_name, name) == 0)) { gid = data->gr_gid; diff --git a/test/fuzztest/systemdumpparameters_fuzzer/systemdumpparameters_fuzzer.cpp b/test/fuzztest/systemdumpparameters_fuzzer/systemdumpparameters_fuzzer.cpp index b055a1f623c8514bf83056290c6ad104504bc0dd..2a74e1a6818e3ae5c177a11ef2a19aba1da73de0 100644 --- a/test/fuzztest/systemdumpparameters_fuzzer/systemdumpparameters_fuzzer.cpp +++ b/test/fuzztest/systemdumpparameters_fuzzer/systemdumpparameters_fuzzer.cpp @@ -24,7 +24,7 @@ namespace OHOS { CloseStdout(); std::string str(reinterpret_cast(data), size); int verbose = atoi(str.c_str()); - SystemDumpParameters(verbose, nullptr); + SystemDumpParameters(verbose, -1, nullptr); return true; } } diff --git a/test/moduletest/param_test_cmds.c b/test/moduletest/param_test_cmds.c index 510e2d5c3add1280c90b0e703c94ec0be830d2db..ef3095fd73d1aa45c27f1efa0e4b036b5774a41b 100644 --- a/test/moduletest/param_test_cmds.c +++ b/test/moduletest/param_test_cmds.c @@ -25,6 +25,7 @@ #include "plugin_test.h" #include "service_watcher.h" #include "parameter.h" +#include "param_base.h" #define MAX_THREAD_NUMBER 100 #define MAX_NUMBER 10 @@ -41,7 +42,6 @@ static char *GetLocalBuffer(uint32_t *buffSize) } int g_stop = 0; -extern void TestReader(); void *CmdReader(void *args) { (void)srand((unsigned)time(NULL)); @@ -63,11 +63,15 @@ void *CmdReader(void *args) static int32_t BShellParamCmdRead(BShellHandle shell, int32_t argc, char *argv[]) { - TestReader(); PLUGIN_CHECK(argc >= 1, return -1, "Invalid parameter"); + if (argc == 1) { +#ifdef PARAM_TEST_PERFORMANCE + TestParameterReaderPerformance(); +#endif + return 0; + } static pthread_t thread = 0; PLUGIN_LOGV("BShellParamCmdWatch %s, threadId %d", argv[1], thread); -#if 0 if (strcmp(argv[1], "start") == 0) { if (thread != 0) { return 0; @@ -83,7 +87,6 @@ static int32_t BShellParamCmdRead(BShellHandle shell, int32_t argc, char *argv[] pthread_join(thread, NULL); thread = 0; } -#endif return 0; } diff --git a/test/unittest/param/client_unittest.cpp b/test/unittest/param/client_unittest.cpp index 66b6b9565678f6e690a038cbe56d991e55773632..19f4dfe9581d14f3119da5b9d34b3704e0952784 100644 --- a/test/unittest/param/client_unittest.cpp +++ b/test/unittest/param/client_unittest.cpp @@ -212,7 +212,7 @@ HWTEST_F(ClientUnitTest, TestClient_03, TestSize.Level0) { // 3 Traversal test TestParamTraversal(); - SystemDumpParameters(1, NULL); + SystemDumpParameters(1, -1, NULL); } HWTEST_F(ClientUnitTest, TestClient_04, TestSize.Level0) diff --git a/test/unittest/param/param_stub.cpp b/test/unittest/param/param_stub.cpp index da3f9b27f75943a6be085e540e9c993b5df9a417..4de58016bb0b4a97d65294795fc0c19ade8fd572 100644 --- a/test/unittest/param/param_stub.cpp +++ b/test/unittest/param/param_stub.cpp @@ -79,7 +79,7 @@ static const char *TestGetParamLabel(const char *paraName) { BEGET_LOGI("TestGetParamLabel %s", paraName); if (paraName == nullptr) { - return 0; + return nullptr; } for (size_t i = 0; i < ARRAY_LENGTH(selinuxLabels); i++) { if (strncmp(selinuxLabels[i][0], paraName, strlen(selinuxLabels[i][0])) == 0) { @@ -503,16 +503,13 @@ void PrepareInitUnitTestEnv(void) InitAddPreCfgLoadHook(0, TestHook); InitAddPostCfgLoadHook(0, TestHook); InitAddPostPersistParamLoadHook(0, TestHook); - // ini system - SystemInit(); - SystemPrepare(); - SystemConfig(); -#else + LoadSpecialParam(); +#endif // read default parameter from system LoadDefaultParams("/system/etc/param/ohos_const", LOAD_PARAM_NORMAL); LoadDefaultParams("/vendor/etc/param", LOAD_PARAM_NORMAL); LoadDefaultParams("/system/etc/param", LOAD_PARAM_ONLY_ADD); -#endif + // read ut parameters LoadDefaultParams(STARTUP_INIT_UT_PATH "/system/etc/param/ohos_const", LOAD_PARAM_NORMAL); LoadDefaultParams(STARTUP_INIT_UT_PATH "/vendor/etc/param", LOAD_PARAM_NORMAL); @@ -716,15 +713,22 @@ int setfilecon(const char *name, const char *content) ParamLabelIndex *TestGetParamLabelIndex(const char *name) { - if (GetParamWorkSpace() == NULL && GetParamWorkSpace()->selinuxSpace.getParamLabelIndex == NULL) { - return NULL; + static ParamLabelIndex labelIndex = {0}; + uint32_t index = 0; + ParamWorkSpace *paramWorkspace = GetParamWorkSpace(); + if (paramWorkspace == nullptr) { + return nullptr; } - uint32_t index = (uint32_t)GetParamWorkSpace()->selinuxSpace.getParamLabelIndex(name); - if (index >= GetParamWorkSpace()->maxLabelIndex) { - return NULL; +#ifdef PARAM_SUPPORT_SELINUX + if (paramWorkspace->selinuxSpace.getParamLabelIndex == nullptr) { + return nullptr; } - static ParamLabelIndex labelIndex = {0}; - WorkSpace *workspace = GetParamWorkSpace()->workSpace[index]; + index = (uint32_t)paramWorkspace->selinuxSpace.getParamLabelIndex(name) + WORKSPACE_INDEX_BASE; + if (index >= paramWorkspace->maxLabelIndex) { + return nullptr; + } +#endif + WorkSpace *workspace = paramWorkspace->workSpace[index]; labelIndex.workspace = workspace; PARAM_CHECK(labelIndex.workspace != NULL, return NULL, "Invalid workSpace"); labelIndex.selinuxLabelIndex = labelIndex.workspace->spaceIndex; diff --git a/test/unittest/param/param_unittest.cpp b/test/unittest/param/param_unittest.cpp index fb87cfcda1afb9b7a25c73621c32692d3d2fb531..5f7241f0e4a078cfacb9c92e74f6605a3cde6245 100644 --- a/test/unittest/param/param_unittest.cpp +++ b/test/unittest/param/param_unittest.cpp @@ -298,7 +298,7 @@ public: int TestDumpParamMemory() { - SystemDumpParameters(1, NULL); + SystemDumpParameters(1, -1, NULL); return 0; } }; @@ -646,6 +646,7 @@ HWTEST_F(ParamUnitTest, TestParamCache, TestSize.Level0) EXPECT_EQ(strcmp(value, "2222222"), 0); CachedParameterDestroy(cacheHandle3); } +#ifdef PARAM_SUPPORT_SELINUX HWTEST_F(ParamUnitTest, TestInitParameterClient, TestSize.Level0) { InitParameterClient(); @@ -659,4 +660,5 @@ HWTEST_F(ParamUnitTest, TestInitParameterClient, TestSize.Level0) EXPECT_EQ(ret, 0); } #endif +#endif } diff --git a/test/unittest/param/paramservice_unittest.cpp b/test/unittest/param/paramservice_unittest.cpp index f746d1d70de51ad8069a55dc321fdbbf7657aa98..f9c6d9e200fe33994a95c4357a8f7a760cbd2278 100644 --- a/test/unittest/param/paramservice_unittest.cpp +++ b/test/unittest/param/paramservice_unittest.cpp @@ -550,9 +550,11 @@ HWTEST_F(ParamServiceUnitTest, TestServiceCtrl, TestSize.Level0) ParamServiceUnitTest test; int ret = test.TestServiceCtrl("server1", 0770); EXPECT_NE(ret, 0); +#ifdef PARAM_SUPPORT_SELINUX // selinux forbid ret = test.TestServiceCtrl("server2", 0772); EXPECT_NE(ret, 0); +#endif ret = 0; } @@ -562,24 +564,32 @@ HWTEST_F(ParamServiceUnitTest, TestPowerCtrl, TestSize.Level0) int ret = test.TestPowerCtrl("reboot,shutdown", 0770); EXPECT_NE(ret, 0); ret = test.TestPowerCtrl("reboot,shutdown", 0772); +#ifdef PARAM_SUPPORT_SELINUX // selinux forbid EXPECT_NE(ret, 0); +#endif ret = test.TestPowerCtrl("reboot,updater", 0770); EXPECT_NE(ret, 0); ret = test.TestPowerCtrl("reboot,updater", 0772); +#ifdef PARAM_SUPPORT_SELINUX // selinux forbid EXPECT_NE(ret, 0); +#endif ret = test.TestPowerCtrl("reboot,flashd", 0770); EXPECT_NE(ret, 0); ret = test.TestPowerCtrl("reboot,flashd", 0772); +#ifdef PARAM_SUPPORT_SELINUX // selinux forbid EXPECT_NE(ret, 0); +#endif ret = test.TestPowerCtrl("reboot", 0770); EXPECT_NE(ret, 0); ret = test.TestPowerCtrl("reboot", 0772); +#ifdef PARAM_SUPPORT_SELINUX // selinux forbid EXPECT_NE(ret, 0); +#endif ParamServiceStop(); } diff --git a/ueventd/ueventd_device_handler.c b/ueventd/ueventd_device_handler.c index d043f04a741c3aab9ae2d21e2455ffbbe91cd95d..a9d0fc1cb1b71a86261046979a2866a5d25aee5a 100644 --- a/ueventd/ueventd_device_handler.c +++ b/ueventd/ueventd_device_handler.c @@ -113,7 +113,7 @@ static void SetDeviceLable(const char *path) continue; } if (gap < 0) { // end with '/' - break; + return; } if (memcpy_s(buffer, PATH_MAX, path, p - path - 1) != EOK) {