!1792 加载初始系统参数时,支持扩展过滤器

Merge pull request !1792 from handy/0226
This commit is contained in:
openharmony_ci 2023-02-28 02:26:58 +00:00 committed by Gitee
commit a5fcc83d55
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 45 additions and 0 deletions

View File

@ -29,6 +29,7 @@ enum INIT_BOOTSTAGE {
INIT_GLOBAL_INIT = 0,
INIT_PRE_PARAM_SERVICE = 10,
INIT_PRE_PARAM_LOAD = 20,
INIT_PARAM_LOAD_FILTER = 25,
INIT_PRE_CFG_LOAD = 30,
INIT_SERVICE_PARSE = 35,
INIT_POST_PERSIST_PARAM_LOAD = 40,
@ -61,6 +62,29 @@ __attribute__((always_inline)) inline int InitAddPreParamLoadHook(int prio, Ohos
return HookMgrAdd(GetBootStageHookMgr(), INIT_PRE_PARAM_LOAD, prio, hook);
}
/**
* @brief Parameter load filter context
*/
typedef struct tagPARAM_LOAD_FILTER_CTX {
const char *name; /* Parameter name */
const char *value; /* Parameter value */
int ignored; /* Ignore this parameter or not */
} PARAM_LOAD_FILTER_CTX;
/**
* @brief Parameter Load Hook function prototype
*
* @param hookInfo hook information
* @param filter filter information context
* @return return 0 if succeed; other values if failed.
*/
typedef int (*ParamLoadFilter)(const HOOK_INFO *hookInfo, PARAM_LOAD_FILTER_CTX *filter);
__attribute__((always_inline)) inline int InitAddParamLoadFilterHook(int prio, ParamLoadFilter filter)
{
return HookMgrAdd(GetBootStageHookMgr(), INIT_PARAM_LOAD_FILTER, prio, (OhosHook)filter);
}
__attribute__((always_inline)) inline int InitAddPreCfgLoadHook(int prio, OhosHook hook)
{
return HookMgrAdd(GetBootStageHookMgr(), INIT_PRE_CFG_LOAD, prio, hook);

View File

@ -236,6 +236,7 @@ static int BootCompleteCmd(const HOOK_INFO *hookInfo, void *executionContext)
// clear hook
HookMgrDel(GetBootStageHookMgr(), INIT_GLOBAL_INIT, NULL);
HookMgrDel(GetBootStageHookMgr(), INIT_PRE_PARAM_SERVICE, NULL);
HookMgrDel(GetBootStageHookMgr(), INIT_PARAM_LOAD_FILTER, NULL);
HookMgrDel(GetBootStageHookMgr(), INIT_PRE_PARAM_LOAD, NULL);
HookMgrDel(GetBootStageHookMgr(), INIT_PRE_CFG_LOAD, NULL);
HookMgrDel(GetBootStageHookMgr(), INIT_SERVICE_PARSE, NULL);

View File

@ -107,6 +107,7 @@ if (defined(ohos_lite)) {
defines = [
"_GNU_SOURCE",
"PARAM_SUPPORT_REAL_CHECK",
"SUPPORT_PARAM_LOAD_HOOK",
]
if (param_base_log) {

View File

@ -17,6 +17,9 @@
#include "param_manager.h"
#include "param_trie.h"
#ifdef SUPPORT_PARAM_LOAD_HOOK
#include "init_module_engine.h"
#endif
/**
* Loading system parameter from /proc/cmdline by the following rules:
@ -206,6 +209,22 @@ static int LoadOneParam_(const uint32_t *context, const char *name, const char *
if (ret != 0) {
return 0;
}
#ifdef SUPPORT_PARAM_LOAD_HOOK
PARAM_LOAD_FILTER_CTX filter;
// Filter by hook
filter.name = name;
filter.value = value;
filter.ignored = 0;
HookMgrExecute(GetBootStageHookMgr(), INIT_PARAM_LOAD_FILTER, (void *)&filter, NULL);
if (filter.ignored) {
PARAM_LOGV("Default parameter [%s] [%s] ignored", name, value);
return 0;
}
#endif
PARAM_LOGV("Add default parameter [%s] [%s]", name, value);
return WriteParam(name, value, NULL, mode & LOAD_PARAM_ONLY_ADD);
}