Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
02b4a78f
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
1 年多 前同步成功
通知
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看板
提交
02b4a78f
编写于
12月 06, 2022
作者:
C
cheng_jinsong
浏览文件
操作
浏览文件
下载
差异文件
read param 优化
Signed-off-by:
N
cheng_jinsong
<
chengjinsong2@huawei.com
>
上级
1f9ee78a
6f5ed9ed
变更
34
隐藏空白更改
内联
并排
Showing
34 changed file
with
233 addition
and
329 deletion
+233
-329
begetd.gni
begetd.gni
+5
-1
services/begetctl/BUILD.gn
services/begetctl/BUILD.gn
+3
-0
services/begetctl/param_cmd.c
services/begetctl/param_cmd.c
+1
-1
services/etc/BUILD.gn
services/etc/BUILD.gn
+19
-1
services/etc/group
services/etc/group
+2
-1
services/etc/param/ohos.para
services/etc/param/ohos.para
+2
-2
services/etc/param/ohos_const/ohos.para
services/etc/param/ohos_const/ohos.para
+2
-2
services/etc/passwd
services/etc/passwd
+1
-0
services/etc_lite/param/ohos_const/ohos.para
services/etc_lite/param/ohos_const/ohos.para
+3
-3
services/include/param/sys_param.h
services/include/param/sys_param.h
+1
-1
services/init/standard/init.c
services/init/standard/init.c
+4
-3
services/modules/selinux/selinux_adp.c
services/modules/selinux/selinux_adp.c
+12
-1
services/param/adapter/param_dac.c
services/param/adapter/param_dac.c
+5
-1
services/param/adapter/param_selinux.c
services/param/adapter/param_selinux.c
+1
-1
services/param/base/BUILD.gn
services/param/base/BUILD.gn
+4
-0
services/param/base/param_base.c
services/param/base/param_base.c
+79
-186
services/param/base/param_base.h
services/param/base/param_base.h
+3
-1
services/param/base/param_include.h
services/param/base/param_include.h
+12
-6
services/param/base/param_trie.c
services/param/base/param_trie.c
+1
-1
services/param/include/param_manager.h
services/param/include/param_manager.h
+1
-1
services/param/include/param_osadp.h
services/param/include/param_osadp.h
+22
-15
services/param/include/param_trie.h
services/param/include/param_trie.h
+1
-1
services/param/linux/param_request.c
services/param/linux/param_request.c
+1
-3
services/param/liteos/BUILD.gn
services/param/liteos/BUILD.gn
+0
-4
services/param/liteos/param_litedac.c
services/param/liteos/param_litedac.c
+2
-2
services/param/liteos/param_service.c
services/param/liteos/param_service.c
+1
-68
services/utils/init_utils.c
services/utils/init_utils.c
+4
-1
test/fuzztest/systemdumpparameters_fuzzer/systemdumpparameters_fuzzer.cpp
...stemdumpparameters_fuzzer/systemdumpparameters_fuzzer.cpp
+1
-1
test/moduletest/param_test_cmds.c
test/moduletest/param_test_cmds.c
+7
-4
test/unittest/param/client_unittest.cpp
test/unittest/param/client_unittest.cpp
+1
-1
test/unittest/param/param_stub.cpp
test/unittest/param/param_stub.cpp
+18
-14
test/unittest/param/param_unittest.cpp
test/unittest/param/param_unittest.cpp
+3
-1
test/unittest/param/paramservice_unittest.cpp
test/unittest/param/paramservice_unittest.cpp
+10
-0
ueventd/ueventd_device_handler.c
ueventd/ueventd_device_handler.c
+1
-1
未找到文件。
begetd.gni
浏览文件 @
02b4a78f
...
...
@@ -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
}
}
services/begetctl/BUILD.gn
浏览文件 @
02b4a78f
...
...
@@ -160,6 +160,9 @@ if (defined(ohos_lite)) {
]
}
if (startup_init_test_performance) {
defines += [ "PARAM_TEST_PERFORMANCE" ]
}
install_images = [ "system" ]
install_enable = true
...
...
services/begetctl/param_cmd.c
浏览文件 @
02b4a78f
...
...
@@ -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
;
...
...
services/etc/BUILD.gn
浏览文件 @
02b4a78f
...
...
@@ -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"
}
...
...
services/etc/group
浏览文件 @
02b4a78f
...
...
@@ -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:
services/etc/param/ohos.para
浏览文件 @
02b4a78f
...
...
@@ -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
...
...
services/etc/param/ohos_const/ohos.para
浏览文件 @
02b4a78f
...
...
@@ -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
services/etc/passwd
浏览文件 @
02b4a78f
...
...
@@ -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
services/etc_lite/param/ohos_const/ohos.para
浏览文件 @
02b4a78f
...
...
@@ -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
services/include/param/sys_param.h
浏览文件 @
02b4a78f
...
...
@@ -24,7 +24,7 @@ extern "C" {
#endif
typedef
uint32_t
ParamHandle
;
typedef
void
*
CachedHandle
;
typedef
void
*
CachedHandle
;
typedef
struct
{
uint8_t
updaterMode
;
...
...
services/init/standard/init.c
浏览文件 @
02b4a78f
...
...
@@ -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"
);
...
...
services/modules/selinux/selinux_adp.c
浏览文件 @
02b4a78f
...
...
@@ -19,6 +19,7 @@
#include "init_hook.h"
#include "init_module_engine.h"
#include "plugin_adapter.h"
#include "securec.h"
#include <policycoreutils.h>
#include <selinux/selinux.h>
...
...
@@ -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
;
}
...
...
services/param/adapter/param_dac.c
浏览文件 @
02b4a78f
...
...
@@ -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
;
...
...
services/param/adapter/param_selinux.c
浏览文件 @
02b4a78f
...
...
@@ -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
;
}
...
...
services/param/base/BUILD.gn
浏览文件 @
02b4a78f
...
...
@@ -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
...
...
services/param/base/param_base.c
浏览文件 @
02b4a78f
...
...
@@ -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
.
work
space
,
testParamName
,
strlen
(
testParamName
),
&
index
);
if
(
node
!=
NULL
&&
node
->
dataIndex
!=
0
)
{
handle
=
PARAM_HANDLE
(
space
,
node
->
dataIndex
);
handle
=
PARAM_HANDLE
(
labelIndex
.
work
space
,
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
(
&
param
->
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
services/param/base/param_base.h
浏览文件 @
02b4a78f
...
...
@@ -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
}
...
...
services/param/base/param_include.h
浏览文件 @
02b4a78f
...
...
@@ -42,21 +42,27 @@ STATIC_INLINE int CompareParamTrieNode(const ParamTrieNode *node, const char *ke
}
else
if
(
node
->
length
<
keyLen
)
{
return
1
;
}
return
strn
cmp
(
node
->
key
,
key
,
keyLen
);
return
mem
cmp
(
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
;
...
...
services/param/base/param_trie.c
浏览文件 @
02b4a78f
...
...
@@ -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
;
...
...
services/param/include/param_manager.h
浏览文件 @
02b4a78f
...
...
@@ -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
);
\
...
...
services/param/include/param_osadp.h
浏览文件 @
02b4a78f
...
...
@@ -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
...
...
services/param/include/param_trie.h
浏览文件 @
02b4a78f
...
...
@@ -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
)
...
...
services/param/linux/param_request.c
浏览文件 @
02b4a78f
...
...
@@ -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
...
...
services/param/liteos/BUILD.gn
浏览文件 @
02b4a78f
...
...
@@ -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" ]
...
...
services/param/liteos/param_litedac.c
浏览文件 @
02b4a78f
...
...
@@ -52,7 +52,7 @@ static int CheckFilePermission(const ParamSecurityLabel *localLabel, const char
return
0
;
}
INIT_LOCAL_API
int
DacCheckParamPermission
(
uint32_t
index
,
static
int
Lite
DacCheckParamPermission
(
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
=
Lite
DacCheckParamPermission
;
ops
->
securityFreeLabel
=
FreeLocalSecurityLabel
;
if
(
isInit
)
{
ops
->
securityGetLabel
=
DacGetParamSecurityLabel
;
...
...
services/param/liteos/param_service.c
浏览文件 @
02b4a78f
...
...
@@ -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
();
...
...
services/utils/init_utils.c
浏览文件 @
02b4a78f
...
...
@@ -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
;
...
...
test/fuzztest/systemdumpparameters_fuzzer/systemdumpparameters_fuzzer.cpp
浏览文件 @
02b4a78f
...
...
@@ -24,7 +24,7 @@ namespace OHOS {
CloseStdout
();
std
::
string
str
(
reinterpret_cast
<
const
char
*>
(
data
),
size
);
int
verbose
=
atoi
(
str
.
c_str
());
SystemDumpParameters
(
verbose
,
nullptr
);
SystemDumpParameters
(
verbose
,
-
1
,
nullptr
);
return
true
;
}
}
...
...
test/moduletest/param_test_cmds.c
浏览文件 @
02b4a78f
...
...
@@ -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
;
}
...
...
test/unittest/param/client_unittest.cpp
浏览文件 @
02b4a78f
...
...
@@ -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
)
...
...
test/unittest/param/param_stub.cpp
浏览文件 @
02b4a78f
...
...
@@ -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
;
...
...
test/unittest/param/param_unittest.cpp
浏览文件 @
02b4a78f
...
...
@@ -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
}
test/unittest/param/paramservice_unittest.cpp
浏览文件 @
02b4a78f
...
...
@@ -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
();
}
...
...
ueventd/ueventd_device_handler.c
浏览文件 @
02b4a78f
...
...
@@ -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
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录