Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
6d267dab
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,发现更多精彩内容 >>
未验证
提交
6d267dab
编写于
10月 21, 2022
作者:
O
openharmony_ci
提交者:
Gitee
10月 21, 2022
浏览文件
操作
浏览文件
下载
差异文件
!1414 修复代码静态告警(1020)
Merge pull request !1414 from cheng_jinsong/codex
上级
6c87b2a8
a921eb42
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
154 addition
and
116 deletion
+154
-116
services/init/standard/init.c
services/init/standard/init.c
+8
-2
services/modules/bootevent/bootevent.c
services/modules/bootevent/bootevent.c
+79
-81
services/param/watcher/agent/watcher_manager_kits.cpp
services/param/watcher/agent/watcher_manager_kits.cpp
+1
-1
services/param/watcher/agent/watcher_manager_kits.h
services/param/watcher/agent/watcher_manager_kits.h
+1
-1
services/param/watcher/proxy/watcher_manager.cpp
services/param/watcher/proxy/watcher_manager.cpp
+5
-5
services/param/watcher/proxy/watcher_manager.h
services/param/watcher/proxy/watcher_manager.h
+43
-15
test/moduletest/param_test_cmds.c
test/moduletest/param_test_cmds.c
+7
-4
test/moduletest/syspara_moduleTest.cpp
test/moduletest/syspara_moduleTest.cpp
+1
-1
test/unittest/param/param_stub.cpp
test/unittest/param/param_stub.cpp
+3
-3
test/unittest/param/watcher_agent_unittest.cpp
test/unittest/param/watcher_agent_unittest.cpp
+6
-3
未找到文件。
services/init/standard/init.c
浏览文件 @
6d267dab
...
...
@@ -343,12 +343,18 @@ static void TriggerServices(int startMode)
node
=
GetNextGroupNode
(
NODE_TYPE_SERVICES
,
node
);
continue
;
}
if
(
sprintf_s
(
cmd
,
sizeof
(
cmd
),
"start %s"
,
service
->
name
)
<=
0
)
{
node
=
GetNextGroupNode
(
NODE_TYPE_SERVICES
,
node
);
continue
;
}
if
(
index
==
0
)
{
(
void
)
sprintf_s
(
jobName
,
sizeof
(
jobName
),
"boot-service:service-%d-%03d"
,
startMode
,
jobNum
);
if
(
sprintf_s
(
jobName
,
sizeof
(
jobName
),
"boot-service:service-%d-%03d"
,
startMode
,
jobNum
)
<=
0
)
{
node
=
GetNextGroupNode
(
NODE_TYPE_SERVICES
,
node
);
continue
;
}
jobNum
++
;
}
index
++
;
(
void
)
sprintf_s
(
cmd
,
sizeof
(
cmd
),
"start %s"
,
service
->
name
);
AddCompleteJob
(
jobName
,
NULL
,
cmd
);
INIT_LOGV
(
"Add %s to job %s"
,
service
->
name
,
jobName
);
if
(
index
==
maxServiceInJob
)
{
...
...
services/modules/bootevent/bootevent.c
浏览文件 @
6d267dab
...
...
@@ -147,7 +147,81 @@ static void BootEventDestroy(ListNode *node)
free
((
void
*
)
bootEvent
);
}
static
int
SaveServiceBootEvent
();
static
int
AddItemToJson
(
cJSON
*
root
,
const
char
*
name
,
double
startTime
,
int
pid
,
double
durTime
)
{
cJSON
*
obj
=
cJSON_CreateObject
();
// release obj at traverse done
INIT_CHECK_RETURN_VALUE
(
obj
!=
NULL
,
-
1
);
cJSON_AddStringToObject
(
obj
,
"name"
,
name
);
cJSON_AddNumberToObject
(
obj
,
"ts"
,
startTime
);
cJSON_AddStringToObject
(
obj
,
"ph"
,
"X"
);
cJSON_AddNumberToObject
(
obj
,
"pid"
,
pid
);
cJSON_AddNumberToObject
(
obj
,
"tid"
,
pid
);
cJSON_AddNumberToObject
(
obj
,
"dur"
,
durTime
);
cJSON_AddItemToArray
(
root
,
obj
);
return
0
;
}
static
int
BootEventTraversal
(
ListNode
*
node
,
void
*
root
)
{
static
int
start
=
0
;
BOOT_EVENT_PARAM_ITEM
*
item
=
(
BOOT_EVENT_PARAM_ITEM
*
)
node
;
double
forkTime
=
item
->
timestamp
[
BOOTEVENT_FORK
].
tv_sec
*
SECTOMSEC
+
(
double
)
item
->
timestamp
[
BOOTEVENT_FORK
].
tv_nsec
/
MSECTONSEC
;
double
readyTime
=
item
->
timestamp
[
BOOTEVENT_READY
].
tv_sec
*
SECTOMSEC
+
(
double
)
item
->
timestamp
[
BOOTEVENT_READY
].
tv_nsec
/
MSECTONSEC
;
double
durTime
=
readyTime
-
forkTime
;
if
(
item
->
pid
==
0
)
{
if
(
durTime
<
SAVEINITBOOTEVENTMSEC
)
{
return
0
;
}
item
->
pid
=
1
;
// 1 is init pid
}
if
(
start
==
0
)
{
// set trace start time 0
INIT_CHECK_RETURN_VALUE
(
AddItemToJson
((
cJSON
*
)
root
,
item
->
paramName
,
0
,
1
,
0
)
==
0
,
-
1
);
start
++
;
}
INIT_CHECK_RETURN_VALUE
(
AddItemToJson
((
cJSON
*
)
root
,
item
->
paramName
,
forkTime
,
item
->
pid
,
durTime
>
0
?
durTime
:
0
)
==
0
,
-
1
);
return
0
;
}
static
int
SaveServiceBootEvent
()
{
if
(
g_bootEventEnable
==
0
)
{
return
0
;
}
time_t
nowTime
=
time
(
NULL
);
INIT_CHECK_RETURN_VALUE
(
nowTime
>
0
,
-
1
);
struct
tm
*
p
=
localtime
(
&
nowTime
);
INIT_CHECK_RETURN_VALUE
(
p
!=
NULL
,
-
1
);
char
bootEventFileName
[
BOOT_EVENT_FILEPATH_MAX_LEN
]
=
""
;
INIT_CHECK_RETURN_VALUE
(
snprintf_s
(
bootEventFileName
,
BOOT_EVENT_FILEPATH_MAX_LEN
,
BOOT_EVENT_FILEPATH_MAX_LEN
-
1
,
BOOTEVENT_OUTPUT_PATH
"%d%d%d-%d%d.bootevent"
,
1900
+
p
->
tm_year
,
p
->
tm_mon
,
p
->
tm_mday
,
p
->
tm_hour
,
p
->
tm_min
)
>=
0
,
-
1
);
// 1900 is start year
CheckAndCreatFile
(
bootEventFileName
,
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IROTH
);
FILE
*
tmpFile
=
fopen
(
bootEventFileName
,
"wr"
);
INIT_CHECK_RETURN_VALUE
(
tmpFile
!=
NULL
,
-
1
);
cJSON
*
root
=
cJSON_CreateArray
();
if
(
root
==
NULL
)
{
(
void
)
fclose
(
tmpFile
);
return
-
1
;
}
OH_ListTraversal
(
&
bootEventList
,
(
void
*
)
root
,
BootEventTraversal
,
0
);
char
*
buff
=
cJSON_Print
(
root
);
if
(
buff
==
NULL
)
{
cJSON_Delete
(
root
);
(
void
)
fclose
(
tmpFile
);
return
-
1
;
}
INIT_CHECK_ONLY_ELOG
(
fprintf
(
tmpFile
,
"%s
\n
"
,
buff
)
>=
0
,
"save boot event file failed"
);
free
(
buff
);
cJSON_Delete
(
root
);
(
void
)
fflush
(
tmpFile
);
(
void
)
fclose
(
tmpFile
);
return
0
;
}
static
void
BootEventParaFireByName
(
const
char
*
paramName
)
{
...
...
@@ -280,82 +354,6 @@ static int DoBootEventCmd(int id, const char *name, int argc, const char **argv)
return
0
;
}
static
int
AddItemToJson
(
cJSON
*
root
,
const
char
*
name
,
double
startTime
,
int
pid
,
double
durTime
)
{
cJSON
*
obj
=
cJSON_CreateObject
();
// release obj at traverse done
INIT_CHECK_RETURN_VALUE
(
obj
!=
NULL
,
-
1
);
cJSON_AddStringToObject
(
obj
,
"name"
,
name
);
cJSON_AddNumberToObject
(
obj
,
"ts"
,
startTime
);
cJSON_AddStringToObject
(
obj
,
"ph"
,
"X"
);
cJSON_AddNumberToObject
(
obj
,
"pid"
,
pid
);
cJSON_AddNumberToObject
(
obj
,
"tid"
,
pid
);
cJSON_AddNumberToObject
(
obj
,
"dur"
,
durTime
);
cJSON_AddItemToArray
(
root
,
obj
);
return
0
;
}
static
int
BootEventTraversal
(
ListNode
*
node
,
void
*
root
)
{
static
int
start
=
0
;
BOOT_EVENT_PARAM_ITEM
*
item
=
(
BOOT_EVENT_PARAM_ITEM
*
)
node
;
double
forkTime
=
item
->
timestamp
[
BOOTEVENT_FORK
].
tv_sec
*
SECTOMSEC
+
(
double
)
item
->
timestamp
[
BOOTEVENT_FORK
].
tv_nsec
/
MSECTONSEC
;
double
readyTime
=
item
->
timestamp
[
BOOTEVENT_READY
].
tv_sec
*
SECTOMSEC
+
(
double
)
item
->
timestamp
[
BOOTEVENT_READY
].
tv_nsec
/
MSECTONSEC
;
double
durTime
=
readyTime
-
forkTime
;
if
(
item
->
pid
==
0
)
{
if
(
durTime
<
SAVEINITBOOTEVENTMSEC
)
{
return
0
;
}
item
->
pid
=
1
;
// 1 is init pid
}
if
(
start
==
0
)
{
// set trace start time 0
INIT_CHECK_RETURN_VALUE
(
AddItemToJson
((
cJSON
*
)
root
,
item
->
paramName
,
0
,
1
,
0
)
==
0
,
-
1
);
start
++
;
}
INIT_CHECK_RETURN_VALUE
(
AddItemToJson
((
cJSON
*
)
root
,
item
->
paramName
,
forkTime
,
item
->
pid
,
durTime
>
0
?
durTime
:
0
)
==
0
,
-
1
);
return
0
;
}
static
int
SaveServiceBootEvent
()
{
if
(
g_bootEventEnable
==
0
)
{
return
0
;
}
time_t
nowTime
=
time
(
NULL
);
INIT_CHECK_RETURN_VALUE
(
nowTime
>
0
,
-
1
);
struct
tm
*
p
=
localtime
(
&
nowTime
);
INIT_CHECK_RETURN_VALUE
(
p
!=
NULL
,
-
1
);
char
bootEventFileName
[
BOOT_EVENT_FILEPATH_MAX_LEN
]
=
""
;
INIT_CHECK_RETURN_VALUE
(
snprintf
(
bootEventFileName
,
BOOT_EVENT_FILEPATH_MAX_LEN
,
BOOTEVENT_OUTPUT_PATH
"%d%d%d-%d%d.bootevent"
,
1900
+
p
->
tm_year
,
p
->
tm_mon
,
p
->
tm_mday
,
p
->
tm_hour
,
p
->
tm_min
)
>=
0
,
-
1
);
// 1900 is start year
CheckAndCreatFile
(
bootEventFileName
,
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IROTH
);
FILE
*
tmpFile
=
fopen
(
bootEventFileName
,
"wr"
);
INIT_CHECK_RETURN_VALUE
(
tmpFile
!=
NULL
,
-
1
);
cJSON
*
root
=
cJSON_CreateArray
();
if
(
root
==
NULL
)
{
(
void
)
fclose
(
tmpFile
);
return
-
1
;
}
OH_ListTraversal
(
&
bootEventList
,
(
void
*
)
root
,
BootEventTraversal
,
0
);
char
*
buff
=
cJSON_Print
(
root
);
if
(
buff
==
NULL
)
{
cJSON_Delete
(
root
);
(
void
)
fclose
(
tmpFile
);
return
-
1
;
}
INIT_CHECK_ONLY_ELOG
(
fprintf
(
tmpFile
,
"%s
\n
"
,
buff
)
>=
0
,
"save boot event file failed"
);
free
(
buff
);
cJSON_Delete
(
root
);
(
void
)
fflush
(
tmpFile
);
(
void
)
fclose
(
tmpFile
);
return
0
;
}
static
int32_t
g_executorId
=
-
1
;
static
int
ParamSetBootEventHook
(
const
HOOK_INFO
*
hookInfo
,
void
*
cookie
)
{
...
...
@@ -411,10 +409,10 @@ static void SetServiceBootEventFork(SERVICE_INFO_CTX *serviceCtx)
static
int
GetBootEventFlag
(
const
HOOK_INFO
*
info
,
void
*
cookie
)
{
char
B
ootEventOpen
[
6
]
=
""
;
// 6 is length of bool value
uint32_t
len
=
sizeof
(
B
ootEventOpen
);
SystemReadParam
(
"persist.init.bootevent.enable"
,
B
ootEventOpen
,
&
len
);
if
(
strcmp
(
B
ootEventOpen
,
"true"
)
!=
0
)
{
char
b
ootEventOpen
[
6
]
=
""
;
// 6 is length of bool value
uint32_t
len
=
sizeof
(
b
ootEventOpen
);
SystemReadParam
(
"persist.init.bootevent.enable"
,
b
ootEventOpen
,
&
len
);
if
(
strcmp
(
b
ootEventOpen
,
"true"
)
!=
0
)
{
g_bootEventEnable
=
0
;
}
return
0
;
...
...
services/param/watcher/agent/watcher_manager_kits.cpp
浏览文件 @
6d267dab
...
...
@@ -281,7 +281,7 @@ int WatcherManagerKits::ParamWatcher::DelParameterListener(ParameterChangePtr ca
}
void
WatcherManagerKits
::
RemoteWatcher
::
OnParameterChange
(
const
std
::
string
&
prefix
,
const
std
::
string
&
name
,
const
std
::
string
&
value
)
const
std
::
string
&
prefix
,
const
std
::
string
&
name
,
const
std
::
string
&
value
)
{
// get param watcher
WatcherManagerKits
::
ParamWatcher
*
watcher
=
watcherManager_
->
GetParamWatcher
(
prefix
);
...
...
services/param/watcher/agent/watcher_manager_kits.h
浏览文件 @
6d267dab
...
...
@@ -88,7 +88,7 @@ private:
class
RemoteWatcher
final
:
public
Watcher
{
public:
RemoteWatcher
(
WatcherManagerKits
*
watcherManager
)
:
watcherManager_
(
watcherManager
)
{}
explicit
RemoteWatcher
(
WatcherManagerKits
*
watcherManager
)
:
watcherManager_
(
watcherManager
)
{}
~
RemoteWatcher
(
void
)
override
{}
void
OnParameterChange
(
const
std
::
string
&
prefix
,
const
std
::
string
&
name
,
const
std
::
string
&
value
)
final
;
...
...
services/param/watcher/proxy/watcher_manager.cpp
浏览文件 @
6d267dab
...
...
@@ -464,7 +464,7 @@ int WatcherManager::Dump(int fd, const std::vector<std::u16string>& args)
dprintf
(
fd
,
"%s
\n
"
,
dumpInfo
.
c_str
());
return
0
;
}
auto
D
umpParamWatcher
=
[
this
,
fd
](
ParamWatcherListPtr
list
,
WatcherNodePtr
node
,
uint32_t
index
)
{
auto
d
umpParamWatcher
=
[
this
,
fd
](
ParamWatcherListPtr
list
,
WatcherNodePtr
node
,
uint32_t
index
)
{
auto
remoteWatcher
=
GetRemoteWatcher
(
node
->
GetNodeId
());
if
(
remoteWatcher
!=
nullptr
)
{
dprintf
(
fd
,
"%s%u(%u)"
,
(
index
==
0
)
?
"Watch id list : "
:
", "
,
...
...
@@ -482,11 +482,11 @@ int WatcherManager::Dump(int fd, const std::vector<std::u16string>& args)
}
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
watcherMutex_
);
group
->
TraversalNode
(
D
umpParamWatcher
);
group
->
TraversalNode
(
d
umpParamWatcher
);
}
return
0
;
}
DumpAllGroup
(
fd
,
D
umpParamWatcher
);
DumpAllGroup
(
fd
,
d
umpParamWatcher
);
return
0
;
}
...
...
@@ -662,7 +662,7 @@ void ParamWatcherList::TraversalNode(ParamWatcherProcessor handle)
uint32_t
index
=
0
;
// get first
WatcherNodePtr
node
=
WatcherNode
::
GetNextFromList
(
&
nodeList_
,
0
);
while
(
node
!=
NULL
)
{
while
(
node
!=
nullptr
)
{
WatcherNodePtr
next
=
node
->
GetNext
(
&
nodeList_
);
handle
(
this
,
node
,
index
);
node
=
next
;
...
...
@@ -675,7 +675,7 @@ void ParamWatcherList::TraversalNodeSafe(ParamWatcherProcessor processor)
uint32_t
index
=
0
;
// get first
WatcherNodePtr
node
=
WatcherNode
::
GetNextFromList
(
&
nodeList_
,
0
);
while
(
node
!=
NULL
)
{
while
(
node
!=
nullptr
)
{
uint32_t
nodeId
=
node
->
GetNodeId
();
// notify free, must be free
processor
(
this
,
node
,
index
);
...
...
services/param/watcher/proxy/watcher_manager.h
浏览文件 @
6d267dab
...
...
@@ -133,23 +133,30 @@ private:
class
WatcherNode
{
public:
WatcherNode
(
uint32_t
nodeId
)
:
nodeId_
(
nodeId
)
explicit
WatcherNode
(
uint32_t
nodeId
)
:
nodeId_
(
nodeId
)
{
OH_ListInit
(
&
node_
);
}
virtual
~
WatcherNode
(
void
)
=
default
;
uint32_t
GetNodeId
(
void
)
const
{
return
nodeId_
;
}
uint32_t
GetNodeId
(
void
)
const
{
return
nodeId_
;
}
void
AddToList
(
ListHeadPtr
list
);
void
RemoveFromList
(
ListHeadPtr
list
);
WatcherNodePtr
GetNext
(
ListHeadPtr
list
);
static
WatcherNodePtr
GetFromList
(
ListHeadPtr
list
,
uint32_t
nodeId
);
static
WatcherNodePtr
GetNextFromList
(
ListHeadPtr
list
,
uint32_t
nodeId
);
static
WatcherNodePtr
ConvertNodeToBase
(
ListNodePtr
node
)
{
WatcherNodePtr
tmp
=
NULL
;
static
WatcherNodePtr
ConvertNodeToBase
(
ListNodePtr
node
)
{
WatcherNodePtr
tmp
=
nullptr
;
return
reinterpret_cast
<
WatcherNodePtr
>
((
char
*
)
node
-
(
char
*
)
tmp
->
GetListNode
());
}
ListNodePtr
GetListNode
()
{
return
&
node_
;
}
ListNodePtr
GetListNode
()
{
return
&
node_
;
}
private:
static
int
CompareNode
(
ListNodePtr
node
,
ListNodePtr
newNode
);
static
int
CompareData
(
ListNodePtr
node
,
void
*
data
);
...
...
@@ -177,7 +184,7 @@ inline T *ConvertTo(WatcherNodePtr node)
class
ParamWatcher
:
public
WatcherNode
{
public:
ParamWatcher
(
uint32_t
watcherId
)
:
WatcherNode
(
watcherId
)
{}
explicit
ParamWatcher
(
uint32_t
watcherId
)
:
WatcherNode
(
watcherId
)
{}
~
ParamWatcher
(
void
)
override
{}
};
...
...
@@ -193,7 +200,10 @@ public:
{
return
nodeList_
.
next
==
&
nodeList_
;
}
uint32_t
GetNodeCount
(
void
)
const
{
return
nodeCount_
;
}
uint32_t
GetNodeCount
(
void
)
const
{
return
nodeCount_
;
}
int
AddNode
(
WatcherNodePtr
node
);
int
RemoveNode
(
WatcherNodePtr
node
);
WatcherNodePtr
GetNode
(
uint32_t
nodeId
);
...
...
@@ -209,7 +219,7 @@ public:
class
RemoteWatcher
:
public
WatcherNode
,
public
ParamWatcherList
{
public:
RemoteWatcher
(
uint32_t
watcherId
,
const
sptr
<
IWatcher
>
&
watcher
)
:
WatcherNode
(
watcherId
),
ParamWatcherList
(),
watcher_
(
watcher
)
{}
:
WatcherNode
(
watcherId
),
ParamWatcherList
(),
watcher_
(
watcher
)
{}
~
RemoteWatcher
(
void
)
override
{
watcher_
=
nullptr
;
...
...
@@ -220,14 +230,26 @@ public:
});
}
uint32_t
GetRemoteWatcherId
(
void
)
const
{
return
GetNodeId
();
}
uint32_t
GetAgentId
(
void
)
const
{
return
id_
;
}
void
SetAgentId
(
uint32_t
id
)
{
id_
=
id
;
}
uint32_t
GetRemoteWatcherId
(
void
)
const
{
return
GetNodeId
();
}
uint32_t
GetAgentId
(
void
)
const
{
return
id_
;
}
void
SetAgentId
(
uint32_t
id
)
{
id_
=
id
;
}
void
ProcessParameterChange
(
const
std
::
string
&
prefix
,
const
std
::
string
&
name
,
const
std
::
string
&
value
)
{
watcher_
->
OnParameterChange
(
prefix
,
name
,
value
);
}
sptr
<
IWatcher
>
GetWatcher
(
void
)
{
return
watcher_
;
}
sptr
<
IWatcher
>
GetWatcher
(
void
)
{
return
watcher_
;
}
private:
uint32_t
id_
=
{
0
};
sptr
<
IWatcher
>
watcher_
{};
...
...
@@ -236,7 +258,7 @@ private:
class
WatcherGroup
:
public
WatcherNode
,
public
ParamWatcherList
{
public:
WatcherGroup
(
uint32_t
groupId
,
const
std
::
string
&
key
)
:
WatcherNode
(
groupId
),
ParamWatcherList
(),
keyPrefix_
(
key
)
{}
:
WatcherNode
(
groupId
),
ParamWatcherList
(),
keyPrefix_
(
key
)
{}
~
WatcherGroup
()
override
{
TraversalNodeSafe
([](
ParamWatcherListPtr
list
,
WatcherNodePtr
node
,
uint32_t
index
)
{
...
...
@@ -246,8 +268,14 @@ public:
});
}
void
ProcessParameterChange
(
WatcherManager
*
mananger
,
const
std
::
string
&
name
,
const
std
::
string
&
value
);
const
std
::
string
GetKeyPrefix
()
const
{
return
keyPrefix_
;
}
uint32_t
GetGroupId
()
const
{
return
GetNodeId
();
}
const
std
::
string
GetKeyPrefix
()
const
{
return
keyPrefix_
;
}
uint32_t
GetGroupId
()
const
{
return
GetNodeId
();
}
private:
std
::
string
keyPrefix_
{
};
};
...
...
test/moduletest/param_test_cmds.c
浏览文件 @
6d267dab
...
...
@@ -93,7 +93,7 @@ static void HandleParamChange2(const char *key, const char *value, void *context
PLUGIN_CHECK
(
key
!=
NULL
&&
value
!=
NULL
,
return
,
"Invalid parameter"
);
long
long
commit
=
GetSystemCommitId
();
size_t
index
=
(
size_t
)
context
;
printf
(
"[%zu] Receive parameter
%p commit %lld change %s %s
\n
"
,
index
,
context
,
commit
,
key
,
value
);
printf
(
"[%zu] Receive parameter
commit %lld change %s %s
\n
"
,
index
,
commit
,
key
,
value
);
static
int
addWatcher
=
0
;
int
ret
=
0
;
if
((
index
==
4
)
&&
!
addWatcher
)
{
// 4 when context == 4 add
...
...
@@ -202,14 +202,14 @@ static int32_t BShellParamCmdWatch(BShellHandle shell, int32_t argc, char *argv[
int
maxCount
=
StringToInt
(
argv
[
CMD_INDEX
],
-
1
);
// 2 cmd index
if
(
maxCount
<=
0
||
maxCount
>
65535
)
{
// 65535 max count
PLUGIN_LOGE
(
"Invalid input %s"
,
argv
[
2
]);
PLUGIN_LOGE
(
"Invalid input %s"
,
argv
[
CMD_INDEX
]);
return
0
;
}
uint32_t
buffSize
=
0
;
char
*
buffer
=
GetLocalBuffer
(
&
buffSize
);
size_t
count
=
0
;
while
(
count
<
(
size_t
)
maxCount
)
{
// 100 max count
int
len
=
sprintf_s
(
buffer
,
buffSize
,
"%s.%
d
"
,
argv
[
1
],
count
);
int
len
=
sprintf_s
(
buffer
,
buffSize
,
"%s.%
zu
"
,
argv
[
1
],
count
);
PLUGIN_CHECK
(
len
>
0
,
return
-
1
,
"Invalid buffer"
);
buffer
[
len
]
=
'\0'
;
StartWatcher
(
buffer
);
...
...
@@ -298,11 +298,14 @@ static int32_t BShellParamCmdMemGet(BShellHandle shell, int32_t argc, char *argv
int
ret
=
sprintf_s
(
buff
,
buffSize
-
1
,
"/proc/%s/smaps"
,
argv
[
1
]);
PLUGIN_CHECK
(
ret
>
0
,
return
-
1
,
"Failed to format path %s"
,
argv
[
1
]);
buff
[
ret
]
=
'\0'
;
char
*
realPath
=
GetRealPath
(
buff
);
PLUGIN_CHECK
(
realPath
!=
NULL
,
return
-
1
,
"Failed to get real path"
);
int
all
=
0
;
if
(
argc
>
2
&&
strcmp
(
argv
[
2
],
"all"
)
==
0
)
{
// 2 2 max arg
all
=
1
;
}
FILE
*
fp
=
fopen
(
buff
,
"r"
);
FILE
*
fp
=
fopen
(
realPath
,
"r"
);
free
(
realPath
);
int
value
=
0
;
while
(
fp
!=
NULL
&&
buff
!=
NULL
&&
fgets
(
buff
,
buffSize
,
fp
)
!=
NULL
)
{
buff
[
buffSize
-
1
]
=
'\0'
;
...
...
test/moduletest/syspara_moduleTest.cpp
浏览文件 @
6d267dab
...
...
@@ -80,7 +80,7 @@ static void SetParameterTestFunc(const char *key, const char *value)
EXPECT_EQ
(
ret
,
strlen
(
nameGet
));
EXPECT_STREQ
(
key
,
nameGet
);
char
valueGet
[
PARAM_VALUE_LEN_MAX
]
=
{
0
};
ret
=
GetParameterValue
(
handle
,
valueGet
,
PARAM_VALUE_LEN_MAX
);
ret
=
GetParameterValue
(
handle
,
valueGet
,
PARAM_VALUE_LEN_MAX
);
EXPECT_EQ
(
ret
,
strlen
(
valueGet
));
EXPECT_STREQ
(
value
,
valueGet
);
EXPECT_NE
(
GetSystemCommitId
(),
0
);
...
...
test/unittest/param/param_stub.cpp
浏览文件 @
6d267dab
...
...
@@ -74,15 +74,15 @@ static const char *TestGetParamLabel(const char *paraName)
return
selinuxLabels
[
code
][
1
];
}
static
const
char
*
forbidReadParamName
[]
=
{
static
const
char
*
g_
forbidReadParamName
[]
=
{
"ohos.servicectrl."
,
// "test.permission.write",
};
static
int
TestReadParamCheck
(
const
char
*
paraName
)
{
// forbid to read ohos.servicectrl.
for
(
size_t
i
=
0
;
i
<
ARRAY_LENGTH
(
forbidReadParamName
);
i
++
)
{
if
(
strncmp
(
paraName
,
forbidReadParamName
[
i
],
strlen
(
forbidReadParamName
[
i
]))
==
0
)
{
for
(
size_t
i
=
0
;
i
<
ARRAY_LENGTH
(
g_
forbidReadParamName
);
i
++
)
{
if
(
strncmp
(
paraName
,
g_forbidReadParamName
[
i
],
strlen
(
g_
forbidReadParamName
[
i
]))
==
0
)
{
return
1
;
}
}
...
...
test/unittest/param/watcher_agent_unittest.cpp
浏览文件 @
6d267dab
...
...
@@ -112,11 +112,14 @@ public:
int
TestDelWatcher
()
{
size_t
index
=
1
;
int
ret
=
SystemWatchParameter
(
"test.permission.watcher.test3.1"
,
TestParameterChange
,
(
void
*
)
index
);
int
ret
=
SystemWatchParameter
(
"test.permission.watcher.test3.1"
,
TestParameterChange
,
reinterpret_cast
<
void
*>
(
index
));
EXPECT_EQ
(
ret
,
0
);
ret
=
SystemWatchParameter
(
"test.permission.watcher.test3.1*"
,
TestParameterChange
,
(
void
*
)
index
);
ret
=
SystemWatchParameter
(
"test.permission.watcher.test3.1*"
,
TestParameterChange
,
reinterpret_cast
<
void
*>
(
index
));
EXPECT_EQ
(
ret
,
0
);
ret
=
SystemWatchParameter
(
"test.permission.watcher.test3.2"
,
TestParameterChange
,
(
void
*
)
index
);
ret
=
SystemWatchParameter
(
"test.permission.watcher.test3.2"
,
TestParameterChange
,
reinterpret_cast
<
void
*>
(
index
));
EXPECT_EQ
(
ret
,
0
);
ret
=
SystemWatchParameter
(
"test.permission.watcher.test3.1"
,
nullptr
,
nullptr
);
EXPECT_EQ
(
ret
,
0
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录