提交 a31095b3 编写于 作者: H handyohos

Feat: add param load filter hook

add filter hook when loading system parameter from .para files.
Signed-off-by: Nhandyohos <zhangxiaotian@huawei.com>
Change-Id: I6be57c0f58727de6276bd3f10ab3da955edd4702

#I6HRVR
上级 de4c329a
......@@ -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);
......
......@@ -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);
......
......@@ -107,6 +107,7 @@ if (defined(ohos_lite)) {
defines = [
"_GNU_SOURCE",
"PARAM_SUPPORT_REAL_CHECK",
"SUPPORT_PARAM_LOAD_HOOK",
]
if (param_base_log) {
......
......@@ -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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册