Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
e63b8cb7
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e63b8cb7
编写于
3月 23, 2023
作者:
C
cheng_jinsong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init ut memory
Signed-off-by:
N
cheng_jinsong
<
chengjinsong2@huawei.com
>
上级
ed5e8f4d
变更
38
隐藏空白更改
内联
并排
Showing
38 changed file
with
231 addition
and
63 deletion
+231
-63
services/begetctl/BUILD.gn
services/begetctl/BUILD.gn
+1
-0
services/begetctl/param_cmd.c
services/begetctl/param_cmd.c
+1
-0
services/begetctl/shell/shell_bas.c
services/begetctl/shell/shell_bas.c
+3
-0
services/include/init_hashmap.h
services/include/init_hashmap.h
+2
-2
services/init/include/init_group_manager.h
services/init/include/init_group_manager.h
+2
-0
services/init/init_common_service.c
services/init/init_common_service.c
+5
-6
services/init/init_group_manager.c
services/init/init_group_manager.c
+39
-2
services/init/init_service_manager.c
services/init/init_service_manager.c
+23
-9
services/loopevent/loop/le_loop.c
services/loopevent/loop/le_loop.c
+6
-5
services/loopevent/signal/le_signal.c
services/loopevent/signal/le_signal.c
+1
-0
services/loopevent/task/le_asynctask.c
services/loopevent/task/le_asynctask.c
+1
-0
services/loopevent/task/le_streamtask.c
services/loopevent/task/le_streamtask.c
+3
-2
services/loopevent/task/le_task.c
services/loopevent/task/le_task.c
+0
-1
services/loopevent/task/le_watchtask.c
services/loopevent/task/le_watchtask.c
+1
-0
services/loopevent/timer/le_timer.c
services/loopevent/timer/le_timer.c
+1
-0
services/modules/reboot/reboot_static.c
services/modules/reboot/reboot_static.c
+17
-0
services/modules/selinux/selinux_adp.c
services/modules/selinux/selinux_adp.c
+1
-1
services/param/base/param_base.c
services/param/base/param_base.c
+2
-0
services/param/linux/param_request.c
services/param/linux/param_request.c
+15
-2
services/param/manager/param_manager.c
services/param/manager/param_manager.c
+2
-1
services/param/trigger/trigger_manager.c
services/param/trigger/trigger_manager.c
+1
-1
services/param/trigger/trigger_processor.c
services/param/trigger/trigger_processor.c
+2
-0
services/utils/init_hashmap.c
services/utils/init_hashmap.c
+4
-4
test/unittest/deviceinfo/DeviceInfoUnittest.cpp
test/unittest/deviceinfo/DeviceInfoUnittest.cpp
+1
-2
test/unittest/init/cmds_unittest.cpp
test/unittest/init/cmds_unittest.cpp
+1
-1
test/unittest/init/group_unittest.cpp
test/unittest/init/group_unittest.cpp
+16
-5
test/unittest/init/init_unittest.cpp
test/unittest/init/init_unittest.cpp
+1
-3
test/unittest/init/service_unittest.cpp
test/unittest/init/service_unittest.cpp
+6
-0
test/unittest/innerkits/innerkits_unittest.cpp
test/unittest/innerkits/innerkits_unittest.cpp
+13
-2
test/unittest/lite/BUILD.gn
test/unittest/lite/BUILD.gn
+4
-0
test/unittest/loopevent/loopevent_unittest.cpp
test/unittest/loopevent/loopevent_unittest.cpp
+4
-8
test/unittest/loopevent/loopserver_unittest.cpp
test/unittest/loopevent/loopserver_unittest.cpp
+1
-1
test/unittest/loopevent/loopsignal_unittest.cpp
test/unittest/loopevent/loopsignal_unittest.cpp
+1
-0
test/unittest/param/param_stub.cpp
test/unittest/param/param_stub.cpp
+16
-4
test/unittest/param/param_unittest.cpp
test/unittest/param/param_unittest.cpp
+1
-0
ueventd/include/ueventd.h
ueventd/include/ueventd.h
+1
-1
ueventd/ueventd_main.c
ueventd/ueventd_main.c
+1
-0
ueventd/ueventd_read_cfg.c
ueventd/ueventd_read_cfg.c
+31
-0
未找到文件。
services/begetctl/BUILD.gn
浏览文件 @
e63b8cb7
...
...
@@ -25,6 +25,7 @@ common_include_dirs = [
"//base/startup/init/services/init/include",
"//base/startup/init/services/log",
"//base/startup/init/interfaces/innerkits/include",
"//base/startup/init/interfaces/innerkits/include/syspara",
"//base/security/selinux/interfaces/policycoreutils/include",
"//third_party/bounds_checking_function/include",
"//third_party/selinux/libselinux/include",
...
...
services/begetctl/param_cmd.c
浏览文件 @
e63b8cb7
...
...
@@ -422,6 +422,7 @@ static int32_t BShellParamCmdShell(BShellHandle shell, int32_t argc, char *argv[
return
-
1
;
}
}
SetInitLogLevel
(
INIT_INFO
);
pid_t
pid
=
fork
();
if
(
pid
==
0
)
{
setuid
(
uid
);
...
...
services/begetctl/shell/shell_bas.c
浏览文件 @
e63b8cb7
...
...
@@ -645,6 +645,9 @@ static int32_t BShellParamSetValue(BShellParam *param, void *value)
sizeof
(
uint8_t
),
sizeof
(
uint16_t
),
sizeof
(
uint32_t
),
sizeof
(
char
*
)
};
if
(
param
->
type
==
PARAM_STRING
)
{
if
(
param
->
value
.
string
!=
NULL
)
{
free
(
param
->
value
.
string
);
}
param
->
value
.
string
=
strdup
((
char
*
)
value
);
BSH_CHECK
(
param
->
value
.
string
!=
NULL
,
return
BSH_SYSTEM_ERR
,
"Failed to copy value for %s"
,
param
->
name
);
}
else
if
(
param
->
type
<
PARAM_STRING
)
{
...
...
services/include/init_hashmap.h
浏览文件 @
e63b8cb7
...
...
@@ -38,7 +38,7 @@ typedef int (*HashNodeCompare)(const HashNode *node1, const HashNode *node2);
typedef
int
(
*
HashKeyCompare
)(
const
HashNode
*
node1
,
const
void
*
key
);
typedef
int
(
*
HashNodeFunction
)(
const
HashNode
*
node
);
typedef
int
(
*
HashKeyFunction
)(
const
void
*
key
);
typedef
void
(
*
HashNodeOnFree
)(
const
HashNode
*
node
);
typedef
void
(
*
HashNodeOnFree
)(
const
HashNode
*
node
,
void
*
context
);
typedef
struct
{
HashNodeCompare
nodeCompare
;
...
...
@@ -53,7 +53,7 @@ typedef void *HashMapHandle;
int
OH_HashMapIsEmpty
(
HashMapHandle
handle
);
int32_t
OH_HashMapCreate
(
HashMapHandle
*
handle
,
const
HashInfo
*
info
);
void
OH_HashMapDestory
(
HashMapHandle
handle
);
void
OH_HashMapDestory
(
HashMapHandle
handle
,
void
*
context
);
int32_t
OH_HashMapAdd
(
HashMapHandle
handle
,
HashNode
*
hashNode
);
void
OH_HashMapRemove
(
HashMapHandle
handle
,
const
void
*
key
);
HashNode
*
OH_HashMapGet
(
HashMapHandle
handle
,
const
void
*
key
);
...
...
services/init/include/init_group_manager.h
浏览文件 @
e63b8cb7
...
...
@@ -69,6 +69,7 @@ typedef struct {
}
InitWorkspace
;
void
InitServiceSpace
(
void
);
void
CloseServiceSpace
(
void
);
int
InitParseGroupCfg
(
void
);
int
GenerateHashCode
(
const
char
*
key
);
...
...
@@ -83,6 +84,7 @@ InitWorkspace *GetInitWorkspace(void);
#endif
int
GetBootModeFromMisc
(
void
);
void
clearMisc
(
void
);
void
ReleaseCmd
(
PluginCmd
*
cmd
);
#ifdef __cplusplus
#if __cplusplus
}
...
...
services/init/init_common_service.c
浏览文件 @
e63b8cb7
...
...
@@ -212,10 +212,7 @@ static int WritePid(const Service *service)
void
CloseServiceFds
(
Service
*
service
,
bool
needFree
)
{
if
(
service
==
NULL
)
{
return
;
}
INIT_ERROR_CHECK
(
service
!=
NULL
,
return
,
"Service null"
);
INIT_LOGI
(
"Closing service
\'
%s
\'
fds"
,
service
->
name
);
// fdCount > 0, There is no reason fds is NULL
if
(
service
->
fdCount
!=
0
)
{
...
...
@@ -223,8 +220,10 @@ void CloseServiceFds(Service *service, bool needFree)
int
*
fds
=
service
->
fds
;
for
(
size_t
i
=
0
;
i
<
fdCount
;
i
++
)
{
INIT_LOGV
(
"Closing fd: %d"
,
fds
[
i
]);
close
(
fds
[
i
]);
fds
[
i
]
=
-
1
;
if
(
fds
[
i
]
!=
-
1
)
{
close
(
fds
[
i
]);
fds
[
i
]
=
-
1
;
}
}
}
service
->
fdCount
=
0
;
...
...
services/init/init_group_manager.c
浏览文件 @
e63b8cb7
...
...
@@ -152,9 +152,16 @@ static int GroupNodeGetNodeHashCode(const HashNode *node)
return
GenerateHashCode
((
const
char
*
)
groupNode
->
name
);
}
static
void
GroupNodeFree
(
const
HashNode
*
node
)
static
void
GroupNodeFree
(
const
HashNode
*
node
,
void
*
context
)
{
InitGroupNode
*
groupNode
=
HASHMAP_ENTRY
(
node
,
InitGroupNode
,
hashNode
);
if
(
groupNode
->
type
==
NODE_TYPE_SERVICES
)
{
ReleaseService
(
groupNode
->
data
.
service
);
groupNode
->
data
.
service
=
NULL
;
}
else
if
(
groupNode
->
type
==
NODE_TYPE_CMDS
)
{
ReleaseCmd
(
groupNode
->
data
.
cmd
);
groupNode
->
data
.
cmd
=
NULL
;
}
free
(
groupNode
);
}
...
...
@@ -299,7 +306,7 @@ int CheckNodeValid(int type, const char *name)
}
HashNode
*
node
=
OH_HashMapGet
(
g_initWorkspace
.
hashMap
[
type
],
name
);
if
(
node
!=
NULL
)
{
INIT_LOG
I
(
"Found %s in %s group"
,
name
,
type
==
NODE_TYPE_JOBS
?
"job"
:
"service"
);
INIT_LOG
V
(
"Found %s in %s group"
,
name
,
type
==
NODE_TYPE_JOBS
?
"job"
:
"service"
);
return
0
;
}
if
(
g_initWorkspace
.
groupMode
==
GROUP_BOOT
)
{
...
...
@@ -320,6 +327,36 @@ HashMapHandle GetGroupHashMap(int type)
return
g_initWorkspace
.
hashMap
[
type
];
}
void
CloseServiceSpace
(
void
)
{
if
(
g_initWorkspace
.
initFlags
==
0
)
{
return
;
}
for
(
size_t
i
=
0
;
i
<
ARRAY_LENGTH
(
g_initWorkspace
.
hashMap
);
i
++
)
{
if
(
g_initWorkspace
.
hashMap
[
i
]
!=
NULL
)
{
HashMapHandle
handle
=
g_initWorkspace
.
hashMap
[
i
];
g_initWorkspace
.
hashMap
[
i
]
=
NULL
;
OH_HashMapDestory
(
handle
,
NULL
);
}
}
g_initWorkspace
.
initFlags
=
0
;
}
void
ReleaseCmd
(
PluginCmd
*
cmd
)
{
if
(
cmd
==
NULL
)
{
return
;
}
ListNode
*
node
=
cmd
->
cmdExecutor
.
next
;
while
(
node
!=
&
cmd
->
cmdExecutor
)
{
PluginCmdExecutor
*
cmdExec
=
ListEntry
(
node
,
PluginCmdExecutor
,
node
);
OH_ListRemove
(
&
cmdExec
->
node
);
free
(
cmdExec
);
node
=
cmd
->
cmdExecutor
.
next
;
}
free
(
cmd
);
}
#ifdef STARTUP_INIT_TEST
InitWorkspace
*
GetInitWorkspace
(
void
)
{
...
...
services/init/init_service_manager.c
浏览文件 @
e63b8cb7
...
...
@@ -90,6 +90,10 @@ Service *AddService(const char *name)
INIT_LOGE
(
"Failed to create service name %s"
,
name
);
return
NULL
;
}
if
(
node
->
data
.
service
!=
NULL
)
{
ReleaseService
(
node
->
data
.
service
);
node
->
data
.
service
=
NULL
;
}
Service
*
service
=
(
Service
*
)
calloc
(
1
,
sizeof
(
Service
));
INIT_ERROR_CHECK
(
service
!=
NULL
,
return
NULL
,
"Failed to malloc for service"
);
node
->
data
.
service
=
service
;
...
...
@@ -116,11 +120,19 @@ static void FreeServiceFile(ServiceFile *fileOpt)
return
;
}
static
void
ExecuteServiceClear
(
Service
*
service
)
{
#ifndef OHOS_LITE
// clear ext data
SERVICE_INFO_CTX
ctx
=
{
0
};
ctx
.
serviceName
=
service
->
name
;
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_SERVICE_CLEAR
,
(
void
*
)
&
ctx
,
NULL
);
#endif
}
void
ReleaseService
(
Service
*
service
)
{
if
(
service
==
NULL
)
{
return
;
}
INIT_CHECK
(
service
!=
NULL
,
return
);
FreeServiceArg
(
&
service
->
pathArgs
);
FreeServiceArg
(
&
service
->
writePidArgs
);
FreeServiceArg
(
&
service
->
capsArgs
);
...
...
@@ -138,7 +150,9 @@ void ReleaseService(Service *service)
}
service
->
servPerm
.
gIDCnt
=
0
;
FreeServiceSocket
(
service
->
socketCfg
);
service
->
socketCfg
=
NULL
;
FreeServiceFile
(
service
->
fileCfg
);
service
->
fileCfg
=
NULL
;
if
(
service
->
apl
!=
NULL
)
{
free
(
service
->
apl
);
...
...
@@ -154,12 +168,12 @@ void ReleaseService(Service *service)
free
(
service
->
cpuSet
);
service
->
cpuSet
=
NULL
;
}
#ifndef OHOS_LITE
// clear ext data
SERVICE_INFO_CTX
ctx
=
{
0
}
;
ctx
.
serviceName
=
service
->
name
;
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_SERVICE_CLEAR
,
(
void
*
)
&
ctx
,
NULL
);
#endif
if
(
service
->
restartArg
!=
NULL
)
{
free
(
service
->
restartArg
);
service
->
restartArg
=
NULL
;
}
CloseServiceFds
(
service
,
true
);
ExecuteServiceClear
(
service
);
g_serviceSpace
.
serviceCount
--
;
InitGroupNode
*
groupNode
=
GetGroupNode
(
NODE_TYPE_SERVICES
,
service
->
name
);
if
(
groupNode
!=
NULL
)
{
...
...
services/loopevent/loop/le_loop.c
浏览文件 @
e63b8cb7
...
...
@@ -43,10 +43,11 @@ static int TaskGetKeyHasCode(const void *key)
return
taskId
->
taskId
.
fd
;
}
static
void
TaskNodeFree
(
const
HashNode
*
node
)
static
void
TaskNodeFree
(
const
HashNode
*
node
,
void
*
context
)
{
BaseTask
*
task
=
HASHMAP_ENTRY
(
node
,
BaseTask
,
hashNode
);
CloseTask
(
LE_GetDefaultLoop
(),
task
);
CloseTask
((
const
LoopHandle
)
context
,
task
);
free
(
task
);
}
static
LE_STATUS
CreateLoop_
(
EventLoop
**
loop
,
uint32_t
maxevents
,
uint32_t
timeout
)
...
...
@@ -76,7 +77,7 @@ LE_STATUS CloseLoop(EventLoop *loop)
if
(
!
loop
->
stop
)
{
return
LE_SUCCESS
;
}
OH_HashMapDestory
(
loop
->
taskMap
);
OH_HashMapDestory
(
loop
->
taskMap
,
loop
);
if
(
loop
->
close
)
{
loop
->
close
(
loop
);
}
...
...
@@ -100,9 +101,9 @@ LE_STATUS ProcessEvent(const EventLoop *loop, int fd, uint32_t oper)
LE_STATUS
AddTask
(
EventLoop
*
loop
,
BaseTask
*
task
)
{
LoopMutexLock
(
&
loop
->
mutex
);
OH_HashMapAdd
(
loop
->
taskMap
,
&
task
->
hashNode
);
int
ret
=
OH_HashMapAdd
(
loop
->
taskMap
,
&
task
->
hashNode
);
LoopMutexUnlock
(
&
loop
->
mutex
);
return
LE_SUCCESS
;
return
ret
;
}
BaseTask
*
GetTaskByFd
(
EventLoop
*
loop
,
int
fd
)
...
...
services/loopevent/signal/le_signal.c
浏览文件 @
e63b8cb7
...
...
@@ -43,6 +43,7 @@ static void HandleSignalTaskClose_(const LoopHandle loopHandle, const TaskHandle
{
BaseTask
*
task
=
(
BaseTask
*
)
signalHandle
;
CloseTask
(
loopHandle
,
task
);
DelTask
((
EventLoop
*
)
loopHandle
,
task
);
close
(
task
->
taskId
.
fd
);
}
...
...
services/loopevent/task/le_asynctask.c
浏览文件 @
e63b8cb7
...
...
@@ -90,6 +90,7 @@ static void HandleAsyncTaskClose_(const LoopHandle loopHandle, const TaskHandle
{
BaseTask
*
task
=
(
BaseTask
*
)
taskHandle
;
CloseTask
(
loopHandle
,
task
);
DelTask
((
EventLoop
*
)
loopHandle
,
task
);
close
(
task
->
taskId
.
fd
);
}
...
...
services/loopevent/task/le_streamtask.c
浏览文件 @
e63b8cb7
...
...
@@ -69,13 +69,13 @@ static LE_STATUS HandleRecvMsg_(const LoopHandle loopHandle,
}
}
if
(
status
!=
LE_SUCCESS
)
{
FreeBuffer
(
loopHandle
,
(
StreamTask
*
)
taskHandle
,
buffer
);
FreeBuffer
(
loopHandle
,
NULL
,
buffer
);
return
status
;
}
if
(
recvMessage
)
{
recvMessage
(
taskHandle
,
buffer
->
data
,
readLen
);
}
FreeBuffer
(
loopHandle
,
(
StreamTask
*
)
taskHandle
,
buffer
);
FreeBuffer
(
loopHandle
,
NULL
,
buffer
);
return
status
;
}
...
...
@@ -130,6 +130,7 @@ static void HandleStreamTaskClose_(const LoopHandle loopHandle, const TaskHandle
{
BaseTask
*
task
=
(
BaseTask
*
)
taskHandle
;
CloseTask
(
loopHandle
,
task
);
DelTask
((
EventLoop
*
)
loopHandle
,
task
);
if
(
task
->
taskId
.
fd
>
0
)
{
close
(
task
->
taskId
.
fd
);
}
...
...
services/loopevent/task/le_task.c
浏览文件 @
e63b8cb7
...
...
@@ -69,7 +69,6 @@ void CloseTask(const LoopHandle loopHandle, BaseTask *task)
if
(
task
->
close
!=
NULL
)
{
task
->
close
((
TaskHandle
)
task
);
}
DelTask
((
EventLoop
*
)
loopHandle
,
task
);
}
LE_Buffer
*
CreateBuffer
(
uint32_t
bufferSize
)
...
...
services/loopevent/task/le_watchtask.c
浏览文件 @
e63b8cb7
...
...
@@ -46,6 +46,7 @@ static LE_STATUS HandleWatcherEvent_(const LoopHandle loopHandle, const TaskHand
static
void
HandleWatcherTaskClose_
(
const
LoopHandle
loopHandle
,
const
TaskHandle
taskHandle
)
{
CloseTask
(
loopHandle
,
(
BaseTask
*
)
taskHandle
);
DelTask
((
EventLoop
*
)
loopHandle
,
(
BaseTask
*
)
taskHandle
);
}
LE_STATUS
LE_StartWatcher
(
const
LoopHandle
loopHandle
,
...
...
services/loopevent/timer/le_timer.c
浏览文件 @
e63b8cb7
...
...
@@ -67,6 +67,7 @@ static void HandleTimerClose_(const LoopHandle loopHandle, const TaskHandle task
{
BaseTask
*
task
=
(
BaseTask
*
)
taskHandle
;
CloseTask
(
loopHandle
,
task
);
DelTask
((
EventLoop
*
)
loopHandle
,
task
);
close
(
task
->
taskId
.
fd
);
}
...
...
services/modules/reboot/reboot_static.c
浏览文件 @
e63b8cb7
...
...
@@ -167,3 +167,20 @@ MODULE_CONSTRUCTOR(void)
// 执行reboot时调用,安装reboot模块
InitAddRebootHook
(
InitRebootHook_
);
}
MODULE_DESTRUCTOR
(
void
)
{
for
(
int
i
=
0
;
i
<
g_rebootParamCmdValidNumber
;
i
++
)
{
if
(
g_rebootParamCmdInfos
[
i
].
name
!=
NULL
)
{
free
(
g_rebootParamCmdInfos
[
i
].
name
);
}
if
(
g_rebootParamCmdInfos
[
i
].
replace
!=
NULL
)
{
free
(
g_rebootParamCmdInfos
[
i
].
replace
);
}
if
(
g_rebootParamCmdInfos
[
i
].
cmd
!=
NULL
)
{
free
(
g_rebootParamCmdInfos
[
i
].
cmd
);
}
}
free
(
g_rebootParamCmdInfos
);
g_rebootParamCmdInfos
=
NULL
;
}
\ No newline at end of file
services/modules/selinux/selinux_adp.c
浏览文件 @
e63b8cb7
...
...
@@ -106,7 +106,7 @@ static int RestoreContentRecurse(int id, const char *name, int argc, const char
{
PLUGIN_CHECK
(
name
!=
NULL
&&
argc
>=
1
&&
argv
!=
NULL
,
return
-
1
,
"Invalid parameter"
);
PLUGIN_LOGV
(
"RestoreContentRecurse path %s"
,
argv
[
0
]);
if
(
RestoreconRecurse
(
argv
[
0
]))
{
if
(
RestoreconRecurse
(
argv
[
0
])
&&
errno
!=
0
)
{
PLUGIN_LOGE
(
"restoreContentRecurse failed for '%s', err %d."
,
argv
[
0
],
errno
);
}
return
0
;
...
...
services/param/base/param_base.c
浏览文件 @
e63b8cb7
...
...
@@ -194,6 +194,8 @@ INIT_LOCAL_API void CloseParamWorkSpace(void)
}
g_paramWorkSpace
.
workSpace
[
i
]
=
NULL
;
}
free
(
g_paramWorkSpace
.
workSpace
);
g_paramWorkSpace
.
workSpace
=
NULL
;
for
(
int
i
=
0
;
i
<
PARAM_SECURITY_MAX
;
i
++
)
{
if
(
g_paramWorkSpace
.
paramSecurityOps
[
i
].
securityFreeLabel
!=
NULL
)
{
g_paramWorkSpace
.
paramSecurityOps
[
i
].
securityFreeLabel
(
&
g_paramWorkSpace
.
securityLabel
);
...
...
services/param/linux/param_request.c
浏览文件 @
e63b8cb7
...
...
@@ -135,6 +135,9 @@ static int StartRequest(int clientFd, ParamMessage *request, int timeout)
}
PARAM_CHECK
(
sendLen
>=
0
,
return
PARAM_CODE_FAIL_CONNECT
,
"Failed to send message err: %d"
,
errno
);
PARAM_LOGV
(
"sendMessage sendLen fd %d %zd"
,
clientFd
,
sendLen
);
if
(
timeout
<=
0
)
{
return
0
;
}
int
ret
=
ReadMessage
(
clientFd
,
(
char
*
)
request
,
timeout
);
if
(
ret
==
0
)
{
ret
=
ProcessRecvMsg
(
request
);
...
...
@@ -142,7 +145,7 @@ static int StartRequest(int clientFd, ParamMessage *request, int timeout)
return
ret
;
}
int
SystemSetParameter
(
const
char
*
name
,
const
char
*
value
)
static
int
SystemSetParameter_
(
const
char
*
name
,
const
char
*
value
,
int
timeout
)
{
PARAM_CHECK
(
name
!=
NULL
&&
value
!=
NULL
,
return
-
1
,
"Invalid name or value"
);
int
ret
=
CheckParamName
(
name
,
0
);
...
...
@@ -173,7 +176,7 @@ int SystemSetParameter(const char *name, const char *value)
ret
=
DAC_RESULT_FORBIDED
;
break
;
}
ret
=
StartRequest
(
g_clientFd
,
request
,
DEFAULT_PARAM_SET_TIMEOUT
);
ret
=
StartRequest
(
g_clientFd
,
request
,
timeout
);
if
(
ret
==
PARAM_CODE_INVALID_SOCKET
)
{
close
(
g_clientFd
);
g_clientFd
=
INVALID_SOCKET
;
...
...
@@ -189,6 +192,16 @@ int SystemSetParameter(const char *name, const char *value)
return
ret
;
}
int
SystemSetParameter
(
const
char
*
name
,
const
char
*
value
)
{
return
SystemSetParameter_
(
name
,
value
,
DEFAULT_PARAM_SET_TIMEOUT
);
}
int
SystemSetParameterNoWait
(
const
char
*
name
,
const
char
*
value
)
{
return
SystemSetParameter_
(
name
,
value
,
0
);
}
int
SystemWaitParameter
(
const
char
*
name
,
const
char
*
value
,
int32_t
timeout
)
{
PARAM_CHECK
(
name
!=
NULL
,
return
-
1
,
"Invalid name"
);
...
...
services/param/manager/param_manager.c
浏览文件 @
e63b8cb7
...
...
@@ -485,11 +485,12 @@ INIT_LOCAL_API int CheckParamPermission(const ParamSecurityLabel *srcLabel, cons
{
PARAM_CHECK
(
srcLabel
!=
NULL
,
return
DAC_RESULT_FORBIDED
,
"The srcLabel is null"
);
ParamWorkSpace
*
paramSpace
=
GetParamWorkSpace
();
PARAM_CHECK
(
paramSpace
!=
NULL
,
return
DAC_RESULT_FORBIDED
,
"Invalid param workspace"
);
WorkSpace
*
dacSpace
=
GetWorkSpace
(
WORKSPACE_INDEX_DAC
);
PARAM_WORKSPACE_CHECK
(
paramSpace
,
return
DAC_RESULT_FORBIDED
,
"Invalid workspace"
);
PARAM_CHECK
(
paramSpace
->
checkParamPermission
!=
NULL
,
return
DAC_RESULT_FORBIDED
,
"Invalid check permission"
);
ParamLabelIndex
labelIndex
=
{
0
};
// search node from dac space, and get selinux label index
WorkSpace
*
dacSpace
=
GetWorkSpace
(
WORKSPACE_INDEX_DAC
);
(
void
)
FindTrieNode
(
dacSpace
,
name
,
strlen
(
name
),
&
labelIndex
.
dacLabelIndex
);
ParamSecurityNode
*
securityNode
=
(
ParamSecurityNode
*
)
GetTrieNode
(
dacSpace
,
labelIndex
.
dacLabelIndex
);
if
((
securityNode
==
NULL
)
||
(
securityNode
->
selinuxIndex
==
0
)
||
...
...
services/param/trigger/trigger_manager.c
浏览文件 @
e63b8cb7
...
...
@@ -622,7 +622,7 @@ static int JobNodeGetKeyHasCode(const void *key)
return
code
;
}
static
void
JobNodeFree
(
const
HashNode
*
node
)
static
void
JobNodeFree
(
const
HashNode
*
node
,
void
*
context
)
{
JobNode
*
jobNode
=
HASHMAP_ENTRY
(
node
,
JobNode
,
hashNode
);
FreeTrigger
(
GetTriggerWorkSpace
(),
(
TriggerNode
*
)
jobNode
);
...
...
services/param/trigger/trigger_processor.c
浏览文件 @
e63b8cb7
...
...
@@ -319,6 +319,8 @@ void CloseTriggerWorkSpace(void)
for
(
size_t
i
=
0
;
i
<
sizeof
(
g_triggerWorkSpace
.
triggerHead
)
/
sizeof
(
g_triggerWorkSpace
.
triggerHead
[
0
]);
i
++
)
{
ClearTrigger
(
&
g_triggerWorkSpace
,
i
);
}
OH_HashMapDestory
(
g_triggerWorkSpace
.
hashMap
,
NULL
);
g_triggerWorkSpace
.
hashMap
=
NULL
;
free
(
g_triggerWorkSpace
.
executeQueue
.
executeQueue
);
g_triggerWorkSpace
.
executeQueue
.
executeQueue
=
NULL
;
ParamTaskClose
(
g_triggerWorkSpace
.
eventHandle
);
...
...
services/utils/init_hashmap.c
浏览文件 @
e63b8cb7
...
...
@@ -132,7 +132,7 @@ HashNode *OH_HashMapGet(HashMapHandle handle, const void *key)
return
GetHashNodeByKey
(
tab
,
tab
->
buckets
[
hashCode
],
key
,
tab
->
keyCompare
);
}
static
void
HashListFree
(
HashTab
*
tab
,
HashNode
*
root
)
static
void
HashListFree
(
HashTab
*
tab
,
HashNode
*
root
,
void
*
context
)
{
if
(
root
==
NULL
)
{
return
;
...
...
@@ -141,18 +141,18 @@ static void HashListFree(HashTab *tab, HashNode *root)
while
(
node
!=
NULL
)
{
HashNode
*
next
=
node
->
next
;
if
(
tab
->
nodeFree
!=
NULL
)
{
tab
->
nodeFree
(
node
);
tab
->
nodeFree
(
node
,
context
);
}
node
=
next
;
}
}
void
OH_HashMapDestory
(
HashMapHandle
handle
)
void
OH_HashMapDestory
(
HashMapHandle
handle
,
void
*
context
)
{
INIT_ERROR_CHECK
(
handle
!=
NULL
,
return
,
"Invalid hash handle"
);
HashTab
*
tab
=
(
HashTab
*
)
handle
;
for
(
int
i
=
0
;
i
<
tab
->
maxBucket
;
i
++
)
{
HashListFree
(
tab
,
tab
->
buckets
[
i
]);
HashListFree
(
tab
,
tab
->
buckets
[
i
]
,
context
);
}
free
(
tab
);
}
...
...
test/unittest/deviceinfo/DeviceInfoUnittest.cpp
浏览文件 @
e63b8cb7
...
...
@@ -184,8 +184,7 @@ HWTEST_F(DeviceInfoUnittest, TestDeviceInfoProxy1, TestSize.Level1)
proxy
->
GetSerialID
(
serialId
);
char
localDeviceId
[
UDID_LEN
]
=
{
0
};
int
ret
=
AclGetDevUdid
(
localDeviceId
,
UDID_LEN
);
ASSERT_NE
(
ret
,
0
);
(
void
)
AclGetDevUdid
(
localDeviceId
,
UDID_LEN
);
const
char
*
serialNumber
=
AclGetSerial
();
EXPECT_NE
(
nullptr
,
serialNumber
);
}
...
...
test/unittest/init/cmds_unittest.cpp
浏览文件 @
e63b8cb7
...
...
@@ -82,7 +82,7 @@ HWTEST_F(CmdsUnitTest, TestCommonChown, TestSize.Level1)
{
const
char
*
testFile
=
"/data/init_ut/test_dir0"
;
DoCmdByName
(
"chown "
,
"system system /data/init_ut/test_dir0"
);
struct
stat
info
;
struct
stat
info
=
{}
;
stat
(
testFile
,
&
info
);
const
unsigned
int
systemUidGid
=
1000
;
EXPECT_EQ
(
info
.
st_uid
,
systemUidGid
);
...
...
test/unittest/init/group_unittest.cpp
浏览文件 @
e63b8cb7
...
...
@@ -68,7 +68,7 @@ static int TestHashKeyFunction(const void *key)
return
code
;
}
static
void
TestHashNodeFree
(
const
HashNode
*
node
)
static
void
TestHashNodeFree
(
const
HashNode
*
node
,
void
*
context
)
{
TestHashNode
*
testNode
=
HASHMAP_ENTRY
(
node
,
TestHashNode
,
node
);
printf
(
"TestHashNodeFree %s
\n
"
,
testNode
->
name
);
...
...
@@ -108,7 +108,7 @@ HashInfo g_info = {
2
};
HWTEST_F
(
InitGroupManagerUnitTest
,
TestHashMap
,
TestSize
.
Level1
)
HWTEST_F
(
InitGroupManagerUnitTest
,
TestHashMap
001
,
TestSize
.
Level1
)
{
HashMapHandle
handle
;
OH_HashMapCreate
(
&
handle
,
&
g_info
);
...
...
@@ -143,14 +143,24 @@ HWTEST_F(InitGroupManagerUnitTest, TestHashMap, TestSize.Level1)
TestHashNode
*
tmp
=
HASHMAP_ENTRY
(
node
,
TestHashNode
,
node
);
EXPECT_EQ
(
strcmp
(
tmp
->
name
,
str3
),
0
);
}
OH_HashMapIsEmpty
(
handle
);
OH_HashMapTraverse
(
handle
,
[](
const
HashNode
*
node
,
const
void
*
context
)
{
return
;},
nullptr
);
OH_HashMapDestory
(
handle
,
NULL
);
}
HWTEST_F
(
InitGroupManagerUnitTest
,
TestHashMap002
,
TestSize
.
Level1
)
{
HashMapHandle
handle
;
OH_HashMapCreate
(
&
handle
,
&
g_info
);
TestHashNode
*
node4
=
TestCreateHashNode
(
"pre-init"
);
OH_HashMapAdd
(
handle
,
&
node4
->
node
);
OH_HashMapRemove
(
handle
,
"pre-init"
);
TestHashNodeFree
(
&
node4
->
node
,
NULL
);
const
char
*
act
=
"load_persist_props_action"
;
TestHashNode
*
node5
=
TestCreateHashNode
(
act
);
OH_HashMapAdd
(
handle
,
&
node5
->
node
);
OH_HashMapRemove
(
handle
,
"pre-init"
);
node
=
OH_HashMapGet
(
handle
,
(
const
void
*
)
act
);
HashNode
*
node
=
OH_HashMapGet
(
handle
,
(
const
void
*
)
act
);
EXPECT_NE
(
node
!=
nullptr
,
0
);
if
(
node
)
{
TestHashNode
*
tmp
=
HASHMAP_ENTRY
(
node
,
TestHashNode
,
node
);
...
...
@@ -158,7 +168,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestHashMap, TestSize.Level1)
}
OH_HashMapIsEmpty
(
handle
);
OH_HashMapTraverse
(
handle
,
[](
const
HashNode
*
node
,
const
void
*
context
)
{
return
;},
nullptr
);
OH_HashMapDestory
(
handle
);
OH_HashMapDestory
(
handle
,
NULL
);
}
HWTEST_F
(
InitGroupManagerUnitTest
,
TestInitGroupMgrInit
,
TestSize
.
Level1
)
...
...
@@ -366,6 +376,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestProcessWatchEvent, TestSize.Level1)
ASSERT_EQ
(
ret
,
0
);
uint32_t
event
;
((
WatcherTask
*
)
watcher
)
->
processEvent
((
WatcherHandle
)
watcher
,
0
,
&
event
,
service
);
service
->
socketCfg
=
NULL
;
}
HWTEST_F
(
InitGroupManagerUnitTest
,
TestCheckNodeValid
,
TestSize
.
Level1
)
...
...
test/unittest/init/init_unittest.cpp
浏览文件 @
e63b8cb7
...
...
@@ -57,8 +57,6 @@ public:
HWTEST_F
(
InitUnitTest
,
TestSignalHandle
,
TestSize
.
Level1
)
{
SignalInit
();
struct
signalfd_siginfo
siginfo
;
siginfo
.
ssi_signo
=
SIGCHLD
;
ProcessSignal
(
&
siginfo
);
...
...
@@ -106,6 +104,7 @@ static void TestProcessTimer(const TimerHandle taskHandle, void *context)
size_t
fdCount
=
0
;
int
*
fds
=
ServiceGetFd
(
"param_watcher"
,
&
fdCount
);
EXPECT_TRUE
(
fds
!=
nullptr
);
free
(
fds
);
ServiceSaveFd
(
"testservice"
,
fds1
,
ARRAY_LENGTH
(
fds1
));
ServiceSaveFd
(
"deviceinfoservice"
,
fds1
,
ARRAY_LENGTH
(
fds1
));
...
...
@@ -125,7 +124,6 @@ HWTEST_F(InitUnitTest, TestFdHoldService, TestSize.Level1)
EXPECT_EQ
(
ret
,
0
);
ret
=
LE_StartTimer
(
LE_GetDefaultLoop
(),
timer
,
500
,
2
);
EXPECT_EQ
(
ret
,
0
);
SystemRun
();
}
HWTEST_F
(
InitUnitTest
,
TestInitLog
,
TestSize
.
Level1
)
...
...
test/unittest/init/service_unittest.cpp
浏览文件 @
e63b8cb7
...
...
@@ -71,6 +71,7 @@ HWTEST_F(ServiceUnitTest, case01, TestSize.Level1)
EXPECT_EQ
(
ret
,
0
);
ReleaseService
(
service
);
cJSON_Delete
(
jobItem
);
}
HWTEST_F
(
ServiceUnitTest
,
case02
,
TestSize
.
Level1
)
...
...
@@ -113,6 +114,7 @@ HWTEST_F(ServiceUnitTest, case02, TestSize.Level1)
ret
=
ServiceStop
(
service
);
EXPECT_EQ
(
ret
,
0
);
ReleaseService
(
service
);
cJSON_Delete
(
jobItem
);
}
HWTEST_F
(
ServiceUnitTest
,
TestServiceStartAbnormal
,
TestSize
.
Level1
)
...
...
@@ -140,6 +142,7 @@ HWTEST_F(ServiceUnitTest, TestServiceStartAbnormal, TestSize.Level1)
ret
=
ServiceStop
(
service
);
EXPECT_EQ
(
ret
,
0
);
ReleaseService
(
service
);
cJSON_Delete
(
jobItem
);
}
HWTEST_F
(
ServiceUnitTest
,
TestServiceReap
,
TestSize
.
Level1
)
...
...
@@ -202,6 +205,7 @@ HWTEST_F(ServiceUnitTest, TestServiceReapOther, TestSize.Level1)
ret
=
ServiceStop
(
service
);
EXPECT_EQ
(
ret
,
0
);
ReleaseService
(
service
);
cJSON_Delete
(
jobItem
);
}
HWTEST_F
(
ServiceUnitTest
,
TestServiceManagerRelease
,
TestSize
.
Level1
)
...
...
@@ -254,6 +258,7 @@ HWTEST_F(ServiceUnitTest, TestServiceManagerGetService, TestSize.Level1)
ASSERT_NE
(
nullptr
,
service
);
int
ret
=
ParseOneService
(
serviceItem
,
service
);
EXPECT_NE
(
ret
,
0
);
cJSON_Delete
(
jobItem
);
const
char
*
jsonStr1
=
"{
\"
services
\"
:{
\"
name
\"
:
\"
test_service3
\"
,
\"
path
\"
:[
\"
/data/init_ut/test_service
\"
],"
"
\"
importance
\"
:-20,
\"
uid
\"
:
\"
system
\"
,
\"
writepid
\"
:[
\"
/dev/test_service
\"
],
\"
console
\"
:1,"
"
\"
gid
\"
:[
\"
system
\"
],
\"
critical
\"
:[
\"
on
\"
]}}"
;
...
...
@@ -265,6 +270,7 @@ HWTEST_F(ServiceUnitTest, TestServiceManagerGetService, TestSize.Level1)
ASSERT_NE
(
nullptr
,
service
);
ret
=
ParseOneService
(
serviceItem
,
service
);
EXPECT_NE
(
ret
,
0
);
cJSON_Delete
(
jobItem
);
}
/**
...
...
test/unittest/innerkits/innerkits_unittest.cpp
浏览文件 @
e63b8cb7
...
...
@@ -415,12 +415,23 @@ HWTEST_F(InnerkitsUnitTest, TestHoldFd, TestSize.Level1)
fds
=
ServiceGetFd
(
"testServiceName"
,
&
fdCount
);
EXPECT_NE
(
fds
,
nullptr
);
struct
msghdr
msghdr
;
struct
msghdr
msghdr
=
{}
;
BuildControlMessage
(
nullptr
,
nullptr
,
1
,
0
);
BuildControlMessage
(
&
msghdr
,
nullptr
,
1
,
0
);
if
(
msghdr
.
msg_control
!=
NULL
)
{
free
(
msghdr
.
msg_control
);
msghdr
.
msg_control
=
NULL
;
}
BuildControlMessage
(
&
msghdr
,
fds
,
-
1
,
0
);
if
(
msghdr
.
msg_control
!=
NULL
)
{
free
(
msghdr
.
msg_control
);
msghdr
.
msg_control
=
NULL
;
}
BuildControlMessage
(
&
msghdr
,
fds
,
-
1
,
1
);
if
(
msghdr
.
msg_control
!=
NULL
)
{
free
(
msghdr
.
msg_control
);
msghdr
.
msg_control
=
NULL
;
}
if
(
fds
!=
nullptr
)
{
free
(
fds
);
...
...
test/unittest/lite/BUILD.gn
浏览文件 @
e63b8cb7
...
...
@@ -79,6 +79,8 @@ if (defined(ohos_lite)) {
}
include_dirs = [
"//base/startup/init/services/begetctl",
"//base/startup/init/services/begetctl/shell",
"//base/startup/init/services/include",
"//base/startup/init/services/include/param",
"//base/startup/init/services/init/include",
...
...
@@ -103,6 +105,8 @@ if (defined(ohos_lite)) {
"//base/startup/init/interfaces/innerkits/include/syspara",
"//base/startup/init/interfaces/innerkits/init_module_engine/include",
"//base/startup/init/interfaces/innerkits/syspara",
"//base/startup/init/ueventd",
"//base/startup/init/ueventd/include",
"//third_party/cJSON",
"//third_party/bounds_checking_function/include",
"//base/hiviewdfx/hilog_lite/interfaces/native/kits",
...
...
test/unittest/loopevent/loopevent_unittest.cpp
浏览文件 @
e63b8cb7
...
...
@@ -45,9 +45,6 @@ using HashTab = struct {
HashNode
*
buckets
[
0
];
};
extern
"C"
{
void
OnClose
(
ParamTaskPtr
client
);
}
static
LE_STATUS
TestHandleTaskEvent
(
const
LoopHandle
loop
,
const
TaskHandle
task
,
uint32_t
oper
)
{
return
LE_SUCCESS
;
...
...
@@ -140,7 +137,7 @@ public:
LE_StreamServerInfo
info
=
{};
info
.
baseInfo
.
flags
=
TASK_STREAM
|
TASK_PIPE
|
TASK_SERVER
|
TASK_TEST
;
info
.
server
=
(
char
*
)
"/data/testpipe"
;
info
.
baseInfo
.
close
=
OnClose
;
info
.
baseInfo
.
close
=
NULL
;
info
.
incommingConnect
=
IncomingConnect
;
LE_CreateStreamServer
(
LE_GetDefaultLoop
(),
&
serverTask_
,
&
info
);
if
(
serverTask_
==
nullptr
)
{
...
...
@@ -152,7 +149,7 @@ public:
ParamStreamInfo
paramStreamInfo
=
{};
paramStreamInfo
.
flags
=
PARAM_TEST_FLAGS
;
paramStreamInfo
.
server
=
NULL
;
paramStreamInfo
.
close
=
OnClose
;
paramStreamInfo
.
close
=
NULL
;
paramStreamInfo
.
recvMessage
=
ProcessMessage
;
paramStreamInfo
.
incomingConnect
=
NULL
;
ParamTaskPtr
client
=
NULL
;
...
...
@@ -174,7 +171,6 @@ public:
ParamWatcher
*
watcher
=
(
ParamWatcher
*
)
ParamGetTaskUserData
(
client
);
PARAM_CHECK
(
watcher
!=
nullptr
,
return
,
"Failed to get watcher"
);
OH_ListInit
(
&
watcher
->
triggerHead
);
OnClose
(
client
);
LE_FreeBuffer
(
LE_GetDefaultLoop
(),
(
TaskHandle
)
client
,
nullptr
);
return
;
}
...
...
@@ -188,7 +184,6 @@ public:
task
->
handleEvent
=
TestHandleTaskEvent
;
ProcessEvent
((
EventLoop
*
)
LE_GetDefaultLoop
(),
testfd
,
Event_Read
);
}
((
HashTab
*
)(((
EventLoop
*
)
LE_GetDefaultLoop
())
->
taskMap
))
->
nodeFree
(
&
task
->
hashNode
);
}
void
ProcessasynEvent
()
{
...
...
@@ -217,6 +212,7 @@ public:
((
WatcherTask
*
)
handle
)
->
base
.
handleEvent
(
LE_GetDefaultLoop
(),
(
TaskHandle
)
handle
,
0
);
((
WatcherTask
*
)
handle
)
->
base
.
flags
=
WATCHER_ONCE
;
((
WatcherTask
*
)
handle
)
->
base
.
handleEvent
(
LE_GetDefaultLoop
(),
(
TaskHandle
)
handle
,
Event_Read
);
LE_RemoveWatcher
(
LE_GetDefaultLoop
(),
handle
);
}
void
CreateSocketTest
()
{
...
...
@@ -224,7 +220,7 @@ public:
LE_StreamServerInfo
info
=
{};
info
.
baseInfo
.
flags
=
TASK_PIPE
|
TASK_CONNECT
|
TASK_TEST
;
info
.
server
=
(
char
*
)
"/data/testpipe"
;
info
.
baseInfo
.
close
=
OnClose
;
info
.
baseInfo
.
close
=
NULL
;
info
.
incommingConnect
=
IncomingConnect
;
info
.
socketId
=
1111
;
// 1111 is test fd
LE_CreateStreamServer
(
LE_GetDefaultLoop
(),
&
serverTask
,
&
info
);
...
...
test/unittest/loopevent/loopserver_unittest.cpp
浏览文件 @
e63b8cb7
...
...
@@ -268,7 +268,7 @@ public:
void
StartServer
()
{
s
erverThread_
=
new
(
std
::
nothrow
)
std
::
thread
(
&
LoopServerUnitTest
::
RunServer
,
this
);
s
td
::
thread
(
&
LoopServerUnitTest
::
RunServer
,
this
).
detach
(
);
sleep
(
1
);
}
...
...
test/unittest/loopevent/loopsignal_unittest.cpp
浏览文件 @
e63b8cb7
...
...
@@ -59,6 +59,7 @@ HWTEST_F(LoopSignalUnitTest, SignalInitTestRmSig, TestSize.Level1)
((
BaseTask
*
)
g_sigHandler
)
->
handleEvent
(
loopClient
,
(
TaskHandle
)
&
g_sigHandler
,
Event_Write
);
LE_CloseSignalTask
(
loopClient
,
g_sigHandler
);
ASSERT_EQ
(
ret
,
0
);
LE_StopLoop
(
loopClient
);
LE_CloseLoop
(
loopClient
);
loopClient
=
nullptr
;
}
...
...
test/unittest/param/param_stub.cpp
浏览文件 @
e63b8cb7
...
...
@@ -18,6 +18,7 @@
#include <sys/prctl.h>
#include <unistd.h>
#include "begetctl.h"
#include "bootstage.h"
#include "init.h"
#include "init_log.h"
...
...
@@ -35,6 +36,7 @@
#ifdef PARAM_LOAD_CFG_FROM_CODE
#include "param_cfg.h"
#endif
#include "ueventd.h"
#ifdef __cplusplus
#if __cplusplus
...
...
@@ -492,13 +494,11 @@ void PrepareInitUnitTestEnv(void)
return
;
}
printf
(
"PrepareInitUnitTestEnv
\n
"
);
SignalInit
();
#ifdef PARAM_SUPPORT_SELINUX
RegisterSecuritySelinuxOps
(
nullptr
,
0
);
#endif
int32_t
loglevel
=
GetIntParameter
(
"persist.init.debug.loglevel"
,
INIT_ERROR
);
SetInitLogLevel
((
InitLogLevel
)
loglevel
);
#ifndef OHOS_LITE
InitAddGlobalInitHook
(
0
,
TestHook
);
InitAddPreParamServiceHook
(
0
,
TestHook
);
...
...
@@ -520,6 +520,9 @@ void PrepareInitUnitTestEnv(void)
LoadParamsFile
(
STARTUP_INIT_UT_PATH
"/system/etc/param"
,
LOAD_PARAM_ONLY_ADD
);
LoadParamFromCfg
();
int32_t
loglevel
=
GetIntParameter
(
"persist.init.debug.loglevel"
,
INIT_ERROR
);
SetInitLogLevel
((
InitLogLevel
)
loglevel
);
// for test int get
SystemWriteParam
(
"test.int.get"
,
"-101"
);
SystemWriteParam
(
"test.uint.get"
,
"101"
);
...
...
@@ -568,6 +571,7 @@ static __attribute__((constructor(101))) void ParamTestStubInit(void)
{
printf
(
"Init unit test start
\n
"
);
EnableInitLog
(
INIT_ERROR
);
// prepare data
mkdir
(
STARTUP_INIT_UT_PATH
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
PrepareUeventdcfg
();
...
...
@@ -593,9 +597,17 @@ __attribute__((destructor)) static void ParamTestStubExit(void)
{
PARAM_LOGI
(
"ParamTestStubExit"
);
#ifndef OHOS_LITE
StopParamService
();
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_BOOT_COMPLETE
,
NULL
,
NULL
);
CloseUeventConfig
();
const
char
*
clearBootEventArgv
[]
=
{
"bootevent"
};
PluginExecCmd
(
"clear"
,
ARRAY_LENGTH
(
clearBootEventArgv
),
clearBootEventArgv
);
CloseServiceSpace
();
demoExit
();
LE_CloseLoop
(
LE_GetDefaultLoop
());
HookMgrDestroy
(
GetBootStageHookMgr
());
#endif
StopParamService
();
}
#ifdef OHOS_LITE
...
...
test/unittest/param/param_unittest.cpp
浏览文件 @
e63b8cb7
...
...
@@ -434,6 +434,7 @@ HWTEST_F(ParamUnitTest, TestWorkSpace2, TestSize.Level0)
int
ret
=
ParamStrCpy
(
workSpace
->
fileName
,
size
,
spaceName
);
EXPECT_EQ
(
ret
,
0
);
CloseWorkSpace
(
workSpace
);
free
(
workSpace
);
}
#if !(defined __LITEOS_A__ || defined __LITEOS_M__) // can not support parameter type
...
...
ueventd/include/ueventd.h
浏览文件 @
e63b8cb7
...
...
@@ -76,7 +76,7 @@ void ParseUeventMessage(const char *buffer, ssize_t length, struct Uevent *ueven
void
RetriggerUevent
(
int
sockFd
,
char
**
devices
,
int
num
);
void
RetriggerUeventByPath
(
int
sockFd
,
char
*
path
);
void
ProcessUevent
(
int
sockFd
,
char
**
devices
,
int
num
);
void
CloseUeventConfig
(
void
);
#ifdef __cplusplus
#if __cplusplus
}
...
...
ueventd/ueventd_main.c
浏览文件 @
e63b8cb7
...
...
@@ -81,5 +81,6 @@ int main(int argc, char **argv)
ProcessUevent
(
ueventSockFd
,
NULL
,
0
);
// Not require boot devices
}
PollUeventdSocketTimeout
(
ueventSockFd
,
ondemand
);
CloseUeventConfig
();
return
0
;
}
ueventd/ueventd_read_cfg.c
浏览文件 @
e63b8cb7
...
...
@@ -412,3 +412,34 @@ void ChangeSysAttributePermissions(const char *sysPath)
INIT_LOGE
(
"[uevent][error] chmod for file %s failed, err = %d"
,
sysAttr
,
errno
);
}
}
static
void
FreeDeviceConfig
(
ListNode
*
node
)
{
struct
DeviceUdevConf
*
config
=
ListEntry
(
node
,
struct
DeviceUdevConf
,
list
);
free
((
void
*
)
config
->
name
);
free
((
void
*
)
config
->
parameter
);
OH_ListRemove
(
&
config
->
paramNode
);
free
(
config
);
}
static
void
FreeSysUdevConf
(
ListNode
*
node
)
{
struct
SysUdevConf
*
config
=
ListEntry
(
node
,
struct
SysUdevConf
,
list
);
free
((
void
*
)
config
->
sysPath
);
free
((
void
*
)
config
->
attr
);
free
(
config
);
}
static
void
FreeFirmwareUdevConf
(
ListNode
*
node
)
{
struct
FirmwareUdevConf
*
config
=
ListEntry
(
node
,
struct
FirmwareUdevConf
,
list
);
free
((
void
*
)
config
->
fmPath
);
free
(
config
);
}
void
CloseUeventConfig
(
void
)
{
OH_ListRemoveAll
(
&
g_devices
,
FreeDeviceConfig
);
OH_ListRemoveAll
(
&
g_sysDevices
,
FreeSysUdevConf
);
OH_ListRemoveAll
(
&
g_firmwares
,
FreeFirmwareUdevConf
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录