diff --git a/services/BUILD.gn b/services/BUILD.gn index 6c0928027..c3283382e 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -123,6 +123,7 @@ if (defined(ohos_lite)) { sources += init_common_sources include_dirs = [ + "//base/customization/config_policy/interfaces/innerkits/include", "//base/security/access_token/interfaces/innerkits/token_setproc/include", "//base/security/access_token/interfaces/innerkits/nativetoken/include", "//base/startup/init_lite/interfaces/innerkits/sandbox/include", @@ -139,6 +140,7 @@ if (defined(ohos_lite)) { "//third_party/bounds_checking_function/include", ] deps = [ + "//base/customization/config_policy/frameworks/config_policy:configpolicy_util_for_init_static", "//base/security/access_token/interfaces/innerkits/nativetoken:libnativetoken", "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", "//base/startup/init_lite/interfaces/innerkits:libfsmanager_static", diff --git a/services/init/standard/init.c b/services/init/standard/init.c index ea4afe6ea..a35b7ca8d 100644 --- a/services/init/standard/init.c +++ b/services/init/standard/init.c @@ -23,6 +23,8 @@ #include #include #include + +#include "config_policy_utils.h" #include "device.h" #include "fd_holder_service.h" #include "fs_manager/fs_manager.h" @@ -289,23 +291,38 @@ static void IsEnableSandbox(void) } } +// Init provide this function for static lib link +__attribute__((weak)) int SystemGetParameter(const char *name, char *value, unsigned int *len) +{ + return SystemReadParam(name, value, len); +} + +static void InitLoadParamFiles(void) +{ + // Load const params, these can't be override! + LoadDefaultParams("/system/etc/param/ohos_const", LOAD_PARAM_NORMAL); + CfgFiles *files = GetCfgFiles("etc/param"); + for (int i = MAX_CFG_POLICY_DIRS_CNT - 1; files && i >= 0; i--) { + if (files->paths[i]) { + LoadDefaultParams(files->paths[i], LOAD_PARAM_ONLY_ADD); + } + } + FreeCfgFiles(files); +} + void SystemConfig(void) { InitServiceSpace(); + InitParamService(); InitParseGroupCfg(); PluginManagerInit(); - - InitParamService(); RegisterBootStateChange(BootStateChange); // load SELinux context and policy // Do not move position! SystemLoadSelinux(); - // parse parameters - LoadDefaultParams("/system/etc/param/ohos_const", LOAD_PARAM_NORMAL); - LoadDefaultParams("/vendor/etc/param", LOAD_PARAM_NORMAL); - LoadDefaultParams("/system/etc/param", LOAD_PARAM_ONLY_ADD); + InitLoadParamFiles(); // read config ReadConfig(); INIT_LOGI("Parse init config file done."); diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 9864d1169..7b4cab731 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -134,6 +134,7 @@ ohos_unittest("init_ut") { configs = [ "//base/startup/init_lite/test/unittest:utest_config" ] include_dirs = [ + "//base/customization/config_policy/interfaces/innerkits/include", "//base/startup/init_lite/services/init/standard", "//base/startup/init_lite/interfaces/innerkits/include", "//base/startup/init_lite/interfaces/innerkits/fd_holder", @@ -174,6 +175,7 @@ ohos_unittest("init_ut") { ] deps = [ + "//base/customization/config_policy/frameworks/config_policy:configpolicy_util_for_init_static", "//base/security/access_token/interfaces/innerkits/nativetoken:libnativetoken", "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",