Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
26cea69a
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
接近 2 年 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
26cea69a
编写于
3月 31, 2022
作者:
X
xlei1030
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
代码结构调整
Signed-off-by:
N
xlei1030
<
xionglei6@huawei.com
>
上级
7717a9bf
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
92 addition
and
86 deletion
+92
-86
services/param/include/param_service.h
services/param/include/param_service.h
+7
-1
services/param/service/param_service.c
services/param/service/param_service.c
+85
-85
未找到文件。
services/param/include/param_service.h
浏览文件 @
26cea69a
...
...
@@ -33,8 +33,14 @@ struct CmdLineEntry {
int
set
;
};
typedef
struct
cmdLineInfo
{
const
char
*
name
;
int
(
*
processor
)(
const
char
*
name
,
const
char
*
value
,
int
);
}
cmdLineInfo
;
int
WriteParam
(
const
WorkSpace
*
workSpace
,
const
char
*
name
,
const
char
*
value
,
uint32_t
*
dataIndex
,
int
onlyAdd
);
int
CheckAndResetSnValue
(
char
*
value
);
int
CommonDealFun
(
const
char
*
name
,
const
char
*
value
,
int
);
int
SnDealFun
(
const
char
*
name
,
const
char
*
value
,
int
);
int
InitPersistParamWorkSpace
(
const
ParamWorkSpace
*
workSpace
);
void
ClosePersistParamWorkSpace
(
void
);
...
...
services/param/service/param_service.c
浏览文件 @
26cea69a
...
...
@@ -123,23 +123,11 @@ static int CheckParamValue(const WorkSpace *workSpace, const ParamTrieNode *node
int
WriteParam
(
const
WorkSpace
*
workSpace
,
const
char
*
name
,
const
char
*
value
,
uint32_t
*
dataIndex
,
int
onlyAdd
)
{
char
strValue
[
PARAM_CONST_VALUE_LEN_MAX
+
1
]
=
{};
int
res
=
strcpy_s
(
strValue
,
strlen
(
value
)
+
1
,
value
);
if
(
res
!=
EOK
)
{
PARAM_LOGE
(
"Error, strcpy failed!"
);
return
-
1
;
}
PARAM_CHECK
(
workSpace
!=
NULL
,
return
PARAM_CODE_INVALID_PARAM
,
"Invalid workSpace"
);
PARAM_CHECK
(
strV
alue
!=
NULL
&&
name
!=
NULL
,
return
PARAM_CODE_INVALID_PARAM
,
"Invalid name or value"
);
PARAM_CHECK
(
v
alue
!=
NULL
&&
name
!=
NULL
,
return
PARAM_CODE_INVALID_PARAM
,
"Invalid name or value"
);
ParamTrieNode
*
node
=
FindTrieNode
(
workSpace
,
name
,
strlen
(
name
),
NULL
);
int
ret
=
CheckParamValue
(
workSpace
,
node
,
name
,
strValue
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Invalid param value param: %s=%s"
,
name
,
strValue
);
if
(
strcmp
(
name
,
"ohos.boot.sn"
)
==
0
&&
CheckAndResetSnValue
(
strValue
)
!=
0
)
{
PARAM_LOGE
(
"Error,Reset sn value failed!"
);
return
PARAM_CODE_INVALID_PARAM
;
}
int
ret
=
CheckParamValue
(
workSpace
,
node
,
name
,
value
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Invalid param value param: %s=%s"
,
name
,
value
);
if
(
node
!=
NULL
&&
node
->
dataIndex
!=
0
)
{
if
(
dataIndex
!=
NULL
)
{
...
...
@@ -148,45 +136,9 @@ int WriteParam(const WorkSpace *workSpace, const char *name, const char *value,
if
(
onlyAdd
)
{
return
0
;
}
return
UpdateParam
(
workSpace
,
&
node
->
dataIndex
,
name
,
strValue
);
}
return
AddParam
((
WorkSpace
*
)
workSpace
,
name
,
strValue
,
dataIndex
);
}
int
CheckAndResetSnValue
(
char
*
value
)
{
char
snFile
[
PARAM_CONST_VALUE_LEN_MAX
]
=
{};
int
res
=
0
;
if
(
value
[
0
]
==
'/'
)
{
res
=
strcpy_s
(
snFile
,
strlen
(
value
)
+
1
,
value
);
if
(
res
!=
EOK
)
{
PARAM_LOGE
(
"Error, strcpy failed!"
);
return
-
1
;
}
}
else
{
return
0
;
}
char
*
data
=
ReadFileData
(
snFile
);
if
(
data
==
NULL
)
{
PARAM_LOGE
(
"Error, Read sn file failed!"
);
return
-
1
;
}
int
index
=
0
;
for
(
size_t
i
=
0
;
i
<
strlen
(
data
);
i
++
)
{
if
(
*
(
data
+
i
)
!=
':'
)
{
*
(
data
+
index
)
=
*
(
data
+
i
);
index
++
;
}
}
data
[
index
]
=
'\0'
;
res
=
strcpy_s
(
value
,
strlen
(
data
)
+
1
,
data
);
if
(
res
!=
EOK
)
{
PARAM_LOGE
(
"Error, strcpy failed!"
);
return
-
1
;
return
UpdateParam
(
workSpace
,
&
node
->
dataIndex
,
name
,
value
);
}
return
0
;
return
AddParam
((
WorkSpace
*
)
workSpace
,
name
,
value
,
dataIndex
)
;
}
PARAM_STATIC
int
AddSecurityLabel
(
const
ParamAuditData
*
auditData
,
void
*
context
)
...
...
@@ -736,21 +688,21 @@ static int GetParamValueFromBuffer(const char *name, const char *buffer, char *v
static
int
LoadParamFromCmdLine
(
void
)
{
int
ret
;
static
const
c
har
*
cmdLines
[]
=
{
OHOS_BOOT
"hardware"
,
OHOS_BOOT
"bootgroup"
,
OHOS_BOOT
"reboot_reason"
,
OHOS_BOOT
"sn"
,
static
const
c
mdLineInfo
cmdLines
[]
=
{
{
OHOS_BOOT
"hardware"
,
CommonDealFun
}
,
{
OHOS_BOOT
"bootgroup"
,
CommonDealFun
}
,
{
OHOS_BOOT
"reboot_reason"
,
CommonDealFun
}
,
{
OHOS_BOOT
"sn"
,
SnDealFun
}
,
#ifdef STARTUP_INIT_TEST
OHOS_BOOT
"mem"
,
OHOS_BOOT
"console"
,
OHOS_BOOT
"mmz"
,
OHOS_BOOT
"androidboot.selinux"
,
OHOS_BOOT
"init"
,
OHOS_BOOT
"root"
,
OHOS_BOOT
"uuid"
,
OHOS_BOOT
"rootfstype"
,
OHOS_BOOT
"blkdevparts"
{
OHOS_BOOT
"mem"
,
CommonDealFun
}
,
{
OHOS_BOOT
"console"
,
CommonDealFun
}
,
{
OHOS_BOOT
"mmz"
,
CommonDealFun
}
,
{
OHOS_BOOT
"androidboot.selinux"
,
CommonDealFun
}
,
{
OHOS_BOOT
"init"
,
CommonDealFun
}
,
{
OHOS_BOOT
"root"
,
CommonDealFun
}
,
{
OHOS_BOOT
"uuid"
,
CommonDealFun
}
,
{
OHOS_BOOT
"rootfstype"
,
CommonDealFun
}
,
{
OHOS_BOOT
"blkdevparts"
,
CommonDealFun
}
#endif
};
char
*
data
=
ReadFileData
(
PARAM_CMD_LINE
);
...
...
@@ -761,29 +713,15 @@ static int LoadParamFromCmdLine(void)
for
(
size_t
i
=
0
;
i
<
ARRAY_LENGTH
(
cmdLines
);
i
++
)
{
#ifdef BOOT_EXTENDED_CMDLINE
ret
=
GetParamValueFromBuffer
(
cmdLines
[
i
],
BOOT_EXTENDED_CMDLINE
,
value
,
PARAM_CONST_VALUE_LEN_MAX
);
ret
=
GetParamValueFromBuffer
(
cmdLines
[
i
]
.
name
,
BOOT_EXTENDED_CMDLINE
,
value
,
PARAM_CONST_VALUE_LEN_MAX
);
if
(
ret
!=
0
)
{
ret
=
GetParamValueFromBuffer
(
cmdLines
[
i
],
data
,
value
,
PARAM_CONST_VALUE_LEN_MAX
);
ret
=
GetParamValueFromBuffer
(
cmdLines
[
i
]
.
name
,
data
,
value
,
PARAM_CONST_VALUE_LEN_MAX
);
}
#else
ret
=
GetParamValueFromBuffer
(
cmdLines
[
i
],
data
,
value
,
PARAM_CONST_VALUE_LEN_MAX
);
ret
=
GetParamValueFromBuffer
(
cmdLines
[
i
]
.
name
,
data
,
value
,
PARAM_CONST_VALUE_LEN_MAX
);
#endif
//if cmdline not set sn or set sn value is null,read sn from default file
if
(
strcmp
(
cmdLines
[
i
],
"ohos.boot.sn"
)
==
0
&&
ret
!=
0
)
{
ret
=
0
;
strcpy_s
(
value
,
strlen
(
SN_FILE
)
+
1
,
SN_FILE
);
}
if
(
ret
==
0
)
{
PARAM_LOGV
(
"Add param from cmdline %s %s"
,
cmdLines
[
i
],
value
);
ret
=
CheckParamName
(
cmdLines
[
i
],
0
);
PARAM_CHECK
(
ret
==
0
,
break
,
"Invalid name %s"
,
cmdLines
[
i
]);
PARAM_LOGV
(
"**** cmdLines[%d] %s, value %s"
,
i
,
cmdLines
[
i
],
value
);
ret
=
WriteParam
(
&
g_paramWorkSpace
.
paramSpace
,
cmdLines
[
i
],
value
,
NULL
,
0
);
PARAM_CHECK
(
ret
==
0
,
break
,
"Failed to write param %s %s"
,
cmdLines
[
i
],
value
);
}
else
{
PARAM_LOGE
(
"Can not find arrt %s"
,
cmdLines
[
i
]);
}
cmdLines
[
i
].
processor
(
cmdLines
[
i
].
name
,
value
,
ret
);
}
PARAM_LOGV
(
"Parse cmdline finish %s"
,
PARAM_CMD_LINE
);
free
(
data
);
...
...
@@ -791,6 +729,68 @@ static int LoadParamFromCmdLine(void)
return
0
;
}
int
CommonDealFun
(
const
char
*
name
,
const
char
*
value
,
int
res
)
{
PARAM_LOGI
(
"Add param from cmdline %s %s"
,
name
,
value
);
int
ret
=
0
;
if
(
res
==
0
)
{
ret
=
CheckParamName
(
name
,
0
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Invalid name %s"
,
name
);
PARAM_LOGV
(
"**** name %s, value %s"
,
name
,
value
);
ret
=
WriteParam
(
&
g_paramWorkSpace
.
paramSpace
,
name
,
value
,
NULL
,
0
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Failed to write param %s %s"
,
name
,
value
);
PARAM_LOGE
(
"----Debug1 name is:%s , value is :%s!"
,
name
,
value
);
}
else
{
PARAM_LOGE
(
"Can not find arrt %s"
,
name
);
}
return
ret
;
}
int
SnDealFun
(
const
char
*
name
,
const
char
*
value
,
int
res
)
{
PARAM_LOGI
(
"Add SN param from cmdline %s %s"
,
name
,
value
);
int
ret
=
CheckParamName
(
name
,
0
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Invalid name %s"
,
name
);
char
*
data
=
NULL
;
if
(
res
!=
0
)
{
//if cmdline not set sn or set sn value is null,read sn from default file
data
=
ReadFileData
(
SN_FILE
);
if
(
data
==
NULL
)
{
PARAM_LOGE
(
"Error, Read sn from default file failed!"
);
return
-
1
;
}
PARAM_LOGE
(
"----Debug2 name is:%s , value is :%s!"
,
name
,
data
);
}
else
if
(
value
[
0
]
==
'/'
)
{
data
=
ReadFileData
(
value
);
if
(
data
==
NULL
)
{
PARAM_LOGE
(
"Error, Read sn from cmdline file failed!"
);
return
-
1
;
}
PARAM_LOGE
(
"----Debug3 name is:%s , value is :%s!"
,
name
,
data
);
}
else
{
PARAM_LOGV
(
"**** name %s, value %s"
,
name
,
value
);
ret
=
WriteParam
(
&
g_paramWorkSpace
.
paramSpace
,
name
,
value
,
NULL
,
0
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Failed to write param %s %s"
,
name
,
value
);
PARAM_LOGE
(
"----Debug4 name is:%s , value is :%s!"
,
name
,
value
);
return
ret
;
}
int
index
=
0
;
for
(
size_t
i
=
0
;
i
<
strlen
(
data
);
i
++
)
{
if
(
*
(
data
+
i
)
!=
':'
)
{
*
(
data
+
index
)
=
*
(
data
+
i
);
index
++
;
}
}
data
[
index
]
=
'\0'
;
PARAM_LOGE
(
"----Debug5 name is:%s , value is :%s!"
,
name
,
data
);
PARAM_LOGV
(
"**** name %s, value %s"
,
name
,
data
);
ret
=
WriteParam
(
&
g_paramWorkSpace
.
paramSpace
,
name
,
data
,
NULL
,
0
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Failed to write param %s %s"
,
name
,
data
);
return
ret
;
}
int
SystemWriteParam
(
const
char
*
name
,
const
char
*
value
)
{
PARAM_CHECK
(
name
!=
NULL
&&
value
!=
NULL
,
return
-
1
,
"The name is null"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录