Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
235e009d
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看板
提交
235e009d
编写于
11月 30, 2021
作者:
O
openharmony_ci
提交者:
Gitee
11月 30, 2021
浏览文件
操作
浏览文件
下载
差异文件
!171 fix: coeddex
Merge pull request !171 from 熊磊/startup_init_lite1127
上级
d69b944c
87b3a515
变更
31
隐藏空白更改
内联
并排
Showing
31 changed file
with
149 addition
and
70 deletion
+149
-70
interfaces/innerkits/fs_manager/fs_manager_log.c
interfaces/innerkits/fs_manager/fs_manager_log.c
+7
-2
interfaces/innerkits/fs_manager/fstab.c
interfaces/innerkits/fs_manager/fstab.c
+5
-4
services/cmds/misc/misc_daemon.cpp
services/cmds/misc/misc_daemon.cpp
+9
-2
services/init/init_common_cmds.c
services/init/init_common_cmds.c
+5
-6
services/init/init_config.c
services/init/init_config.c
+1
-1
services/init/init_service_manager.c
services/init/init_service_manager.c
+6
-1
services/init/standard/init_cmds.c
services/init/standard/init_cmds.c
+4
-4
services/init/standard/init_mount.c
services/init/standard/init_mount.c
+1
-1
services/init/standard/init_mount.h
services/init/standard/init_mount.h
+1
-1
services/init/standard/init_reboot.c
services/init/standard/init_reboot.c
+6
-7
services/init/standard/switch_root.c
services/init/standard/switch_root.c
+15
-3
services/param/adapter/param_persistadp.c
services/param/adapter/param_persistadp.c
+3
-3
services/param/adapter/param_selinux.c
services/param/adapter/param_selinux.c
+2
-2
services/param/client/param_request.c
services/param/client/param_request.c
+1
-1
services/param/cmd/param_cmd.c
services/param/cmd/param_cmd.c
+1
-1
services/param/manager/param_manager.c
services/param/manager/param_manager.c
+1
-0
services/param/service/param_service.c
services/param/service/param_service.c
+5
-4
services/param/trigger/trigger_manager.c
services/param/trigger/trigger_manager.c
+14
-6
services/param/trigger/trigger_processor.c
services/param/trigger/trigger_processor.c
+1
-1
services/param/watcher/proxy/watcher_manager.h
services/param/watcher/proxy/watcher_manager.h
+4
-4
test/unittest/init/cmds_unittest.cpp
test/unittest/init/cmds_unittest.cpp
+5
-6
test/unittest/init/mount_unittest.cpp
test/unittest/init/mount_unittest.cpp
+1
-0
test/unittest/init/service_file_unittest.cpp
test/unittest/init/service_file_unittest.cpp
+3
-0
test/unittest/init/service_socket_unittest.cpp
test/unittest/init/service_socket_unittest.cpp
+2
-1
test/unittest/init/service_unittest.cpp
test/unittest/init/service_unittest.cpp
+6
-0
test/unittest/param/client_unittest.cpp
test/unittest/param/client_unittest.cpp
+6
-0
test/unittest/param/dac_unittest.cpp
test/unittest/param/dac_unittest.cpp
+5
-2
test/unittest/param/param_unittest.cpp
test/unittest/param/param_unittest.cpp
+4
-1
test/unittest/param/selinux_unittest.cpp
test/unittest/param/selinux_unittest.cpp
+7
-4
test/unittest/param/trigger_unittest.cpp
test/unittest/param/trigger_unittest.cpp
+17
-1
ueventd/ueventd_socket.c
ueventd/ueventd_socket.c
+1
-1
未找到文件。
interfaces/innerkits/fs_manager/fs_manager_log.c
浏览文件 @
235e009d
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
#include "fs_manager/fs_manager_log.h"
#include "fs_manager/fs_manager_log.h"
#include "init_log.h"
#include "init_log.h"
#include "init_utils.h"
#include "securec.h"
#include "securec.h"
#define LOG_BUFFER_MAX (1024)
#define LOG_BUFFER_MAX (1024)
...
@@ -152,8 +153,12 @@ void FsManagerLogInit(LogTarget target, const char *fileName)
...
@@ -152,8 +153,12 @@ void FsManagerLogInit(LogTarget target, const char *fileName)
break
;
break
;
case
LOG_TO_FILE
:
case
LOG_TO_FILE
:
if
(
fileName
!=
NULL
&&
*
fileName
!=
'\0'
)
{
if
(
fileName
!=
NULL
&&
*
fileName
!=
'\0'
)
{
g_logFile
=
fopen
(
fileName
,
"a+"
);
char
*
realPath
=
GetRealPath
(
fileName
);
setbuf
(
g_logFile
,
NULL
);
if
(
realPath
!=
NULL
)
{
g_logFile
=
fopen
(
realPath
,
"a+"
);
setbuf
(
g_logFile
,
NULL
);
free
(
realPath
);
}
// Do not check return values. The log writte function will do this.
// Do not check return values. The log writte function will do this.
}
}
g_logFunc
=
FsManagerLogToFile
;
g_logFunc
=
FsManagerLogToFile
;
...
...
interfaces/innerkits/fs_manager/fstab.c
浏览文件 @
235e009d
...
@@ -191,12 +191,13 @@ Fstab *ReadFstabFromFile(const char *file, bool procMounts)
...
@@ -191,12 +191,13 @@ Fstab *ReadFstabFromFile(const char *file, bool procMounts)
ssize_t
readn
=
0
;
ssize_t
readn
=
0
;
Fstab
*
fstab
=
NULL
;
Fstab
*
fstab
=
NULL
;
if
(
file
==
NULL
)
{
char
*
realPath
=
GetRealPath
(
file
);
if
(
realPath
==
NULL
)
{
FSMGR_LOGE
(
"Invalid file"
);
FSMGR_LOGE
(
"Invalid file"
);
return
NULL
;
return
NULL
;
}
}
FILE
*
fp
=
fopen
(
realPath
,
"r"
);
FILE
*
fp
=
fopen
(
file
,
"r"
);
free
(
realPath
);
if
(
fp
==
NULL
)
{
if
(
fp
==
NULL
)
{
FSMGR_LOGE
(
"Open %s failed, err = %d"
,
file
,
errno
);
FSMGR_LOGE
(
"Open %s failed, err = %d"
,
file
,
errno
);
return
NULL
;
return
NULL
;
...
@@ -250,7 +251,7 @@ FstabItem *FindFstabItemForMountPoint(Fstab fstab, const char *mp)
...
@@ -250,7 +251,7 @@ FstabItem *FindFstabItemForMountPoint(Fstab fstab, const char *mp)
FstabItem
*
item
=
NULL
;
FstabItem
*
item
=
NULL
;
if
(
mp
!=
NULL
)
{
if
(
mp
!=
NULL
)
{
for
(
item
=
fstab
.
head
;
item
!=
NULL
;
item
=
item
->
next
)
{
for
(
item
=
fstab
.
head
;
item
!=
NULL
;
item
=
item
->
next
)
{
if
(
strcmp
(
item
->
mountPoint
,
mp
)
==
0
)
{
if
(
(
item
->
mountPoint
!=
NULL
)
&&
(
strcmp
(
item
->
mountPoint
,
mp
)
==
0
)
)
{
break
;
break
;
}
}
}
}
...
...
services/cmds/misc/misc_daemon.cpp
浏览文件 @
235e009d
...
@@ -55,6 +55,7 @@ static std::string GetMiscDevicePath()
...
@@ -55,6 +55,7 @@ static std::string GetMiscDevicePath()
FstabItem
*
misc
=
FindFstabItemForMountPoint
(
*
fstab
,
"/misc"
);
FstabItem
*
misc
=
FindFstabItemForMountPoint
(
*
fstab
,
"/misc"
);
if
(
misc
==
nullptr
)
{
if
(
misc
==
nullptr
)
{
std
::
cout
<<
"Cannot find misc partition from fstab
\n
"
;
std
::
cout
<<
"Cannot find misc partition from fstab
\n
"
;
ReleaseFstab
(
fstab
);
return
miscDev
;
return
miscDev
;
}
}
miscDev
=
misc
->
deviceName
;
miscDev
=
misc
->
deviceName
;
...
@@ -86,22 +87,27 @@ static void WriteLogoContent(int fd, const std::string &logoPath, uint32_t size)
...
@@ -86,22 +87,27 @@ static void WriteLogoContent(int fd, const std::string &logoPath, uint32_t size)
std
::
cout
<<
"path is null or size illegal
\n
"
;
std
::
cout
<<
"path is null or size illegal
\n
"
;
return
;
return
;
}
}
FILE
*
rgbFile
=
fopen
(
logoPath
.
c_str
(),
"rb"
);
FILE
*
rgbFile
=
fopen
(
logoPath
.
c_str
(),
"rb"
);
if
(
rgbFile
==
nullptr
)
{
if
(
rgbFile
==
nullptr
)
{
std
::
cout
<<
"cannot find pic file
\n
"
;
std
::
cout
<<
"cannot find pic file
\n
"
;
return
;
return
;
}
}
char
*
buffer
=
(
char
*
)
malloc
(
size
);
char
*
buffer
=
(
char
*
)
malloc
(
size
);
if
(
buffer
==
nullptr
)
{
if
(
buffer
==
nullptr
)
{
(
void
)
fclose
(
rgbFile
);
return
;
return
;
}
}
uint32_t
ret
=
fread
(
buffer
,
1
,
size
,
rgbFile
);
uint32_t
ret
=
fread
(
buffer
,
1
,
size
,
rgbFile
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
(
void
)
fclose
(
rgbFile
);
free
(
buffer
);
return
;
return
;
}
}
ret
=
write
(
fd
,
buffer
,
size
);
ret
=
write
(
fd
,
buffer
,
size
);
if
(
ret
!=
size
)
{
if
(
ret
!=
size
)
{
(
void
)
fclose
(
rgbFile
);
free
(
buffer
);
return
;
return
;
}
}
...
@@ -194,6 +200,7 @@ static void WriteLogoToMisc(const std::string &logoPath)
...
@@ -194,6 +200,7 @@ static void WriteLogoToMisc(const std::string &logoPath)
int
fd1
=
open
(
miscDev
.
c_str
(),
O_RDWR
|
O_CLOEXEC
,
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IROTH
);
int
fd1
=
open
(
miscDev
.
c_str
(),
O_RDWR
|
O_CLOEXEC
,
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IROTH
);
if
(
lseek
(
fd1
,
addrOffset
*
BLOCK_SZIE_1
,
SEEK_SET
)
<
0
)
{
if
(
lseek
(
fd1
,
addrOffset
*
BLOCK_SZIE_1
,
SEEK_SET
)
<
0
)
{
std
::
cout
<<
"Failed to seek file
\n
"
;
std
::
cout
<<
"Failed to seek file
\n
"
;
close
(
fd1
);
return
;
return
;
}
}
...
...
services/init/init_common_cmds.c
浏览文件 @
235e009d
...
@@ -56,6 +56,7 @@ static char *AddOneArg(const char *param, size_t paramLen)
...
@@ -56,6 +56,7 @@ static char *AddOneArg(const char *param, size_t paramLen)
char
*
BuildStringFromCmdArg
(
const
struct
CmdArgs
*
ctx
,
int
startIndex
)
char
*
BuildStringFromCmdArg
(
const
struct
CmdArgs
*
ctx
,
int
startIndex
)
{
{
INIT_ERROR_CHECK
(
ctx
!=
NULL
,
return
NULL
,
"Failed to get cmd args "
);
char
*
options
=
(
char
*
)
calloc
(
1
,
OPTIONS_SIZE
+
1
);
char
*
options
=
(
char
*
)
calloc
(
1
,
OPTIONS_SIZE
+
1
);
INIT_ERROR_CHECK
(
options
!=
NULL
,
return
NULL
,
"Failed to get memory "
);
INIT_ERROR_CHECK
(
options
!=
NULL
,
return
NULL
,
"Failed to get memory "
);
options
[
0
]
=
'\0'
;
options
[
0
]
=
'\0'
;
...
@@ -336,7 +337,7 @@ static int GetMountFlag(unsigned long *mountflag, const char *targetStr, const c
...
@@ -336,7 +337,7 @@ static int GetMountFlag(unsigned long *mountflag, const char *targetStr, const c
INIT_CHECK_RETURN_VALUE
(
targetStr
!=
NULL
&&
mountflag
!=
NULL
,
0
);
INIT_CHECK_RETURN_VALUE
(
targetStr
!=
NULL
&&
mountflag
!=
NULL
,
0
);
struct
{
struct
{
char
*
flagName
;
char
*
flagName
;
int
value
;
unsigned
long
value
;
}
mountFlagMap
[]
=
{
}
mountFlagMap
[]
=
{
{
"noatime"
,
MS_NOATIME
},
{
"noatime"
,
MS_NOATIME
},
{
"noexec"
,
MS_NOEXEC
},
{
"noexec"
,
MS_NOEXEC
},
...
@@ -416,18 +417,16 @@ static void DoWrite(const struct CmdArgs *ctx)
...
@@ -416,18 +417,16 @@ static void DoWrite(const struct CmdArgs *ctx)
int
fd
=
-
1
;
int
fd
=
-
1
;
if
(
realPath
!=
NULL
)
{
if
(
realPath
!=
NULL
)
{
fd
=
open
(
realPath
,
O_WRONLY
|
O_CREAT
|
O_NOFOLLOW
|
O_CLOEXEC
,
S_IRUSR
|
S_IWUSR
);
fd
=
open
(
realPath
,
O_WRONLY
|
O_CREAT
|
O_NOFOLLOW
|
O_CLOEXEC
,
S_IRUSR
|
S_IWUSR
);
free
(
realPath
);
realPath
=
NULL
;
}
else
{
}
else
{
fd
=
open
(
ctx
->
argv
[
0
],
O_WRONLY
|
O_CREAT
|
O_NOFOLLOW
|
O_CLOEXEC
,
S_IRUSR
|
S_IWUSR
);
fd
=
open
(
ctx
->
argv
[
0
],
O_WRONLY
|
O_CREAT
|
O_NOFOLLOW
|
O_CLOEXEC
,
S_IRUSR
|
S_IWUSR
);
}
}
if
(
fd
>=
0
)
{
if
(
fd
>=
0
)
{
size_t
ret
=
write
(
fd
,
ctx
->
argv
[
1
],
strlen
(
ctx
->
argv
[
1
]));
size_t
ret
=
write
(
fd
,
ctx
->
argv
[
1
],
strlen
(
ctx
->
argv
[
1
]));
INIT_CHECK_ONLY_ELOG
(
ret
>=
0
,
"DoWrite: write to file %s failed: %d"
,
ctx
->
argv
[
0
],
errno
);
INIT_CHECK_ONLY_ELOG
(
ret
>=
0
,
"DoWrite: write to file %s failed: %d"
,
ctx
->
argv
[
0
],
errno
);
close
(
fd
);
}
}
if
(
realPath
!=
NULL
)
{
free
(
realPath
);
}
realPath
=
NULL
;
close
(
fd
);
}
}
static
void
DoRmdir
(
const
struct
CmdArgs
*
ctx
)
static
void
DoRmdir
(
const
struct
CmdArgs
*
ctx
)
...
...
services/init/init_config.c
浏览文件 @
235e009d
...
@@ -50,7 +50,7 @@ static int ParseInitCfg(const char *configFile, void *context)
...
@@ -50,7 +50,7 @@ static int ParseInitCfg(const char *configFile, void *context)
static
void
ParseAllImports
(
const
cJSON
*
root
)
static
void
ParseAllImports
(
const
cJSON
*
root
)
{
{
char
*
tmpParamValue
=
malloc
(
PARAM_VALUE_LEN_MAX
+
1
);
char
*
tmpParamValue
=
calloc
(
sizeof
(
char
),
PARAM_VALUE_LEN_MAX
+
1
);
INIT_ERROR_CHECK
(
tmpParamValue
!=
0
,
return
,
"Failed to alloc memory for param"
);
INIT_ERROR_CHECK
(
tmpParamValue
!=
0
,
return
,
"Failed to alloc memory for param"
);
cJSON
*
importAttr
=
cJSON_GetObjectItemCaseSensitive
(
root
,
"import"
);
cJSON
*
importAttr
=
cJSON_GetObjectItemCaseSensitive
(
root
,
"import"
);
...
...
services/init/init_service_manager.c
浏览文件 @
235e009d
...
@@ -326,6 +326,7 @@ static int AddServiceSocket(cJSON *json, Service *service)
...
@@ -326,6 +326,7 @@ static int AddServiceSocket(cJSON *json, Service *service)
sockopt
->
gid
=
DecodeUid
(
opt
[
SERVICE_SOCK_GID
]);
sockopt
->
gid
=
DecodeUid
(
opt
[
SERVICE_SOCK_GID
]);
if
(
sockopt
->
uid
==
(
uid_t
)
-
1
||
sockopt
->
gid
==
(
uid_t
)
-
1
)
{
if
(
sockopt
->
uid
==
(
uid_t
)
-
1
||
sockopt
->
gid
==
(
uid_t
)
-
1
)
{
free
(
sockopt
);
free
(
sockopt
);
sockopt
=
NULL
;
INIT_LOGE
(
"Invalid uid %d or gid %d"
,
sockopt
->
uid
,
sockopt
->
gid
);
INIT_LOGE
(
"Invalid uid %d or gid %d"
,
sockopt
->
uid
,
sockopt
->
gid
);
return
SERVICE_FAILURE
;
return
SERVICE_FAILURE
;
}
}
...
@@ -399,6 +400,7 @@ static int AddServiceFile(cJSON *json, Service *service)
...
@@ -399,6 +400,7 @@ static int AddServiceFile(cJSON *json, Service *service)
fileOpt
->
gid
=
DecodeUid
(
opt
[
SERVICE_FILE_GID
]);
fileOpt
->
gid
=
DecodeUid
(
opt
[
SERVICE_FILE_GID
]);
if
(
fileOpt
->
uid
==
(
uid_t
)
-
1
||
fileOpt
->
gid
==
(
gid_t
)
-
1
)
{
if
(
fileOpt
->
uid
==
(
uid_t
)
-
1
||
fileOpt
->
gid
==
(
gid_t
)
-
1
)
{
free
(
fileOpt
);
free
(
fileOpt
);
fileOpt
=
NULL
;
INIT_LOGE
(
"Invalid uid %d or gid %d"
,
fileOpt
->
uid
,
fileOpt
->
gid
);
INIT_LOGE
(
"Invalid uid %d or gid %d"
,
fileOpt
->
uid
,
fileOpt
->
gid
);
return
SERVICE_FAILURE
;
return
SERVICE_FAILURE
;
}
}
...
@@ -641,10 +643,13 @@ Service *GetServiceByPid(pid_t pid)
...
@@ -641,10 +643,13 @@ Service *GetServiceByPid(pid_t pid)
Service
*
GetServiceByName
(
const
char
*
servName
)
Service
*
GetServiceByName
(
const
char
*
servName
)
{
{
INIT_ERROR_CHECK
(
servName
!=
NULL
,
return
NULL
,
"Failed get servName"
);
ListNode
*
node
=
g_serviceSpace
.
services
.
next
;
ListNode
*
node
=
g_serviceSpace
.
services
.
next
;
while
(
node
!=
&
g_serviceSpace
.
services
)
{
while
(
node
!=
&
g_serviceSpace
.
services
)
{
Service
*
service
=
ListEntry
(
node
,
Service
,
node
);
Service
*
service
=
ListEntry
(
node
,
Service
,
node
);
INIT_CHECK_RETURN_VALUE
(
strcmp
(
service
->
name
,
servName
)
!=
0
,
service
);
if
(
service
!=
NULL
)
{
INIT_CHECK_RETURN_VALUE
(
strcmp
(
service
->
name
,
servName
)
!=
0
,
service
);
}
node
=
node
->
next
;
node
=
node
->
next
;
}
}
return
NULL
;
return
NULL
;
...
...
services/init/standard/init_cmds.c
浏览文件 @
235e009d
...
@@ -114,16 +114,16 @@ static void DoInsmod(const struct CmdArgs *ctx)
...
@@ -114,16 +114,16 @@ static void DoInsmod(const struct CmdArgs *ctx)
INIT_LOGD
(
"Install mode %s "
,
fileName
);
INIT_LOGD
(
"Install mode %s "
,
fileName
);
char
*
realPath
=
GetRealPath
(
fileName
);
char
*
realPath
=
GetRealPath
(
fileName
);
INIT_ERROR_CHECK
(
realPath
!=
NULL
,
return
,
"Can not get real file name from param %s"
,
ctx
->
argv
[
0
]);
INIT_ERROR_CHECK
(
realPath
!=
NULL
,
return
,
"Can not get real file name from param %s"
,
ctx
->
argv
[
0
]);
INIT_CHECK
((
ctx
->
argc
>
1
&&
ctx
->
argv
[
1
]
!=
NULL
&&
strcmp
(
ctx
->
argv
[
1
],
"-f"
))
!=
0
,
// [-f]
if
(
ctx
->
argc
>
1
&&
ctx
->
argv
[
1
]
!=
NULL
&&
strcmp
(
ctx
->
argv
[
1
],
"-f"
)
==
0
)
{
// [-f]
flags
=
MODULE_INIT_IGNORE_VERMAGIC
|
MODULE_INIT_IGNORE_MODVERSIONS
;
flags
=
MODULE_INIT_IGNORE_VERMAGIC
|
MODULE_INIT_IGNORE_MODVERSIONS
;
index
++
)
;
index
++
;
}
char
*
options
=
BuildStringFromCmdArg
(
ctx
,
index
);
// [options]
char
*
options
=
BuildStringFromCmdArg
(
ctx
,
index
);
// [options]
int
fd
=
open
(
realPath
,
O_RDONLY
|
O_NOFOLLOW
|
O_CLOEXEC
);
int
fd
=
open
(
realPath
,
O_RDONLY
|
O_NOFOLLOW
|
O_CLOEXEC
);
if
(
fd
>=
0
)
{
if
(
fd
>=
0
)
{
int
rc
=
syscall
(
__NR_finit_module
,
fd
,
options
,
flags
);
int
rc
=
syscall
(
__NR_finit_module
,
fd
,
options
,
flags
);
if
(
rc
==
-
1
)
{
if
(
rc
==
-
1
)
{
INIT_LOGE
(
"Failed to install
mod
e for %s failed options %s err: %d"
,
realPath
,
options
,
errno
);
INIT_LOGE
(
"Failed to install
kernel modul
e for %s failed options %s err: %d"
,
realPath
,
options
,
errno
);
}
}
}
}
if
(
options
!=
NULL
)
{
if
(
options
!=
NULL
)
{
...
...
services/init/standard/init_mount.c
浏览文件 @
235e009d
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
#include "init_log.h"
#include "init_log.h"
#include "securec.h"
#include "securec.h"
int
MountRequriedPartitions
(
Fstab
*
fstab
)
int
MountRequriedPartitions
(
const
Fstab
*
fstab
)
{
{
INIT_ERROR_CHECK
(
fstab
!=
NULL
,
return
-
1
,
"Failed fstab is NULL"
);
INIT_ERROR_CHECK
(
fstab
!=
NULL
,
return
-
1
,
"Failed fstab is NULL"
);
int
rc
=
-
1
;
int
rc
=
-
1
;
...
...
services/init/standard/init_mount.h
浏览文件 @
235e009d
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
#endif
#endif
int
MountRequriedPartitions
(
Fstab
*
fstab
);
int
MountRequriedPartitions
(
const
Fstab
*
fstab
);
#ifdef __cplusplus
#ifdef __cplusplus
#if __cplusplus
#if __cplusplus
}
}
...
...
services/init/standard/init_reboot.c
浏览文件 @
235e009d
...
@@ -43,16 +43,16 @@ static int RBMiscWriteUpdaterMessage(const char *path, const struct RBMiscUpdate
...
@@ -43,16 +43,16 @@ static int RBMiscWriteUpdaterMessage(const char *path, const struct RBMiscUpdate
INIT_CHECK_RETURN_VALUE
(
realPath
!=
NULL
,
-
1
);
INIT_CHECK_RETURN_VALUE
(
realPath
!=
NULL
,
-
1
);
int
ret
=
0
;
int
ret
=
0
;
FILE
*
fp
=
fopen
(
realPath
,
"rb+"
);
FILE
*
fp
=
fopen
(
realPath
,
"rb+"
);
free
(
realPath
);
realPath
=
NULL
;
if
(
fp
!=
NULL
)
{
if
(
fp
!=
NULL
)
{
size_t
writeLen
=
fwrite
(
boot
,
sizeof
(
struct
RBMiscUpdateMessage
),
1
,
fp
);
size_t
writeLen
=
fwrite
(
boot
,
sizeof
(
struct
RBMiscUpdateMessage
),
1
,
fp
);
INIT_ERROR_CHECK
(
writeLen
==
1
,
ret
=
-
1
,
"Failed to write misc for reboot"
);
INIT_ERROR_CHECK
(
writeLen
==
1
,
ret
=
-
1
,
"Failed to write misc for reboot"
);
(
void
)
fclose
(
fp
);
}
else
{
}
else
{
ret
=
-
1
;
ret
=
-
1
;
INIT_LOGE
(
"Failed to open %s"
,
path
);
INIT_LOGE
(
"Failed to open %s"
,
path
);
}
}
free
(
realPath
);
realPath
=
NULL
;
(
void
)
fclose
(
fp
);
return
ret
;
return
ret
;
}
}
...
@@ -62,17 +62,16 @@ static int RBMiscReadUpdaterMessage(const char *path, struct RBMiscUpdateMessage
...
@@ -62,17 +62,16 @@ static int RBMiscReadUpdaterMessage(const char *path, struct RBMiscUpdateMessage
INIT_CHECK_RETURN_VALUE
(
realPath
!=
NULL
,
-
1
);
INIT_CHECK_RETURN_VALUE
(
realPath
!=
NULL
,
-
1
);
int
ret
=
0
;
int
ret
=
0
;
FILE
*
fp
=
fopen
(
realPath
,
"rb"
);
FILE
*
fp
=
fopen
(
realPath
,
"rb"
);
free
(
realPath
);
realPath
=
NULL
;
if
(
fp
!=
NULL
)
{
if
(
fp
!=
NULL
)
{
size_t
readLen
=
fread
(
boot
,
1
,
sizeof
(
struct
RBMiscUpdateMessage
),
fp
);
size_t
readLen
=
fread
(
boot
,
1
,
sizeof
(
struct
RBMiscUpdateMessage
),
fp
);
INIT_ERROR_CHECK
(
readLen
>
0
,
ret
=
-
1
,
"Failed to read misc for reboot"
);
INIT_ERROR_CHECK
(
readLen
>
0
,
ret
=
-
1
,
"Failed to read misc for reboot"
);
(
void
)
fclose
(
fp
);
}
else
{
}
else
{
ret
=
-
1
;
ret
=
-
1
;
INIT_LOGE
(
"Failed to open %s"
,
path
);
INIT_LOGE
(
"Failed to open %s"
,
path
);
}
}
free
(
realPath
);
realPath
=
NULL
;
(
void
)
fclose
(
fp
);
return
ret
;
return
ret
;
}
}
...
...
services/init/standard/switch_root.c
浏览文件 @
235e009d
...
@@ -135,6 +135,14 @@ static int MountToNewTarget(const char *target)
...
@@ -135,6 +135,14 @@ static int MountToNewTarget(const char *target)
return
0
;
return
0
;
}
}
static
void
FreeRootDir
(
DIR
*
oldRoot
,
dev_t
dev
)
{
if
(
oldRoot
!=
NULL
)
{
FreeOldRoot
(
oldRoot
,
dev
);
closedir
(
oldRoot
);
}
}
// Switch root from ramdisk to system
// Switch root from ramdisk to system
int
SwitchRoot
(
const
char
*
newRoot
)
int
SwitchRoot
(
const
char
*
newRoot
)
{
{
...
@@ -157,35 +165,39 @@ int SwitchRoot(const char *newRoot)
...
@@ -157,35 +165,39 @@ int SwitchRoot(const char *newRoot)
struct
stat
newRootStat
=
{};
struct
stat
newRootStat
=
{};
if
(
stat
(
newRoot
,
&
newRootStat
)
!=
0
)
{
if
(
stat
(
newRoot
,
&
newRootStat
)
!=
0
)
{
INIT_LOGE
(
"Failed to get new root
\"
%s
\"
stat"
,
newRoot
);
INIT_LOGE
(
"Failed to get new root
\"
%s
\"
stat"
,
newRoot
);
FreeRootDir
(
oldRoot
,
oldRootStat
.
st_dev
);
return
-
1
;
return
-
1
;
}
}
if
(
oldRootStat
.
st_dev
==
newRootStat
.
st_dev
)
{
if
(
oldRootStat
.
st_dev
==
newRootStat
.
st_dev
)
{
INIT_LOGW
(
"Try to switch root in same device, skip switching root"
);
INIT_LOGW
(
"Try to switch root in same device, skip switching root"
);
FreeRootDir
(
oldRoot
,
oldRootStat
.
st_dev
);
return
0
;
return
0
;
}
}
if
(
MountToNewTarget
(
newRoot
)
<
0
)
{
if
(
MountToNewTarget
(
newRoot
)
<
0
)
{
INIT_LOGE
(
"Failed to move mount to new root
\"
%s
\"
stat"
,
newRoot
);
INIT_LOGE
(
"Failed to move mount to new root
\"
%s
\"
stat"
,
newRoot
);
FreeRootDir
(
oldRoot
,
oldRootStat
.
st_dev
);
return
-
1
;
return
-
1
;
}
}
// OK, we've done move mount.
// OK, we've done move mount.
// Now mount new root.
// Now mount new root.
if
(
chdir
(
newRoot
)
<
0
)
{
if
(
chdir
(
newRoot
)
<
0
)
{
INIT_LOGE
(
"Failed to change directory to %s, err = %d"
,
newRoot
,
errno
);
INIT_LOGE
(
"Failed to change directory to %s, err = %d"
,
newRoot
,
errno
);
FreeRootDir
(
oldRoot
,
oldRootStat
.
st_dev
);
return
-
1
;
return
-
1
;
}
}
if
(
mount
(
newRoot
,
"/"
,
NULL
,
MS_MOVE
,
NULL
)
<
0
)
{
if
(
mount
(
newRoot
,
"/"
,
NULL
,
MS_MOVE
,
NULL
)
<
0
)
{
INIT_LOGE
(
"Failed to mount moving %s to %s, err = %d"
,
newRoot
,
"/"
,
errno
);
INIT_LOGE
(
"Failed to mount moving %s to %s, err = %d"
,
newRoot
,
"/"
,
errno
);
FreeRootDir
(
oldRoot
,
oldRootStat
.
st_dev
);
return
-
1
;
return
-
1
;
}
}
if
(
chroot
(
"."
)
<
0
)
{
if
(
chroot
(
"."
)
<
0
)
{
INIT_LOGE
(
"Failed to change root directory"
);
INIT_LOGE
(
"Failed to change root directory"
);
FreeRootDir
(
oldRoot
,
oldRootStat
.
st_dev
);
return
-
1
;
return
-
1
;
}
}
FreeOldRoot
(
oldRoot
,
oldRootStat
.
st_dev
);
FreeRootDir
(
oldRoot
,
oldRootStat
.
st_dev
);
closedir
(
oldRoot
);
oldRoot
=
NULL
;
return
0
;
return
0
;
}
}
services/param/adapter/param_persistadp.c
浏览文件 @
235e009d
...
@@ -50,10 +50,10 @@ static int LoadPersistParam(PersistParamGetPtr persistParamGet, void *context)
...
@@ -50,10 +50,10 @@ static int LoadPersistParam(PersistParamGetPtr persistParamGet, void *context)
int
ret
=
persistParamGet
(
info
[
0
].
value
,
info
[
1
].
value
,
context
);
int
ret
=
persistParamGet
(
info
[
0
].
value
,
info
[
1
].
value
,
context
);
PARAM_CHECK
(
ret
==
0
,
continue
,
"Failed to set param %d %s"
,
ret
,
buff
);
PARAM_CHECK
(
ret
==
0
,
continue
,
"Failed to set param %d %s"
,
ret
,
buff
);
}
}
if
(
info
)
{
if
(
info
!=
NULL
)
{
free
(
info
);
free
(
info
);
}
}
if
(
buff
)
{
if
(
buff
!=
NULL
)
{
free
(
buff
);
free
(
buff
);
}
}
(
void
)
fclose
(
fp
);
(
void
)
fclose
(
fp
);
...
@@ -107,4 +107,4 @@ int RegisterPersistParamOps(PersistParamOps *ops)
...
@@ -107,4 +107,4 @@ int RegisterPersistParamOps(PersistParamOps *ops)
ops
->
batchSave
=
BatchSavePersistParam
;
ops
->
batchSave
=
BatchSavePersistParam
;
ops
->
batchSaveEnd
=
BatchSavePersistParamEnd
;
ops
->
batchSaveEnd
=
BatchSavePersistParamEnd
;
return
0
;
return
0
;
}
}
\ No newline at end of file
services/param/adapter/param_selinux.c
浏览文件 @
235e009d
...
@@ -84,10 +84,10 @@ static int LoadParamLabels(const char *fileName, SecurityLabelFunc label, void *
...
@@ -84,10 +84,10 @@ static int LoadParamLabels(const char *fileName, SecurityLabelFunc label, void *
PARAM_CHECK
(
ret
==
0
,
continue
,
"Failed to write param info %d %s"
,
ret
,
buff
);
PARAM_CHECK
(
ret
==
0
,
continue
,
"Failed to write param info %d %s"
,
ret
,
buff
);
infoCount
++
;
infoCount
++
;
}
}
if
(
buff
)
{
if
(
buff
!=
NULL
)
{
free
(
buff
);
free
(
buff
);
}
}
if
(
info
)
{
if
(
info
!=
NULL
)
{
free
(
info
);
free
(
info
);
}
}
(
void
)
fclose
(
fp
);
(
void
)
fclose
(
fp
);
...
...
services/param/client/param_request.c
浏览文件 @
235e009d
...
@@ -184,7 +184,7 @@ int SystemSetParameter(const char *name, const char *value)
...
@@ -184,7 +184,7 @@ int SystemSetParameter(const char *name, const char *value)
uint32_t
msgSize
=
sizeof
(
ParamMessage
)
+
sizeof
(
ParamMsgContent
)
+
PARAM_ALIGN
(
strlen
(
value
)
+
1
);
uint32_t
msgSize
=
sizeof
(
ParamMessage
)
+
sizeof
(
ParamMsgContent
)
+
PARAM_ALIGN
(
strlen
(
value
)
+
1
);
uint32_t
labelLen
=
0
;
uint32_t
labelLen
=
0
;
ParamSecurityOps
*
ops
=
GetClientParamSecurityOps
();
ParamSecurityOps
*
ops
=
GetClientParamSecurityOps
();
if
(
NeedCheckParamPermission
(
name
))
{
if
(
NeedCheckParamPermission
(
name
)
==
1
)
{
ret
=
CheckParamPermission
(
&
g_clientSpace
.
paramSpace
,
g_clientSpace
.
paramSpace
.
securityLabel
,
name
,
DAC_WRITE
);
ret
=
CheckParamPermission
(
&
g_clientSpace
.
paramSpace
,
g_clientSpace
.
paramSpace
.
securityLabel
,
name
,
DAC_WRITE
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Forbit to set parameter %s"
,
name
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Forbit to set parameter %s"
,
name
);
}
else
if
(
!
LABEL_IS_ALL_PERMITTED
(
g_clientSpace
.
paramSpace
.
securityLabel
))
{
// check local can check permissions
}
else
if
(
!
LABEL_IS_ALL_PERMITTED
(
g_clientSpace
.
paramSpace
.
securityLabel
))
{
// check local can check permissions
...
...
services/param/cmd/param_cmd.c
浏览文件 @
235e009d
...
@@ -168,7 +168,7 @@ int RunParamCommand(int argc, char *argv[])
...
@@ -168,7 +168,7 @@ int RunParamCommand(int argc, char *argv[])
}
}
for
(
size_t
i
=
0
;
i
<
sizeof
(
paramCmds
)
/
sizeof
(
paramCmds
[
0
]);
i
++
)
{
for
(
size_t
i
=
0
;
i
<
sizeof
(
paramCmds
)
/
sizeof
(
paramCmds
[
0
]);
i
++
)
{
if
(
strcmp
(
argv
[
1
],
paramCmds
[
i
].
name
)
==
0
)
{
if
(
argv
[
1
]
!=
NULL
&&
strcmp
(
argv
[
1
],
paramCmds
[
i
].
name
)
==
0
)
{
if
(
argc
<
paramCmds
[
i
].
minArg
)
{
if
(
argc
<
paramCmds
[
i
].
minArg
)
{
printf
(
"usage: %s
\n
"
,
paramCmds
[
i
].
help
);
printf
(
"usage: %s
\n
"
,
paramCmds
[
i
].
help
);
return
0
;
return
0
;
...
...
services/param/manager/param_manager.c
浏览文件 @
235e009d
...
@@ -76,6 +76,7 @@ int InitParamWorkSpace(ParamWorkSpace *workSpace, int onlyRead)
...
@@ -76,6 +76,7 @@ int InitParamWorkSpace(ParamWorkSpace *workSpace, int onlyRead)
void
CloseParamWorkSpace
(
ParamWorkSpace
*
workSpace
)
void
CloseParamWorkSpace
(
ParamWorkSpace
*
workSpace
)
{
{
PARAM_CHECK
(
workSpace
!=
NULL
,
return
,
"Invalid workSpace"
);
CloseWorkSpace
(
&
workSpace
->
paramSpace
);
CloseWorkSpace
(
&
workSpace
->
paramSpace
);
if
(
workSpace
->
paramSecurityOps
.
securityFreeLabel
!=
NULL
)
{
if
(
workSpace
->
paramSecurityOps
.
securityFreeLabel
!=
NULL
)
{
workSpace
->
paramSecurityOps
.
securityFreeLabel
(
workSpace
->
securityLabel
);
workSpace
->
paramSecurityOps
.
securityFreeLabel
(
workSpace
->
securityLabel
);
...
...
services/param/service/param_service.c
浏览文件 @
235e009d
...
@@ -494,7 +494,8 @@ static int OnIncomingConnect(const ParamTaskPtr server, uint32_t flags)
...
@@ -494,7 +494,8 @@ static int OnIncomingConnect(const ParamTaskPtr server, uint32_t flags)
PARAM_CHECK
(
ret
==
0
,
return
-
1
,
"Failed to create client"
);
PARAM_CHECK
(
ret
==
0
,
return
-
1
,
"Failed to create client"
);
ParamWatcher
*
watcher
=
(
ParamWatcher
*
)
ParamGetTaskUserData
(
client
);
ParamWatcher
*
watcher
=
(
ParamWatcher
*
)
ParamGetTaskUserData
(
client
);
PARAM_CHECK
(
watcher
!=
NULL
,
return
-
1
,
"Failed to get watcher"
);
PARAM_CHECK
(
watcher
!=
NULL
,
ParamTaskClose
(
client
);
return
-
1
,
"Failed to get watcher"
);
ListInit
(
&
watcher
->
node
);
ListInit
(
&
watcher
->
node
);
PARAM_TRIGGER_HEAD_INIT
(
watcher
->
triggerHead
);
PARAM_TRIGGER_HEAD_INIT
(
watcher
->
triggerHead
);
ListAddTail
(
&
GetTriggerWorkSpace
()
->
waitList
,
&
watcher
->
node
);
ListAddTail
(
&
GetTriggerWorkSpace
()
->
waitList
,
&
watcher
->
node
);
...
@@ -547,7 +548,7 @@ static int LoadParamFromCmdLine(void)
...
@@ -547,7 +548,7 @@ static int LoadParamFromCmdLine(void)
};
};
char
*
data
=
ReadFileData
(
PARAM_CMD_LINE
);
char
*
data
=
ReadFileData
(
PARAM_CMD_LINE
);
PARAM_CHECK
(
data
!=
NULL
,
return
-
1
,
"Failed to read file %s"
,
PARAM_CMD_LINE
);
PARAM_CHECK
(
data
!=
NULL
,
return
-
1
,
"Failed to read file %s"
,
PARAM_CMD_LINE
);
char
*
value
=
malloc
(
PARAM_CONST_VALUE_LEN_MAX
);
char
*
value
=
calloc
(
1
,
PARAM_CONST_VALUE_LEN_MAX
+
1
);
PARAM_CHECK
(
value
!=
NULL
,
free
(
data
);
PARAM_CHECK
(
value
!=
NULL
,
free
(
data
);
return
-
1
,
"Failed to read file %s"
,
PARAM_CMD_LINE
);
return
-
1
,
"Failed to read file %s"
,
PARAM_CMD_LINE
);
...
@@ -556,11 +557,11 @@ static int LoadParamFromCmdLine(void)
...
@@ -556,11 +557,11 @@ static int LoadParamFromCmdLine(void)
if
(
ret
==
0
)
{
if
(
ret
==
0
)
{
PARAM_LOGD
(
"Add param from cmdline %s %s"
,
cmdLines
[
i
],
value
);
PARAM_LOGD
(
"Add param from cmdline %s %s"
,
cmdLines
[
i
],
value
);
ret
=
CheckParamName
(
cmdLines
[
i
],
0
);
ret
=
CheckParamName
(
cmdLines
[
i
],
0
);
PARAM_CHECK
(
ret
==
0
,
return
-
1
,
"Invalid name %s"
,
cmdLines
[
i
]);
PARAM_CHECK
(
ret
==
0
,
break
,
"Invalid name %s"
,
cmdLines
[
i
]);
uint32_t
dataIndex
=
0
;
uint32_t
dataIndex
=
0
;
PARAM_LOGE
(
"**** cmdLines[%d] %s, value %s"
,
i
,
cmdLines
[
i
],
value
);
PARAM_LOGE
(
"**** cmdLines[%d] %s, value %s"
,
i
,
cmdLines
[
i
],
value
);
ret
=
WriteParam
(
&
g_paramWorkSpace
.
paramSpace
,
cmdLines
[
i
],
value
,
&
dataIndex
,
0
);
ret
=
WriteParam
(
&
g_paramWorkSpace
.
paramSpace
,
cmdLines
[
i
],
value
,
&
dataIndex
,
0
);
PARAM_CHECK
(
ret
==
0
,
return
-
1
,
"Failed to write param %s %s"
,
cmdLines
[
i
],
value
);
PARAM_CHECK
(
ret
==
0
,
break
,
"Failed to write param %s %s"
,
cmdLines
[
i
],
value
);
}
else
{
}
else
{
PARAM_LOGE
(
"Can not find arrt %s"
,
cmdLines
[
i
]);
PARAM_LOGE
(
"Can not find arrt %s"
,
cmdLines
[
i
]);
}
}
...
...
services/param/trigger/trigger_manager.c
浏览文件 @
235e009d
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
int
AddCommand
(
TriggerNode
*
trigger
,
uint32_t
cmdKeyIndex
,
const
char
*
content
)
int
AddCommand
(
TriggerNode
*
trigger
,
uint32_t
cmdKeyIndex
,
const
char
*
content
)
{
{
PARAM_CHECK
(
trigger
!=
NULL
,
return
-
1
,
"trigger is null"
);
PARAM_CHECK
(
trigger
!=
NULL
&&
trigger
->
triggerHead
!=
NULL
,
return
-
1
,
"trigger is null"
);
uint32_t
size
=
sizeof
(
CommandNode
);
uint32_t
size
=
sizeof
(
CommandNode
);
size
+=
(
content
==
NULL
)
?
1
:
(
strlen
(
content
)
+
1
);
size
+=
(
content
==
NULL
)
?
1
:
(
strlen
(
content
)
+
1
);
size
=
PARAM_ALIGN
(
size
);
size
=
PARAM_ALIGN
(
size
);
...
@@ -109,7 +109,7 @@ void ClearTrigger(TriggerHeader *head)
...
@@ -109,7 +109,7 @@ void ClearTrigger(TriggerHeader *head)
{
{
PARAM_CHECK
(
head
!=
NULL
,
return
,
"head is null"
);
PARAM_CHECK
(
head
!=
NULL
,
return
,
"head is null"
);
ListNode
*
node
=
head
->
triggerList
.
next
;
ListNode
*
node
=
head
->
triggerList
.
next
;
while
(
node
!=
&
head
->
triggerList
)
{
while
(
node
!=
&
head
->
triggerList
&&
node
!=
NULL
)
{
ListRemove
(
node
);
ListRemove
(
node
);
ListInit
(
node
);
ListInit
(
node
);
TriggerNode
*
trigger
=
ListEntry
(
node
,
TriggerNode
,
node
);
TriggerNode
*
trigger
=
ListEntry
(
node
,
TriggerNode
,
node
);
...
@@ -121,20 +121,24 @@ void ClearTrigger(TriggerHeader *head)
...
@@ -121,20 +121,24 @@ void ClearTrigger(TriggerHeader *head)
void
FreeTrigger
(
TriggerNode
*
trigger
)
void
FreeTrigger
(
TriggerNode
*
trigger
)
{
{
PARAM_CHECK
(
trigger
!=
NULL
&&
trigger
->
triggerHead
!=
NULL
,
return
,
"trigger is null"
);
PARAM_CHECK
(
trigger
!=
NULL
,
return
,
"trigger is null"
);
PARAM_LOGD
(
"FreeTrigger %s"
,
trigger
->
name
);
PARAM_LOGD
(
"FreeTrigger %s"
,
trigger
->
name
);
TriggerHeader
*
triggerHead
=
trigger
->
triggerHead
;
TriggerHeader
*
triggerHead
=
trigger
->
triggerHead
;
CommandNode
*
cmd
=
trigger
->
firstCmd
;
CommandNode
*
cmd
=
trigger
->
firstCmd
;
while
(
cmd
!=
NULL
)
{
while
(
cmd
!=
NULL
)
{
CommandNode
*
next
=
cmd
->
next
;
CommandNode
*
next
=
cmd
->
next
;
free
(
cmd
);
free
(
cmd
);
triggerHead
->
cmdNodeCount
--
;
if
(
triggerHead
!=
NULL
)
{
triggerHead
->
cmdNodeCount
--
;
}
cmd
=
next
;
cmd
=
next
;
}
}
trigger
->
lastCmd
=
NULL
;
trigger
->
lastCmd
=
NULL
;
trigger
->
firstCmd
=
NULL
;
trigger
->
firstCmd
=
NULL
;
ListRemove
(
&
trigger
->
node
);
ListRemove
(
&
trigger
->
node
);
triggerHead
->
triggerCount
--
;
if
(
triggerHead
!=
NULL
)
{
triggerHead
->
triggerCount
--
;
}
// 如果在执行队列,从队列中移走
// 如果在执行队列,从队列中移走
if
(
!
TRIGGER_IN_QUEUE
(
trigger
))
{
if
(
!
TRIGGER_IN_QUEUE
(
trigger
))
{
...
@@ -357,6 +361,7 @@ int CheckTrigger(TriggerWorkSpace *workSpace, int type,
...
@@ -357,6 +361,7 @@ int CheckTrigger(TriggerWorkSpace *workSpace, int type,
int
MarkTriggerToParam
(
const
TriggerWorkSpace
*
workSpace
,
const
TriggerHeader
*
triggerHead
,
const
char
*
name
)
int
MarkTriggerToParam
(
const
TriggerWorkSpace
*
workSpace
,
const
TriggerHeader
*
triggerHead
,
const
char
*
name
)
{
{
PARAM_CHECK
(
name
!=
NULL
,
return
0
,
"name is null"
);
int
ret
=
0
;
int
ret
=
0
;
TriggerNode
*
trigger
=
GetNextTrigger
(
triggerHead
,
NULL
);
TriggerNode
*
trigger
=
GetNextTrigger
(
triggerHead
,
NULL
);
while
(
trigger
!=
NULL
)
{
while
(
trigger
!=
NULL
)
{
...
@@ -445,6 +450,7 @@ void ClearWatcherTrigger(const ParamWatcher *watcher)
...
@@ -445,6 +450,7 @@ void ClearWatcherTrigger(const ParamWatcher *watcher)
static
void
DumpTriggerQueue
(
const
TriggerWorkSpace
*
workSpace
,
int
index
)
static
void
DumpTriggerQueue
(
const
TriggerWorkSpace
*
workSpace
,
int
index
)
{
{
const
int
maxCmd
=
1024
*
64
;
PARAM_CHECK
(
workSpace
!=
NULL
,
return
,
"Invalid workSpace "
);
PARAM_CHECK
(
workSpace
!=
NULL
,
return
,
"Invalid workSpace "
);
TriggerNode
*
trigger
=
GetNextTrigger
(
&
workSpace
->
triggerHead
[
index
],
NULL
);
TriggerNode
*
trigger
=
GetNextTrigger
(
&
workSpace
->
triggerHead
[
index
],
NULL
);
while
(
trigger
!=
NULL
)
{
while
(
trigger
!=
NULL
)
{
...
@@ -454,11 +460,13 @@ static void DumpTriggerQueue(const TriggerWorkSpace *workSpace, int index)
...
@@ -454,11 +460,13 @@ static void DumpTriggerQueue(const TriggerWorkSpace *workSpace, int index)
printf
(
"trigger condition %s
\n
"
,
trigger
->
condition
);
printf
(
"trigger condition %s
\n
"
,
trigger
->
condition
);
}
}
int
count
=
0
;
CommandNode
*
cmd
=
GetNextCmdNode
(
trigger
,
NULL
);
CommandNode
*
cmd
=
GetNextCmdNode
(
trigger
,
NULL
);
while
(
cmd
!=
NULL
)
{
while
(
cmd
!=
NULL
&&
count
<
maxCmd
)
{
printf
(
"
\t
command name %s
\n
"
,
GetCmdKey
(
cmd
->
cmdKeyIndex
));
printf
(
"
\t
command name %s
\n
"
,
GetCmdKey
(
cmd
->
cmdKeyIndex
));
printf
(
"
\t
command args %s
\n
"
,
cmd
->
content
);
printf
(
"
\t
command args %s
\n
"
,
cmd
->
content
);
cmd
=
GetNextCmdNode
(
trigger
,
cmd
);
cmd
=
GetNextCmdNode
(
trigger
,
cmd
);
count
++
;
}
}
trigger
=
GetNextTrigger
(
&
workSpace
->
triggerHead
[
index
],
trigger
);
trigger
=
GetNextTrigger
(
&
workSpace
->
triggerHead
[
index
],
trigger
);
}
}
...
...
services/param/trigger/trigger_processor.c
浏览文件 @
235e009d
...
@@ -52,7 +52,7 @@ static void TestTimerCallback(ParamTaskPtr timer, void *context)
...
@@ -52,7 +52,7 @@ static void TestTimerCallback(ParamTaskPtr timer, void *context)
static
uint32_t
value
=
0
;
static
uint32_t
value
=
0
;
int
count
=
0
;
int
count
=
0
;
while
(
count
<
MAX_COUNT
)
{
while
(
count
<
MAX_COUNT
)
{
int
wait
=
READ_DURATION
+
READ_DURATION
;
// 100ms
const
int
wait
=
READ_DURATION
+
READ_DURATION
;
// 100ms
sprintf_s
(
buffer
,
sizeof
(
buffer
),
"%u"
,
value
);
sprintf_s
(
buffer
,
sizeof
(
buffer
),
"%u"
,
value
);
PARAM_LOGI
(
"set param name: %s, value %s"
,
TEST_PARAM_NAME
,
buffer
);
PARAM_LOGI
(
"set param name: %s, value %s"
,
TEST_PARAM_NAME
,
buffer
);
SystemWriteParam
(
TEST_PARAM_NAME
,
buffer
);
SystemWriteParam
(
TEST_PARAM_NAME
,
buffer
);
...
...
services/param/watcher/proxy/watcher_manager.h
浏览文件 @
235e009d
...
@@ -93,8 +93,8 @@ public:
...
@@ -93,8 +93,8 @@ public:
watcher_
->
OnParamerterChange
(
name
,
value
);
watcher_
->
OnParamerterChange
(
name
,
value
);
#endif
#endif
}
}
ListNode
groupNode_
{
};
private:
private:
ListNode
groupNode_
;
uint32_t
watcherId_
=
{
0
};
uint32_t
watcherId_
=
{
0
};
sptr
<
IWatcher
>
watcher_
;
sptr
<
IWatcher
>
watcher_
;
WatcherGroupPtr
group_
{
nullptr
};
WatcherGroupPtr
group_
{
nullptr
};
...
@@ -110,15 +110,15 @@ public:
...
@@ -110,15 +110,15 @@ public:
void
AddWatcher
(
const
ParamWatcherPtr
&
watcher
);
void
AddWatcher
(
const
ParamWatcherPtr
&
watcher
);
void
ProcessParameterChange
(
const
std
::
string
&
name
,
const
std
::
string
&
value
);
void
ProcessParameterChange
(
const
std
::
string
&
name
,
const
std
::
string
&
value
);
const
std
::
string
GetKeyPrefix
()
const
std
::
string
GetKeyPrefix
()
const
{
{
return
keyPrefix_
;
return
keyPrefix_
;
}
}
bool
Emptry
()
bool
Emptry
()
const
{
{
return
ListEmpty
(
watchers_
);
return
ListEmpty
(
watchers_
);
}
}
uint32_t
GetGroupId
()
uint32_t
GetGroupId
()
const
{
{
return
groupId_
;
return
groupId_
;
}
}
...
...
test/unittest/init/cmds_unittest.cpp
浏览文件 @
235e009d
...
@@ -144,8 +144,8 @@ HWTEST_F(CmdsUnitTest, TestCommonChmod, TestSize.Level1)
...
@@ -144,8 +144,8 @@ HWTEST_F(CmdsUnitTest, TestCommonChmod, TestSize.Level1)
EXPECT_EQ
(
testMode
,
testMode
&
info
.
st_mode
);
EXPECT_EQ
(
testMode
,
testMode
&
info
.
st_mode
);
DoCmdByName
(
"chmod "
,
"777 /data/init_ut/test_dir0/test_file001"
);
DoCmdByName
(
"chmod "
,
"777 /data/init_ut/test_dir0/test_file001"
);
fd
=
-
1
;
close
(
fd
);
close
(
fd
);
fd
=
-
1
;
}
}
HWTEST_F
(
CmdsUnitTest
,
TestCommonCopy
,
TestSize
.
Level1
)
HWTEST_F
(
CmdsUnitTest
,
TestCommonCopy
,
TestSize
.
Level1
)
...
@@ -160,9 +160,8 @@ HWTEST_F(CmdsUnitTest, TestCommonCopy, TestSize.Level1)
...
@@ -160,9 +160,8 @@ HWTEST_F(CmdsUnitTest, TestCommonCopy, TestSize.Level1)
DoCmdByName
(
"copy "
,
"/data/init_ut/test_dir0/test_file_copy1 /data/init_ut/test_dir0/test_file_copy2"
);
DoCmdByName
(
"copy "
,
"/data/init_ut/test_dir0/test_file_copy1 /data/init_ut/test_dir0/test_file_copy2"
);
int
ret
=
access
(
testFile2
,
F_OK
);
int
ret
=
access
(
testFile2
,
F_OK
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
ret
,
0
);
fd
=
-
1
;
close
(
fd
);
close
(
fd
);
fd
=
-
1
;
// abnormal
// abnormal
DoCmdByName
(
"copy "
,
"/data/init_ut/test_dir0/test_file_copy1 /data/init_ut/test_dir0/test_file_copy1"
);
DoCmdByName
(
"copy "
,
"/data/init_ut/test_dir0/test_file_copy1 /data/init_ut/test_dir0/test_file_copy1"
);
DoCmdByName
(
"copy "
,
"/data/init_ut/test_dir0/test_file_copy11 /data/init_ut/test_dir0/test_file_copy1"
);
DoCmdByName
(
"copy "
,
"/data/init_ut/test_dir0/test_file_copy11 /data/init_ut/test_dir0/test_file_copy1"
);
...
@@ -178,11 +177,10 @@ HWTEST_F(CmdsUnitTest, TestCommonWrite, TestSize.Level1)
...
@@ -178,11 +177,10 @@ HWTEST_F(CmdsUnitTest, TestCommonWrite, TestSize.Level1)
DoCmdByName
(
"write "
,
"/data/init_ut/test_dir0/test_file_write1 aaa"
);
DoCmdByName
(
"write "
,
"/data/init_ut/test_dir0/test_file_write1 aaa"
);
const
int
bufLen
=
50
;
const
int
bufLen
=
50
;
char
buffer
[
bufLen
];
char
buffer
[
bufLen
];
int
length
=
read
(
fd
,
buffer
,
bufLen
);
int
length
=
read
(
fd
,
buffer
,
bufLen
-
1
);
EXPECT_EQ
(
length
,
strlen
(
"aaa"
));
EXPECT_EQ
(
length
,
strlen
(
"aaa"
));
fd
=
-
1
;
close
(
fd
);
close
(
fd
);
fd
=
-
1
;
// abnormal
// abnormal
DoCmdByName
(
"write "
,
"/data/init_ut/test_dir0/test_file_write2 aaa"
);
DoCmdByName
(
"write "
,
"/data/init_ut/test_dir0/test_file_write2 aaa"
);
}
}
...
@@ -252,6 +250,7 @@ HWTEST_F(CmdsUnitTest, TestGetCmdLinesFromJson, TestSize.Level1)
...
@@ -252,6 +250,7 @@ HWTEST_F(CmdsUnitTest, TestGetCmdLinesFromJson, TestSize.Level1)
cJSON
*
cmdsItem1
=
cJSON_GetArrayItem
(
cmdsItem
,
0
);
cJSON
*
cmdsItem1
=
cJSON_GetArrayItem
(
cmdsItem
,
0
);
ASSERT_NE
(
nullptr
,
cmdsItem1
);
ASSERT_NE
(
nullptr
,
cmdsItem1
);
CmdLines
**
cmdLines
=
(
CmdLines
**
)
calloc
(
1
,
1
);
CmdLines
**
cmdLines
=
(
CmdLines
**
)
calloc
(
1
,
1
);
ASSERT_NE
(
nullptr
,
cmdLines
);
int
ret
=
GetCmdLinesFromJson
(
cmdsItem1
,
cmdLines
);
int
ret
=
GetCmdLinesFromJson
(
cmdsItem1
,
cmdLines
);
EXPECT_EQ
(
ret
,
-
1
);
EXPECT_EQ
(
ret
,
-
1
);
cJSON
*
cmdsItem2
=
cJSON_GetObjectItem
(
cmdsItem1
,
"cmds"
);
cJSON
*
cmdsItem2
=
cJSON_GetObjectItem
(
cmdsItem1
,
"cmds"
);
...
...
test/unittest/init/mount_unittest.cpp
浏览文件 @
235e009d
...
@@ -38,6 +38,7 @@ HWTEST_F(MountUnitTest, TestMountRequriedPartitions, TestSize.Level0)
...
@@ -38,6 +38,7 @@ HWTEST_F(MountUnitTest, TestMountRequriedPartitions, TestSize.Level0)
if
(
fstab
!=
NULL
)
{
if
(
fstab
!=
NULL
)
{
int
ret
=
MountRequriedPartitions
(
fstab
);
int
ret
=
MountRequriedPartitions
(
fstab
);
EXPECT_EQ
(
ret
,
-
1
);
EXPECT_EQ
(
ret
,
-
1
);
ReleaseFstab
(
fstab
);
}
}
}
}
}
// namespace init_ut
}
// namespace init_ut
test/unittest/init/service_file_unittest.cpp
浏览文件 @
235e009d
...
@@ -39,6 +39,7 @@ HWTEST_F(ServiceFileUnitTest, TestServiceFile, TestSize.Level1)
...
@@ -39,6 +39,7 @@ HWTEST_F(ServiceFileUnitTest, TestServiceFile, TestSize.Level1)
{
{
const
char
*
fileName
=
"/data/filetest"
;
const
char
*
fileName
=
"/data/filetest"
;
ServiceFile
*
fileOpt
=
(
ServiceFile
*
)
calloc
(
1
,
sizeof
(
ServiceFile
)
+
strlen
(
fileName
)
+
1
);
ServiceFile
*
fileOpt
=
(
ServiceFile
*
)
calloc
(
1
,
sizeof
(
ServiceFile
)
+
strlen
(
fileName
)
+
1
);
ASSERT_NE
(
fileOpt
,
nullptr
);
fileOpt
->
next
=
NULL
;
fileOpt
->
next
=
NULL
;
fileOpt
->
flags
=
O_RDWR
;
fileOpt
->
flags
=
O_RDWR
;
fileOpt
->
uid
=
1000
;
fileOpt
->
uid
=
1000
;
...
@@ -47,6 +48,7 @@ HWTEST_F(ServiceFileUnitTest, TestServiceFile, TestSize.Level1)
...
@@ -47,6 +48,7 @@ HWTEST_F(ServiceFileUnitTest, TestServiceFile, TestSize.Level1)
fileOpt
->
perm
=
0770
;
fileOpt
->
perm
=
0770
;
if
(
strncpy_s
(
fileOpt
->
fileName
,
strlen
(
fileName
)
+
1
,
fileName
,
strlen
(
fileName
))
!=
0
)
{
if
(
strncpy_s
(
fileOpt
->
fileName
,
strlen
(
fileName
)
+
1
,
fileName
,
strlen
(
fileName
))
!=
0
)
{
free
(
fileOpt
);
free
(
fileOpt
);
fileOpt
=
nullptr
;
ASSERT_TRUE
(
1
);
ASSERT_TRUE
(
1
);
}
}
CreateServiceFile
(
fileOpt
);
CreateServiceFile
(
fileOpt
);
...
@@ -54,5 +56,6 @@ HWTEST_F(ServiceFileUnitTest, TestServiceFile, TestSize.Level1)
...
@@ -54,5 +56,6 @@ HWTEST_F(ServiceFileUnitTest, TestServiceFile, TestSize.Level1)
EXPECT_NE
(
ret
,
-
1
);
EXPECT_NE
(
ret
,
-
1
);
CloseServiceFile
(
fileOpt
);
CloseServiceFile
(
fileOpt
);
free
(
fileOpt
);
free
(
fileOpt
);
fileOpt
=
nullptr
;
}
}
}
}
test/unittest/init/service_socket_unittest.cpp
浏览文件 @
235e009d
...
@@ -32,11 +32,12 @@ public:
...
@@ -32,11 +32,12 @@ public:
HWTEST_F
(
ServiceSocketUnitTest
,
TestCreateSocket
,
TestSize
.
Level0
)
HWTEST_F
(
ServiceSocketUnitTest
,
TestCreateSocket
,
TestSize
.
Level0
)
{
{
ServiceSocket
*
sockopt
=
(
ServiceSocket
*
)
calloc
(
1
,
sizeof
(
ServiceSocket
));
ServiceSocket
*
sockopt
=
(
ServiceSocket
*
)
calloc
(
1
,
sizeof
(
ServiceSocket
));
ASSERT_NE
(
sockopt
,
nullptr
);
sockopt
->
type
=
SOCK_SEQPACKET
;
sockopt
->
type
=
SOCK_SEQPACKET
;
sockopt
->
sockFd
=
-
1
;
sockopt
->
sockFd
=
-
1
;
sockopt
->
uid
=
1000
;
sockopt
->
uid
=
1000
;
sockopt
->
gid
=
1000
;
sockopt
->
gid
=
1000
;
sockopt
->
perm
=
660
;
sockopt
->
perm
=
0
660
;
sockopt
->
passcred
=
true
;
sockopt
->
passcred
=
true
;
const
char
*
testSocName
=
"test_socket"
;
const
char
*
testSocName
=
"test_socket"
;
errno_t
ret
=
strncpy_s
(
sockopt
->
name
,
strlen
(
testSocName
)
+
1
,
testSocName
,
strlen
(
testSocName
));
errno_t
ret
=
strncpy_s
(
sockopt
->
name
,
strlen
(
testSocName
)
+
1
,
testSocName
,
strlen
(
testSocName
));
...
...
test/unittest/init/service_unittest.cpp
浏览文件 @
235e009d
...
@@ -79,6 +79,7 @@ HWTEST_F(ServiceUnitTest, TestServiceStartAbnormal, TestSize.Level1)
...
@@ -79,6 +79,7 @@ HWTEST_F(ServiceUnitTest, TestServiceStartAbnormal, TestSize.Level1)
cJSON
*
serviceItem
=
cJSON_GetObjectItem
(
jobItem
,
"services"
);
cJSON
*
serviceItem
=
cJSON_GetObjectItem
(
jobItem
,
"services"
);
ASSERT_NE
(
nullptr
,
serviceItem
);
ASSERT_NE
(
nullptr
,
serviceItem
);
Service
*
service
=
(
Service
*
)
calloc
(
1
,
sizeof
(
Service
));
Service
*
service
=
(
Service
*
)
calloc
(
1
,
sizeof
(
Service
));
ASSERT_NE
(
nullptr
,
service
);
int
ret
=
ParseOneService
(
serviceItem
,
service
);
int
ret
=
ParseOneService
(
serviceItem
,
service
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
ret
,
0
);
...
@@ -105,10 +106,12 @@ HWTEST_F(ServiceUnitTest, TestServiceStartAbnormal, TestSize.Level1)
...
@@ -105,10 +106,12 @@ HWTEST_F(ServiceUnitTest, TestServiceStartAbnormal, TestSize.Level1)
HWTEST_F
(
ServiceUnitTest
,
TestServiceReap
,
TestSize
.
Level1
)
HWTEST_F
(
ServiceUnitTest
,
TestServiceReap
,
TestSize
.
Level1
)
{
{
Service
*
service
=
(
Service
*
)
calloc
(
1
,
sizeof
(
Service
));
Service
*
service
=
(
Service
*
)
calloc
(
1
,
sizeof
(
Service
));
ASSERT_NE
(
nullptr
,
service
);
ServiceReap
(
service
);
ServiceReap
(
service
);
EXPECT_EQ
(
service
->
attribute
,
0
);
EXPECT_EQ
(
service
->
attribute
,
0
);
service
->
restartArg
=
(
CmdLines
*
)
calloc
(
1
,
sizeof
(
CmdLines
));
service
->
restartArg
=
(
CmdLines
*
)
calloc
(
1
,
sizeof
(
CmdLines
));
ASSERT_NE
(
nullptr
,
service
->
restartArg
);
ServiceReap
(
service
);
ServiceReap
(
service
);
EXPECT_EQ
(
service
->
attribute
,
0
);
EXPECT_EQ
(
service
->
attribute
,
0
);
...
@@ -142,6 +145,7 @@ HWTEST_F(ServiceUnitTest, TestServiceReapOther, TestSize.Level1)
...
@@ -142,6 +145,7 @@ HWTEST_F(ServiceUnitTest, TestServiceReapOther, TestSize.Level1)
ASSERT_NE
(
nullptr
,
serviceItem
);
ASSERT_NE
(
nullptr
,
serviceItem
);
Service
*
service
=
(
Service
*
)
calloc
(
1
,
sizeof
(
Service
));
Service
*
service
=
(
Service
*
)
calloc
(
1
,
sizeof
(
Service
));
ASSERT_NE
(
nullptr
,
service
);
int
ret
=
GetCmdLinesFromJson
(
cJSON_GetObjectItem
(
serviceItem
,
"onrestart"
),
&
service
->
restartArg
);
int
ret
=
GetCmdLinesFromJson
(
cJSON_GetObjectItem
(
serviceItem
,
"onrestart"
),
&
service
->
restartArg
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
ret
,
0
);
ret
=
ParseOneService
(
serviceItem
,
service
);
ret
=
ParseOneService
(
serviceItem
,
service
);
...
@@ -207,7 +211,9 @@ HWTEST_F(ServiceUnitTest, TestServiceManagerGetService, TestSize.Level1)
...
@@ -207,7 +211,9 @@ HWTEST_F(ServiceUnitTest, TestServiceManagerGetService, TestSize.Level1)
HWTEST_F
(
ServiceUnitTest
,
TestServiceExec
,
TestSize
.
Level1
)
HWTEST_F
(
ServiceUnitTest
,
TestServiceExec
,
TestSize
.
Level1
)
{
{
Service
*
service
=
(
Service
*
)
malloc
(
sizeof
(
Service
));
Service
*
service
=
(
Service
*
)
malloc
(
sizeof
(
Service
));
ASSERT_NE
(
service
,
nullptr
);
service
->
pathArgs
.
argv
=
(
char
**
)
malloc
(
sizeof
(
char
*
));
service
->
pathArgs
.
argv
=
(
char
**
)
malloc
(
sizeof
(
char
*
));
ASSERT_NE
(
service
->
pathArgs
.
argv
,
nullptr
);
service
->
pathArgs
.
count
=
1
;
service
->
pathArgs
.
count
=
1
;
const
char
*
path
=
"/data/init_ut/test_service_release"
;
const
char
*
path
=
"/data/init_ut/test_service_release"
;
service
->
pathArgs
.
argv
[
0
]
=
strdup
(
path
);
service
->
pathArgs
.
argv
[
0
]
=
strdup
(
path
);
...
...
test/unittest/param/client_unittest.cpp
浏览文件 @
235e009d
...
@@ -41,6 +41,9 @@ static void ClientCheckParamValue(const char *name, const char *expectValue)
...
@@ -41,6 +41,9 @@ static void ClientCheckParamValue(const char *name, const char *expectValue)
// 多线程测试
// 多线程测试
static
void
*
TestSendParamSetMsg
(
void
*
args
)
static
void
*
TestSendParamSetMsg
(
void
*
args
)
{
{
if
(
args
==
nullptr
)
{
return
nullptr
;
}
std
::
string
name
=
(
char
*
)
args
;
std
::
string
name
=
(
char
*
)
args
;
printf
(
"TestSendParamSetMsg name :
\'
%s
\'
\n
"
,
name
.
c_str
());
printf
(
"TestSendParamSetMsg name :
\'
%s
\'
\n
"
,
name
.
c_str
());
SystemSetParameter
(
name
.
c_str
(),
name
.
c_str
());
SystemSetParameter
(
name
.
c_str
(),
name
.
c_str
());
...
@@ -50,6 +53,9 @@ static void *TestSendParamSetMsg(void *args)
...
@@ -50,6 +53,9 @@ static void *TestSendParamSetMsg(void *args)
static
void
*
TestSendParamWaitMsg
(
void
*
args
)
static
void
*
TestSendParamWaitMsg
(
void
*
args
)
{
{
if
(
args
==
nullptr
)
{
return
nullptr
;
}
std
::
string
name
=
"Wati."
;
std
::
string
name
=
"Wati."
;
name
=
name
+
(
char
*
)
args
;
name
=
name
+
(
char
*
)
args
;
printf
(
"TestSendParamWaitMsg name :
\'
%s
\'
\n
"
,
name
.
c_str
());
printf
(
"TestSendParamWaitMsg name :
\'
%s
\'
\n
"
,
name
.
c_str
());
...
...
test/unittest/param/dac_unittest.cpp
浏览文件 @
235e009d
...
@@ -171,6 +171,9 @@ public:
...
@@ -171,6 +171,9 @@ public:
}
}
ParamSecurityLabel
*
tmp
=
nullptr
;
ParamSecurityLabel
*
tmp
=
nullptr
;
ret
=
clientParamSercurityOps
.
securityDecodeLabel
(
&
tmp
,
buffer
.
data
(),
buffer
.
size
());
ret
=
clientParamSercurityOps
.
securityDecodeLabel
(
&
tmp
,
buffer
.
data
(),
buffer
.
size
());
if
(
label
==
nullptr
||
tmp
==
nullptr
)
{
return
-
1
;
}
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
label
->
cred
.
gid
,
tmp
->
cred
.
gid
);
EXPECT_EQ
(
label
->
cred
.
gid
,
tmp
->
cred
.
gid
);
EXPECT_EQ
(
label
->
cred
.
uid
,
tmp
->
cred
.
uid
);
EXPECT_EQ
(
label
->
cred
.
uid
,
tmp
->
cred
.
uid
);
...
@@ -178,8 +181,8 @@ public:
...
@@ -178,8 +181,8 @@ public:
}
}
private:
private:
ParamSecurityOps
initParamSercurityOps
;
ParamSecurityOps
initParamSercurityOps
{}
;
ParamSecurityOps
clientParamSercurityOps
;
ParamSecurityOps
clientParamSercurityOps
{}
;
};
};
HWTEST_F
(
DacUnitTest
,
TestDacGetLabel
,
TestSize
.
Level0
)
HWTEST_F
(
DacUnitTest
,
TestDacGetLabel
,
TestSize
.
Level0
)
...
...
test/unittest/param/param_unittest.cpp
浏览文件 @
235e009d
...
@@ -116,6 +116,7 @@ public:
...
@@ -116,6 +116,7 @@ public:
ParamSecruityNode
*
node
=
(
ParamSecruityNode
*
)
GetTrieNode
(
&
GetParamWorkSpace
()
->
paramSpace
,
labelIndex
);
ParamSecruityNode
*
node
=
(
ParamSecruityNode
*
)
GetTrieNode
(
&
GetParamWorkSpace
()
->
paramSpace
,
labelIndex
);
if
(
paramNode
==
nullptr
||
node
==
nullptr
)
{
if
(
paramNode
==
nullptr
||
node
==
nullptr
)
{
EXPECT_EQ
(
1
,
0
);
EXPECT_EQ
(
1
,
0
);
return
0
;
}
}
EXPECT_EQ
(
node
->
gid
,
auditData
.
dacData
.
gid
);
EXPECT_EQ
(
node
->
gid
,
auditData
.
dacData
.
gid
);
return
0
;
return
0
;
...
@@ -149,6 +150,7 @@ public:
...
@@ -149,6 +150,7 @@ public:
ParamSecruityNode
*
node
=
(
ParamSecruityNode
*
)
GetTrieNode
(
&
GetParamWorkSpace
()
->
paramSpace
,
labelIndex
);
ParamSecruityNode
*
node
=
(
ParamSecruityNode
*
)
GetTrieNode
(
&
GetParamWorkSpace
()
->
paramSpace
,
labelIndex
);
if
(
paramNode
==
nullptr
||
node
==
nullptr
)
{
if
(
paramNode
==
nullptr
||
node
==
nullptr
)
{
EXPECT_EQ
(
1
,
0
);
EXPECT_EQ
(
1
,
0
);
return
0
;
}
}
EXPECT_EQ
((
int
)
node
->
gid
,
203
);
// 203 test gid
EXPECT_EQ
((
int
)
node
->
gid
,
203
);
// 203 test gid
return
0
;
return
0
;
...
@@ -173,6 +175,7 @@ public:
...
@@ -173,6 +175,7 @@ public:
ParamSecruityNode
*
node
=
(
ParamSecruityNode
*
)
GetTrieNode
(
&
GetParamWorkSpace
()
->
paramSpace
,
labelIndex
);
ParamSecruityNode
*
node
=
(
ParamSecruityNode
*
)
GetTrieNode
(
&
GetParamWorkSpace
()
->
paramSpace
,
labelIndex
);
if
(
paramNode
==
nullptr
||
node
==
nullptr
)
{
if
(
paramNode
==
nullptr
||
node
==
nullptr
)
{
EXPECT_EQ
(
1
,
0
);
EXPECT_EQ
(
1
,
0
);
return
0
;
}
}
EXPECT_EQ
(
node
->
gid
,
auditData
.
dacData
.
gid
);
EXPECT_EQ
(
node
->
gid
,
auditData
.
dacData
.
gid
);
return
0
;
return
0
;
...
@@ -371,7 +374,7 @@ public:
...
@@ -371,7 +374,7 @@ public:
do
{
do
{
uint32_t
offset
=
0
;
uint32_t
offset
=
0
;
int
ret
=
FillParamMsgContent
(
request
,
&
offset
,
PARAM_VALUE
,
value
,
strlen
(
value
));
int
ret
=
FillParamMsgContent
(
request
,
&
offset
,
PARAM_VALUE
,
value
,
strlen
(
value
));
PARAM_CHECK
(
ret
==
0
,
return
-
1
,
"Failed to fill value"
);
PARAM_CHECK
(
ret
==
0
,
break
,
"Failed to fill value"
);
ProcessMessage
((
const
ParamTaskPtr
)
g_worker
,
(
const
ParamMessage
*
)
request
);
ProcessMessage
((
const
ParamTaskPtr
)
g_worker
,
(
const
ParamMessage
*
)
request
);
}
while
(
0
);
}
while
(
0
);
free
(
request
);
free
(
request
);
...
...
test/unittest/param/selinux_unittest.cpp
浏览文件 @
235e009d
...
@@ -222,6 +222,9 @@ public:
...
@@ -222,6 +222,9 @@ public:
}
}
ParamSecurityLabel
*
tmp
=
nullptr
;
ParamSecurityLabel
*
tmp
=
nullptr
;
ret
=
clientParamSercurityOps
.
securityDecodeLabel
(
&
tmp
,
buffer
.
data
(),
buffer
.
size
());
ret
=
clientParamSercurityOps
.
securityDecodeLabel
(
&
tmp
,
buffer
.
data
(),
buffer
.
size
());
if
(
tmp
==
nullptr
||
label
==
nullptr
)
{
return
-
1
;
}
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
label
->
cred
.
gid
,
tmp
->
cred
.
gid
);
EXPECT_EQ
(
label
->
cred
.
gid
,
tmp
->
cred
.
gid
);
EXPECT_EQ
(
label
->
cred
.
uid
,
tmp
->
cred
.
uid
);
EXPECT_EQ
(
label
->
cred
.
uid
,
tmp
->
cred
.
uid
);
...
@@ -233,8 +236,8 @@ public:
...
@@ -233,8 +236,8 @@ public:
}
}
private:
private:
ParamSecurityOps
initParamSercurityOps
;
ParamSecurityOps
initParamSercurityOps
{}
;
ParamSecurityOps
clientParamSercurityOps
;
ParamSecurityOps
clientParamSercurityOps
{}
;
};
};
HWTEST_F
(
SelinuxUnitTest
,
TestSelinuxGetLabel
,
TestSize
.
Level0
)
HWTEST_F
(
SelinuxUnitTest
,
TestSelinuxGetLabel
,
TestSize
.
Level0
)
...
@@ -278,7 +281,7 @@ HWTEST_F(SelinuxUnitTest, TestSeliniuxLabelEncode, TestSize.Level0)
...
@@ -278,7 +281,7 @@ HWTEST_F(SelinuxUnitTest, TestSeliniuxLabelEncode, TestSize.Level0)
{
{
SelinuxUnitTest
test
;
SelinuxUnitTest
test
;
std
::
vector
<
char
>
buffer
;
std
::
vector
<
char
>
buffer
;
ParamSecurityLabel
*
label
;
ParamSecurityLabel
*
label
=
nullptr
;
test
.
TestEncode
(
label
,
buffer
);
test
.
TestEncode
(
label
,
buffer
);
test
.
TestDecode
(
label
,
buffer
);
test
.
TestDecode
(
label
,
buffer
);
}
}
\ No newline at end of file
test/unittest/param/trigger_unittest.cpp
浏览文件 @
235e009d
...
@@ -128,6 +128,9 @@ public:
...
@@ -128,6 +128,9 @@ public:
TriggerNode
*
node
=
AddTrigger
(
GetTriggerHeader
(
TRIGGER_BOOT
),
"init-later"
,
""
,
0
);
TriggerNode
*
node
=
AddTrigger
(
GetTriggerHeader
(
TRIGGER_BOOT
),
"init-later"
,
""
,
0
);
TriggerNode
*
trigger
=
GetTriggerByName
(
GetTriggerWorkSpace
(),
"init-later"
);
TriggerNode
*
trigger
=
GetTriggerByName
(
GetTriggerWorkSpace
(),
"init-later"
);
EXPECT_EQ
(
node
,
trigger
);
EXPECT_EQ
(
node
,
trigger
);
if
(
trigger
==
nullptr
)
{
return
-
1
;
}
EXPECT_EQ
(
strcmp
(
trigger
->
name
,
"init-later"
),
0
);
EXPECT_EQ
(
strcmp
(
trigger
->
name
,
"init-later"
),
0
);
// add command
// add command
...
@@ -146,13 +149,17 @@ public:
...
@@ -146,13 +149,17 @@ public:
TriggerNode
*
node
=
AddTrigger
(
GetTriggerHeader
(
TRIGGER_PARAM
),
triggerName
,
"test_param.000=1"
,
0
);
TriggerNode
*
node
=
AddTrigger
(
GetTriggerHeader
(
TRIGGER_PARAM
),
triggerName
,
"test_param.000=1"
,
0
);
TriggerNode
*
trigger
=
GetTriggerByName
(
GetTriggerWorkSpace
(),
triggerName
);
TriggerNode
*
trigger
=
GetTriggerByName
(
GetTriggerWorkSpace
(),
triggerName
);
EXPECT_EQ
(
trigger
,
node
);
EXPECT_EQ
(
trigger
,
node
);
if
(
trigger
==
nullptr
)
{
return
-
1
;
}
EXPECT_EQ
(
strcmp
(
trigger
->
name
,
triggerName
),
0
);
EXPECT_EQ
(
strcmp
(
trigger
->
name
,
triggerName
),
0
);
// add command
// add command
int
cmdIndex
=
0
;
int
cmdIndex
=
0
;
GetMatchCmd
(
"reboot "
,
&
cmdIndex
);
GetMatchCmd
(
"reboot "
,
&
cmdIndex
);
int
ret
=
AddCommand
(
trigger
,
cmdIndex
,
nullptr
);
int
ret
=
AddCommand
(
trigger
,
cmdIndex
,
nullptr
);
ret
|=
AddCommand
(
trigger
,
cmdIndex
,
"update: aaaaaaa"
);
EXPECT_EQ
(
ret
,
0
);
ret
=
AddCommand
(
trigger
,
cmdIndex
,
"update: aaaaaaa"
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
ret
,
0
);
return
0
;
return
0
;
}
}
...
@@ -392,6 +399,9 @@ public:
...
@@ -392,6 +399,9 @@ public:
TriggerNode
*
node
=
AddTrigger
(
GetTriggerHeader
(
TRIGGER_PARAM
),
triggerName
,
buffer
,
0
);
TriggerNode
*
node
=
AddTrigger
(
GetTriggerHeader
(
TRIGGER_PARAM
),
triggerName
,
buffer
,
0
);
TriggerNode
*
trigger
=
GetTriggerByName
(
GetTriggerWorkSpace
(),
triggerName
);
TriggerNode
*
trigger
=
GetTriggerByName
(
GetTriggerWorkSpace
(),
triggerName
);
EXPECT_EQ
(
trigger
,
node
);
EXPECT_EQ
(
trigger
,
node
);
if
(
trigger
==
nullptr
)
{
return
-
1
;
}
const
uint32_t
cmdIndex
=
103
;
const
uint32_t
cmdIndex
=
103
;
ret
=
AddCommand
(
trigger
,
cmdIndex
,
value
);
ret
=
AddCommand
(
trigger
,
cmdIndex
,
value
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
ret
,
0
);
...
@@ -423,6 +433,9 @@ public:
...
@@ -423,6 +433,9 @@ public:
TriggerNode
*
node
=
AddTrigger
(
GetTriggerHeader
(
TRIGGER_PARAM
),
triggerName
,
buffer
,
0
);
TriggerNode
*
node
=
AddTrigger
(
GetTriggerHeader
(
TRIGGER_PARAM
),
triggerName
,
buffer
,
0
);
TriggerNode
*
trigger
=
GetTriggerByName
(
GetTriggerWorkSpace
(),
triggerName
);
TriggerNode
*
trigger
=
GetTriggerByName
(
GetTriggerWorkSpace
(),
triggerName
);
EXPECT_EQ
(
trigger
,
node
);
EXPECT_EQ
(
trigger
,
node
);
if
(
trigger
==
nullptr
)
{
return
-
1
;
}
const
uint32_t
cmdIndex
=
105
;
const
uint32_t
cmdIndex
=
105
;
ret
=
AddCommand
(
trigger
,
cmdIndex
,
value
);
ret
=
AddCommand
(
trigger
,
cmdIndex
,
value
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
ret
,
0
);
...
@@ -457,6 +470,9 @@ public:
...
@@ -457,6 +470,9 @@ public:
const
int
testCmdIndex
=
1105
;
const
int
testCmdIndex
=
1105
;
int
ret
=
AddCommand
(
trigger
,
testCmdIndex
,
value
);
int
ret
=
AddCommand
(
trigger
,
testCmdIndex
,
value
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
ret
,
0
);
if
(
trigger
==
nullptr
)
{
return
-
1
;
}
TRIGGER_SET_FLAG
(
trigger
,
TRIGGER_FLAGS_SUBTRIGGER
);
TRIGGER_SET_FLAG
(
trigger
,
TRIGGER_FLAGS_SUBTRIGGER
);
char
buffer
[
triggerBuffer
];
char
buffer
[
triggerBuffer
];
...
...
ueventd/ueventd_socket.c
浏览文件 @
235e009d
...
@@ -66,7 +66,7 @@ int UeventdSocketInit(void)
...
@@ -66,7 +66,7 @@ int UeventdSocketInit(void)
ssize_t
ReadUeventMessage
(
int
sockFd
,
char
*
buffer
,
size_t
length
)
ssize_t
ReadUeventMessage
(
int
sockFd
,
char
*
buffer
,
size_t
length
)
{
{
ssize_t
n
=
-
1
;
ssize_t
n
=
-
1
;
struct
msghdr
msghdr
;
struct
msghdr
msghdr
=
{}
;
struct
iovec
iov
;
struct
iovec
iov
;
struct
sockaddr_nl
addr
;
struct
sockaddr_nl
addr
;
char
credMsg
[
CMSG_SPACE
(
sizeof
(
struct
ucred
))];
char
credMsg
[
CMSG_SPACE
(
sizeof
(
struct
ucred
))];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录