Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
cce62d82
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看板
提交
cce62d82
编写于
12月 27, 2021
作者:
X
xionglei6
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add: configurable critical attribute
Signed-off-by:
N
xionglei6
<
xionglei6@huawei.com
>
上级
f5ed759c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
67 addition
and
13 deletion
+67
-13
services/init/include/init_service.h
services/init/include/init_service.h
+2
-0
services/init/init_common_service.c
services/init/init_common_service.c
+7
-12
services/init/init_service_manager.c
services/init/init_service_manager.c
+58
-1
未找到文件。
services/init/include/init_service.h
浏览文件 @
cce62d82
...
...
@@ -79,6 +79,8 @@ typedef struct {
int
pid
;
int
crashCnt
;
time_t
firstCrashTime
;
int
crashCount
;
int
crashTime
;
unsigned
int
attribute
;
int
importance
;
Perms
servPerm
;
...
...
services/init/init_common_service.c
浏览文件 @
cce62d82
...
...
@@ -47,14 +47,9 @@
#define TIOCSCTTY 0x540E
#endif
// 240 seconds, 4 minutes
static
const
int
CRASH_TIME_LIMIT
=
240
;
// maximum number of crashes within time CRASH_TIME_LIMIT for one service
static
const
int
CRASH_COUNT_LIMIT
=
4
;
// 240 seconds, 4 minutes
static
const
int
CRITICAL_CRASH_TIME_LIMIT
=
240
;
// maximum number of crashes within time CRITICAL_CRASH_TIME_LIMIT for one service
static
const
int
CRITICAL_CRASH_COUNT_LIMIT
=
4
;
static
const
int
DEFAULT_CRASH_TIME
=
240
;
// maximum number of crashes within time DEFAULT_CRASH_TIME for one service
static
const
int
DEFAULT_CRASH_COUNT
=
4
;
static
int
SetAllAmbientCapability
(
void
)
{
...
...
@@ -331,14 +326,14 @@ void ServiceReap(Service *service)
}
if
(
service
->
attribute
&
SERVICE_ATTR_CRITICAL
)
{
// critical
if
(
CalculateCrashTime
(
service
,
CRITICAL_CRASH_TIME_LIMIT
,
CRITICAL_CRASH_COUNT_LIMIT
)
==
false
)
{
if
(
CalculateCrashTime
(
service
,
service
->
crashTime
,
service
->
crashCount
)
==
false
)
{
INIT_LOGE
(
"Critical service
\"
%s
\"
crashed %d times, rebooting system"
,
service
->
name
,
CRITICAL_CRASH_COUNT_LIMIT
);
service
->
name
,
service
->
crashCount
);
ExecReboot
(
"reboot"
);
}
}
else
if
(
!
(
service
->
attribute
&
SERVICE_ATTR_NEED_RESTART
))
{
if
(
CalculateCrashTime
(
service
,
CRASH_TIME_LIMIT
,
CRASH_COUNT_LIMI
T
)
==
false
)
{
INIT_LOGE
(
"Service name=%s, crash %d times, no more start."
,
service
->
name
,
CRASH_COUNT_LIMI
T
);
if
(
CalculateCrashTime
(
service
,
DEFAULT_CRASH_TIME
,
DEFAULT_CRASH_COUN
T
)
==
false
)
{
INIT_LOGE
(
"Service name=%s, crash %d times, no more start."
,
service
->
name
,
DEFAULT_CRASH_COUN
T
);
return
;
}
}
...
...
services/init/init_service_manager.c
浏览文件 @
cce62d82
...
...
@@ -34,6 +34,10 @@
// All serivce processes that init will fork+exec.
static
ServiceSpace
g_serviceSpace
=
{
{
&
g_serviceSpace
.
services
,
&
g_serviceSpace
.
services
},
0
};
static
const
int
CRITICAL_DEFAULT_CRASH_TIME
=
20
;
// maximum number of crashes within time CRITICAL_DEFAULT_CRASH_TIME for one service
static
const
int
CRITICAL_DEFAULT_CRASH_COUNT
=
4
;
static
const
int
CRITICAL_CONFIG_ARRAY_LEN
=
3
;
#ifdef OHOS_SERVICE_DUMP
static
void
DumpServiceArgs
(
const
char
*
info
,
const
ServiceArgs
*
args
)
...
...
@@ -516,6 +520,59 @@ static int CheckServiceKeyName(const cJSON *curService)
return
SERVICE_SUCCESS
;
}
int
GetCritical
(
const
cJSON
*
curArrItem
,
Service
*
curServ
,
const
char
*
attrName
,
int
flag
)
{
int
criticalSize
=
0
;
curServ
->
crashCount
=
CRITICAL_DEFAULT_CRASH_COUNT
;
curServ
->
crashTime
=
CRITICAL_DEFAULT_CRASH_TIME
;
cJSON
*
arrItem
=
cJSON_GetObjectItem
(
curArrItem
,
attrName
);
if
(
arrItem
==
NULL
)
{
return
SERVICE_SUCCESS
;
}
if
(
cJSON_IsNumber
(
arrItem
))
{
return
GetServiceAttr
(
curArrItem
,
curServ
,
attrName
,
flag
,
NULL
);
}
else
if
(
cJSON_IsArray
(
arrItem
))
{
criticalSize
=
cJSON_GetArraySize
(
arrItem
);
cJSON
*
attrItem
=
cJSON_GetArrayItem
(
arrItem
,
0
);
// 0 : critical attribute index
if
(
attrItem
==
NULL
||
!
cJSON_IsNumber
(
attrItem
))
{
INIT_LOGE
(
"%s critical invalid"
,
curServ
->
name
);
return
SERVICE_FAILURE
;
}
int
attrValue
=
(
int
)
cJSON_GetNumberValue
(
attrItem
);
curServ
->
attribute
&=
~
flag
;
if
(
criticalSize
==
1
)
{
if
(
attrValue
==
1
)
{
curServ
->
attribute
|=
flag
;
}
}
else
if
(
criticalSize
==
CRITICAL_CONFIG_ARRAY_LEN
)
{
cJSON
*
crashCountItem
=
cJSON_GetArrayItem
(
arrItem
,
1
);
// 1 : critical crash count index
INIT_ERROR_CHECK
(
crashCountItem
!=
NULL
,
return
SERVICE_FAILURE
,
"%s critical invalid"
,
curServ
->
name
);
int
value
=
(
int
)
cJSON_GetNumberValue
(
crashCountItem
);
INIT_ERROR_CHECK
(
value
>
0
,
return
SERVICE_FAILURE
,
"%s critical crashc ount invalid"
,
curServ
->
name
);
curServ
->
crashCount
=
value
;
cJSON
*
crashTimeItem
=
cJSON_GetArrayItem
(
arrItem
,
2
);
// 2 : critical crash time index
INIT_ERROR_CHECK
(
crashTimeItem
!=
NULL
,
return
SERVICE_FAILURE
,
"%s critical invalid"
,
curServ
->
name
);
value
=
(
int
)
cJSON_GetNumberValue
(
crashTimeItem
);
INIT_ERROR_CHECK
(
value
>
0
,
return
SERVICE_FAILURE
,
"%s critical crash time invalid"
,
curServ
->
name
);
curServ
->
crashTime
=
value
;
if
(
attrValue
==
1
)
{
curServ
->
attribute
|=
flag
;
}
}
else
{
curServ
->
attribute
&=
~
flag
;
INIT_LOGE
(
"%s critical param invalid"
,
curServ
->
name
);
return
SERVICE_FAILURE
;
}
}
else
{
INIT_LOGE
(
"%s critical type error"
,
curServ
->
name
);
return
SERVICE_FAILURE
;
}
return
SERVICE_SUCCESS
;
}
int
ParseOneService
(
const
cJSON
*
curItem
,
Service
*
service
)
{
INIT_CHECK_RETURN_VALUE
(
curItem
!=
NULL
&&
service
!=
NULL
,
SERVICE_FAILURE
);
...
...
@@ -540,7 +597,7 @@ int ParseOneService(const cJSON *curItem, Service *service)
INIT_ERROR_CHECK
(
ret
==
0
,
return
SERVICE_FAILURE
,
"Failed to get once flag for service %s"
,
service
->
name
);
ret
=
GetServiceAttr
(
curItem
,
service
,
IMPORTANT_STR_IN_CFG
,
SERVICE_ATTR_IMPORTANT
,
SetImportantValue
);
INIT_ERROR_CHECK
(
ret
==
0
,
return
SERVICE_FAILURE
,
"Failed to get import flag for service %s"
,
service
->
name
);
ret
=
Get
ServiceAttr
(
curItem
,
service
,
CRITICAL_STR_IN_CFG
,
SERVICE_ATTR_CRITICAL
,
NUL
L
);
ret
=
Get
Critical
(
curItem
,
service
,
CRITICAL_STR_IN_CFG
,
SERVICE_ATTR_CRITICA
L
);
INIT_ERROR_CHECK
(
ret
==
0
,
return
SERVICE_FAILURE
,
"Failed to get critical flag for service %s"
,
service
->
name
);
ret
=
GetServiceAttr
(
curItem
,
service
,
DISABLED_STR_IN_CFG
,
SERVICE_ATTR_DISABLED
,
NULL
);
INIT_ERROR_CHECK
(
ret
==
0
,
return
SERVICE_FAILURE
,
"Failed to get disabled flag for service %s"
,
service
->
name
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录