Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
f3010462
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看板
提交
f3010462
编写于
9月 22, 2022
作者:
C
cheng_jinsong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init: code optimizing
Signed-off-by:
N
cheng_jinsong
<
chengjinsong2@huawei.com
>
上级
3e106f56
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
82 addition
and
31 deletion
+82
-31
interfaces/innerkits/init_module_engine/include/init_cmdexecutor.h
...s/innerkits/init_module_engine/include/init_cmdexecutor.h
+1
-0
services/init/init_common_cmds.c
services/init/init_common_cmds.c
+9
-4
services/init/lite/init_cmds.c
services/init/lite/init_cmds.c
+9
-1
services/init/standard/init_cmdexecutor.c
services/init/standard/init_cmdexecutor.c
+21
-3
watchdog/init_watchdog.c
watchdog/init_watchdog.c
+42
-23
未找到文件。
interfaces/innerkits/init_module_engine/include/init_cmdexecutor.h
浏览文件 @
f3010462
...
...
@@ -42,6 +42,7 @@ void PluginExecCmdByName(const char *name, const char *cmdContent);
void
PluginExecCmdByCmdIndex
(
int
index
,
const
char
*
cmdContent
);
int
PluginExecCmd
(
const
char
*
name
,
int
argc
,
const
char
**
argv
);
const
char
*
PluginGetCmdIndex
(
const
char
*
cmdStr
,
int
*
index
);
const
char
*
GetPluginCmdNameByIndex
(
int
index
);
int
AddCmdExecutor
(
const
char
*
cmdName
,
CmdExecutor
execCmd
);
...
...
services/init/init_common_cmds.c
浏览文件 @
f3010462
...
...
@@ -719,7 +719,7 @@ void DoCmdByName(const char *name, const char *cmdContent)
}
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
cmdTimer
.
endTime
);
long
long
diff
=
InitDiffTime
(
&
cmdTimer
);
INIT_LOGV
(
"
Command %s execute time %lld"
,
name
,
diff
);
INIT_LOGV
(
"
Execute command
\"
%s %s
\"
took %lld ms"
,
name
,
cmdContent
,
diff
/
1000
);
// 1000 is convert us to ms
}
void
DoCmdByIndex
(
int
index
,
const
char
*
cmdContent
)
...
...
@@ -731,20 +731,25 @@ void DoCmdByIndex(int index, const char *cmdContent)
INIT_TIMING_STAT
cmdTimer
;
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
cmdTimer
.
startTime
);
const
struct
CmdTable
*
commCmds
=
GetCommCmdTable
(
&
cmdCnt
);
const
char
*
cmdName
=
NULL
;
if
(
index
<
cmdCnt
)
{
cmdName
=
commCmds
[
index
].
name
;
ExecCmd
(
&
commCmds
[
index
],
cmdContent
);
INIT_LOGV
(
"Command: %s content: %s"
,
commCmds
[
index
].
name
,
cmdContent
);
}
else
{
int
number
=
0
;
const
struct
CmdTable
*
cmds
=
GetCmdTable
(
&
number
);
if
(
index
<
(
cmdCnt
+
number
))
{
cmdName
=
cmds
[
index
-
cmdCnt
].
name
;
ExecCmd
(
&
cmds
[
index
-
cmdCnt
],
cmdContent
);
INIT_LOGV
(
"Command: %s content: %s"
,
cmds
[
index
-
cmdCnt
].
name
,
cmdContent
);
}
else
{
PluginExecCmdByCmdIndex
(
index
,
cmdContent
);
cmdName
=
GetPluginCmdNameByIndex
(
index
);
if
(
cmdName
==
NULL
)
{
cmdName
=
"Unknown"
;
}
}
}
(
void
)
clock_gettime
(
CLOCK_MONOTONIC
,
&
cmdTimer
.
endTime
);
long
long
diff
=
InitDiffTime
(
&
cmdTimer
);
INIT_LOGV
(
"
Command execute time %lld"
,
diff
);
INIT_LOGV
(
"
Execute command
\"
%s %s
\"
took %lld ms"
,
cmdName
,
cmdContent
,
diff
/
1000
);
// 1000 is convert us to ms
}
services/init/lite/init_cmds.c
浏览文件 @
f3010462
...
...
@@ -122,14 +122,22 @@ const struct CmdTable *GetCmdTable(int *number)
void
PluginExecCmdByName
(
const
char
*
name
,
const
char
*
cmdContent
)
{
}
void
PluginExecCmdByCmdIndex
(
int
index
,
const
char
*
cmdContent
)
{
}
const
char
*
PluginGetCmdIndex
(
const
char
*
cmdStr
,
int
*
index
)
{
return
NULL
;
}
const
char
*
GetPluginCmdNameByIndex
(
int
index
)
{
return
NULL
;
}
int
SetFileCryptPolicy
(
const
char
*
dir
)
{
return
0
;
}
\ No newline at end of file
}
services/init/standard/init_cmdexecutor.c
浏览文件 @
f3010462
...
...
@@ -144,20 +144,38 @@ static int CompareCmdId(const HashNode *node, const void *key)
return
cmd
->
cmdId
-
*
(
int
*
)
key
;
}
void
PluginExecCmdByCmdIndex
(
int
index
,
const
char
*
cmdContent
)
static
PluginCmd
*
GetPluginCmdByIndex
(
int
index
)
{
int
hashCode
=
((
index
>>
16
)
&
0x0000ffff
)
-
1
;
// 16 left shift
int
cmdId
=
(
index
&
0x0000ffff
);
HashNode
*
node
=
OH_HashMapFind
(
GetGroupHashMap
(
NODE_TYPE_CMDS
),
hashCode
,
(
const
void
*
)
&
cmdId
,
CompareCmdId
);
if
(
node
==
NULL
)
{
return
;
return
NULL
;
}
InitGroupNode
*
groupNode
=
HASHMAP_ENTRY
(
node
,
InitGroupNode
,
hashNode
);
if
(
groupNode
==
NULL
||
groupNode
->
data
.
cmd
==
NULL
)
{
return
NULL
;
}
return
groupNode
->
data
.
cmd
;
}
const
char
*
GetPluginCmdNameByIndex
(
int
index
)
{
PluginCmd
*
cmd
=
GetPluginCmdByIndex
(
index
);
if
(
cmd
==
NULL
)
{
return
NULL
;
}
return
cmd
->
name
;
}
void
PluginExecCmdByCmdIndex
(
int
index
,
const
char
*
cmdContent
)
{
PluginCmd
*
cmd
=
GetPluginCmdByIndex
(
index
);
if
(
cmd
==
NULL
)
{
INIT_LOGW
(
"Cannot find plugin command with index %d"
,
index
);
return
;
}
PluginCmd
*
cmd
=
groupNode
->
data
.
cmd
;
INIT_LOGV
(
"Command: %s cmdContent: %s"
,
cmd
->
name
,
cmdContent
);
PluginExecCmd_
(
cmd
,
cmdContent
);
}
...
...
watchdog/init_watchdog.c
浏览文件 @
f3010462
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021
-2022
Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
...
...
@@ -40,28 +40,34 @@
#define PRETIMEOUT_GAP 5
#define PRETIMEOUT_DIV 2
static
void
WaitAtStartup
(
const
char
*
source
)
#define WATCHDOG_DEV "/dev/watchdog"
static
int
WaitForWatchDogDevice
(
void
)
{
unsigned
int
count
=
0
;
struct
stat
sourceInfo
;
const
unsigned
int
waitTime
=
500000
;
do
{
while
((
stat
(
WATCHDOG_DEV
,
&
sourceInfo
)
<
0
)
&&
(
errno
==
ENOENT
)
&&
(
count
<
WAIT_MAX_COUNT
))
{
usleep
(
waitTime
);
count
++
;
}
while
((
stat
(
source
,
&
sourceInfo
)
<
0
)
&&
(
errno
==
ENOENT
)
&&
(
count
<
WAIT_MAX_COUNT
));
}
if
(
count
==
WAIT_MAX_COUNT
)
{
INIT_LOGE
(
"wait for file:%s failed after %u seconds."
,
source
,
(
WAIT_MAX_COUNT
*
waitTime
)
/
CONVERSION_BASE
);
INIT_LOGE
(
"Wait for watchdog device failed after %u seconds"
,
(
WAIT_MAX_COUNT
*
waitTime
)
/
CONVERSION_BASE
);
return
0
;
}
return
;
return
1
;
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
WaitAtStartup
(
"/dev/watchdog"
);
int
fd
=
open
(
"/dev/watchdog"
,
O_RDWR
);
if
(
fd
==
-
1
)
{
INIT_LOGE
(
"Can't open /dev/watchdog."
);
return
1
;
if
(
WaitForWatchDogDevice
()
==
0
)
{
return
-
1
;
}
int
fd
=
open
(
WATCHDOG_DEV
,
O_RDWR
|
O_CLOEXEC
);
if
(
fd
<
0
)
{
INIT_LOGE
(
"Open watchdog device failed, err = %d"
,
errno
);
return
-
1
;
}
int
interval
=
0
;
...
...
@@ -76,11 +82,10 @@ int main(int argc, const char *argv[])
}
gap
=
(
gap
>
0
)
?
gap
:
DEFAULT_GAP
;
INIT_LOGI
(
"Watchdog started (interval %d, margin %d), fd = %d
\n
"
,
interval
,
gap
,
fd
);
#ifdef OHOS_LITE_WATCHDOG
#ifndef LINUX_WATCHDOG
if
(
setpriority
(
PRIO_PROCESS
,
0
,
14
)
!=
0
)
{
// 14 is process priority
INIT_LOGE
(
"setpriority failed
err=%d
\n
"
,
errno
);
INIT_LOGE
(
"setpriority failed
, err=%d
"
,
errno
);
}
#endif
#endif
...
...
@@ -93,12 +98,16 @@ int main(int argc, const char *argv[])
#endif
int
ret
=
ioctl
(
fd
,
WDIOC_SETTIMEOUT
,
&
timeoutSet
);
if
(
ret
)
{
INIT_LOGE
(
"Failed to set timeout to %d
\n
"
,
timeoutSet
);
if
(
ret
<
0
)
{
INIT_LOGE
(
"ioctl failed with command WDIOC_SETTIMEOUT, err = %d"
,
errno
);
close
(
fd
);
return
-
1
;
}
ret
=
ioctl
(
fd
,
WDIOC_GETTIMEOUT
,
&
timeoutGet
);
if
(
ret
)
{
INIT_LOGE
(
"Failed to get timeout
\n
"
);
if
(
ret
<
0
)
{
INIT_LOGE
(
"ioctl failed with command WDIOC_GETTIMEOUT, err = %d"
,
errno
);
close
(
fd
);
return
-
1
;
}
if
(
timeoutGet
>
0
)
{
...
...
@@ -106,15 +115,19 @@ int main(int argc, const char *argv[])
}
#ifdef WDIOC_SETPRETIMEOUT
preTimeout
=
timeoutGet
-
PRETIMEOUT_GAP
;
// ensure pretimeout smaller then timeout
preTimeout
=
timeoutGet
-
PRETIMEOUT_GAP
;
// ensure pre
timeout smaller then timeout
if
(
preTimeout
>
0
)
{
ret
=
ioctl
(
fd
,
WDIOC_SETPRETIMEOUT
,
&
preTimeout
);
if
(
ret
)
{
INIT_LOGE
(
"Failed to set pretimeout to %d
\n
"
,
preTimeout
);
if
(
ret
<
0
)
{
INIT_LOGE
(
"ioctl failed with command WDIOC_SETPRETIMEOUT, err = %d"
,
errno
);
close
(
fd
);
return
-
1
;
}
ret
=
ioctl
(
fd
,
WDIOC_GETPRETIMEOUT
,
&
preTimeoutGet
);
if
(
ret
)
{
INIT_LOGE
(
"Failed to get pretimeout
\n
"
);
if
(
ret
<
0
)
{
INIT_LOGE
(
"ioctl failed with command WDIOC_GETPRETIMEOUT, err = %d"
,
errno
);
close
(
fd
);
return
-
1
;
}
}
...
...
@@ -123,8 +136,14 @@ int main(int argc, const char *argv[])
}
#endif
INIT_LOGI
(
"watchdog started (interval %d, margin %d)"
,
interval
,
gap
);
while
(
1
)
{
ioctl
(
fd
,
WDIOC_KEEPALIVE
);
ret
=
ioctl
(
fd
,
WDIOC_KEEPALIVE
);
if
(
ret
<
0
)
{
// Fed watchdog failed, we don't need to quit the process.
// Wait for kernel to trigger panic.
INIT_LOGE
(
"ioctl failed with command WDIOC_KEEPALIVE, err = %d"
,
errno
);
}
sleep
(
interval
);
}
close
(
fd
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录