Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
4d341b1a
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,发现更多精彩内容 >>
提交
4d341b1a
编写于
6月 21, 2023
作者:
C
cheng_jinsong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix appspawn check
Signed-off-by:
N
cheng_jinsong
<
chengjinsong2@huawei.com
>
上级
4fb1cf39
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
32 addition
and
47 deletion
+32
-47
services/param/base/param_base.c
services/param/base/param_base.c
+24
-30
services/param/base/param_base.h
services/param/base/param_base.h
+3
-0
services/param/base/param_comm.c
services/param/base/param_comm.c
+1
-1
services/param/include/param_utils.h
services/param/include/param_utils.h
+4
-1
test/unittest/param/param_unittest.cpp
test/unittest/param/param_unittest.cpp
+0
-15
未找到文件。
services/param/base/param_base.c
浏览文件 @
4d341b1a
...
...
@@ -300,18 +300,39 @@ INIT_LOCAL_API int OpenWorkSpace(uint32_t index, int readOnly)
}
int
ret
=
0
;
uint32_t
rwSpaceLock
=
ATOMIC_LOAD_EXPLICIT
(
&
workSpace
->
rwSpaceLock
,
MEMORY_ORDER_ACQUIRE
);
if
(
rwSpaceLock
==
1
)
{
if
(
rwSpaceLock
&
WORKSPACE_STATUS_IN_PROCESS
)
{
PARAM_LOGW
(
"Workspace %s in init"
,
workSpace
->
fileName
);
return
-
1
;
}
ATOMIC_STORE_EXPLICIT
(
&
workSpace
->
rwSpaceLock
,
1
,
MEMORY_ORDER_RELEASE
);
ATOMIC_STORE_EXPLICIT
(
&
workSpace
->
rwSpaceLock
,
rwSpaceLock
|
WORKSPACE_STATUS_IN_PROCESS
,
MEMORY_ORDER_RELEASE
);
if
(
workSpace
->
area
==
NULL
)
{
ret
=
InitWorkSpace
(
workSpace
,
readOnly
,
workSpace
->
spaceSize
);
if
(
ret
!=
0
)
{
PARAM_LOGE
(
"Forbid to open workspace for %s error %d"
,
workSpace
->
fileName
,
errno
);
}
#ifndef PARAM_SUPPORT_SELINUX
}
ATOMIC_STORE_EXPLICIT
(
&
workSpace
->
rwSpaceLock
,
rwSpaceLock
&
~
WORKSPACE_STATUS_IN_PROCESS
,
MEMORY_ORDER_RELEASE
);
#else
}
else
if
(
readOnly
)
{
if
((
rwSpaceLock
&
WORKSPACE_STATUS_VALID
)
==
WORKSPACE_STATUS_VALID
)
{
ret
=
0
;
}
else
if
((
paramSpace
->
flags
&
WORKSPACE_FLAGS_NEED_ACCESS
)
==
WORKSPACE_FLAGS_NEED_ACCESS
)
{
char
buffer
[
FILENAME_LEN_MAX
]
=
{
0
};
int
size
=
PARAM_SPRINTF
(
buffer
,
sizeof
(
buffer
),
"%s/%s"
,
PARAM_STORAGE_PATH
,
workSpace
->
fileName
);
if
(
size
>
0
&&
access
(
buffer
,
R_OK
)
==
0
)
{
PARAM_LOGW
(
"Open workspace %s access ok "
,
workSpace
->
fileName
);
rwSpaceLock
|=
WORKSPACE_STATUS_VALID
;
ret
=
0
;
}
else
{
ret
=
-
1
;
PARAM_LOGE
(
"Forbid to open workspace for %s error %d"
,
workSpace
->
fileName
,
errno
);
rwSpaceLock
&=
~
WORKSPACE_STATUS_VALID
;
}
}
}
ATOMIC_STORE_EXPLICIT
(
&
workSpace
->
rwSpaceLock
,
0
,
MEMORY_ORDER_RELEASE
);
ATOMIC_STORE_EXPLICIT
(
&
workSpace
->
rwSpaceLock
,
rwSpaceLock
&
~
WORKSPACE_STATUS_IN_PROCESS
,
MEMORY_ORDER_RELEASE
);
#endif
return
ret
;
}
...
...
@@ -428,30 +449,6 @@ STATIC_INLINE int DacCheckParamPermission(const ParamLabelIndex *labelIndex,
}
#ifdef PARAM_SUPPORT_SELINUX
STATIC_INLINE
int
IsWorkSpaceReady
(
WorkSpace
*
workSpace
)
{
if
(
workSpace
==
NULL
)
{
return
-
1
;
}
int
ret
=
-
1
;
uint32_t
rwSpaceLock
=
ATOMIC_LOAD_EXPLICIT
(
&
workSpace
->
rwSpaceLock
,
MEMORY_ORDER_ACQUIRE
);
if
(
rwSpaceLock
==
1
)
{
return
ret
;
}
if
(
workSpace
->
area
!=
NULL
)
{
if
((
g_paramWorkSpace
.
flags
&
WORKSPACE_FLAGS_NEED_ACCESS
)
==
WORKSPACE_FLAGS_NEED_ACCESS
)
{
char
buffer
[
FILENAME_LEN_MAX
]
=
{
0
};
int
size
=
PARAM_SPRINTF
(
buffer
,
sizeof
(
buffer
),
"%s/%s"
,
PARAM_STORAGE_PATH
,
workSpace
->
fileName
);
if
(
size
>
0
&&
access
(
buffer
,
R_OK
)
==
0
)
{
ret
=
0
;
}
}
else
{
ret
=
0
;
}
}
return
ret
;
}
STATIC_INLINE
const
char
*
GetSelinuxContent
(
const
char
*
name
)
{
SelinuxSpace
*
selinuxSpace
=
&
g_paramWorkSpace
.
selinuxSpace
;
...
...
@@ -481,9 +478,6 @@ STATIC_INLINE int SelinuxCheckParamPermission(const ParamLabelIndex *labelIndex,
#ifdef STARTUP_INIT_TEST
return
selinuxSpace
->
readParamCheck
(
name
);
#endif
if
(
IsWorkSpaceReady
(
labelIndex
->
workspace
)
==
0
)
{
return
DAC_RESULT_PERMISSION
;
}
ret
=
OpenWorkSpace
(
labelIndex
->
selinuxLabelIndex
,
1
);
}
if
(
ret
!=
0
)
{
...
...
services/param/base/param_base.h
浏览文件 @
4d341b1a
...
...
@@ -29,6 +29,9 @@ extern "C" {
#endif
#endif
#define WORKSPACE_STATUS_IN_PROCESS 0x01
#define WORKSPACE_STATUS_VALID 0x02
#ifndef PARAM_BASE
#define PARAM_SPRINTF(buffer, buffSize, format, ...) \
snprintf_s
((
buffer
),
(
buffSize
),
(
buffSize
)
-
1
,
(
format
),
##
__VA_ARGS__
)
...
...
services/param/base/param_comm.c
浏览文件 @
4d341b1a
...
...
@@ -55,7 +55,7 @@ INIT_LOCAL_API WorkSpace *GetWorkSpace(uint32_t labelIndex)
return
NULL
;
}
uint32_t
rwSpaceLock
=
ATOMIC_LOAD_EXPLICIT
(
&
workSpace
->
rwSpaceLock
,
MEMORY_ORDER_ACQUIRE
);
if
(
rwSpaceLock
==
1
)
{
if
(
rwSpaceLock
&
WORKSPACE_STATUS_IN_PROCESS
)
{
return
NULL
;
}
if
(
workSpace
->
area
!=
NULL
)
{
...
...
services/param/include/param_utils.h
浏览文件 @
4d341b1a
...
...
@@ -47,7 +47,10 @@ typedef enum {
#define PARAM_ENTRY(ptr, type, member) (type *)((char *)(ptr)-offsetof(type, member))
#define IS_READY_ONLY(name) \
((
strncmp
((
name
),
"const."
,
strlen
(
"const."
))
==
0
)
||
(
strncmp
((
name
),
"ro."
,
strlen
(
"ro."
))
==
0
))
((
strncmp
((
name
),
"const."
,
strlen
(
"const."
))
==
0
)
||
\
(
strncmp
((
name
),
"ro."
,
strlen
(
"ro."
))
==
0
)
||
\
(
strncmp
((
name
),
"ohos.boot."
,
strlen
(
"ohos.boot."
))
==
0
))
#define PARAM_PERSIST_PREFIX "persist."
#define SYS_POWER_CTRL "ohos.startup.powerctrl="
...
...
test/unittest/param/param_unittest.cpp
浏览文件 @
4d341b1a
...
...
@@ -28,7 +28,6 @@ using namespace testing::ext;
using
namespace
std
;
extern
"C"
{
int
IsWorkSpaceReady
(
WorkSpace
*
workSpace
);
void
ParamWorBaseLog
(
InitLogLevel
logLevel
,
uint32_t
domain
,
const
char
*
tag
,
const
char
*
fmt
,
...);
static
void
OnClose
(
const
TaskHandle
taskHandle
)
{
...
...
@@ -663,19 +662,5 @@ HWTEST_F(ParamUnitTest, TestParamCache, TestSize.Level0)
EXPECT_EQ
(
valueChange
,
1
);
CachedParameterDestroy
(
cacheHandle3
);
}
#ifdef PARAM_SUPPORT_SELINUX
HWTEST_F
(
ParamUnitTest
,
TestInitParameterClient
,
TestSize
.
Level0
)
{
InitParameterClient
();
WorkSpace
*
workspace
=
GetWorkSpace
(
0
);
int
ret
=
IsWorkSpaceReady
(
workspace
);
EXPECT_EQ
(
ret
,
0
);
ret
=
IsWorkSpaceReady
(
NULL
);
EXPECT_NE
(
ret
,
0
);
workspace
=
GetWorkSpace
(
1
);
ret
=
IsWorkSpaceReady
(
workspace
);
EXPECT_EQ
(
ret
,
0
);
}
#endif
#endif
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录