Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
262f673f
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,发现更多精彩内容 >>
提交
262f673f
编写于
4月 01, 2022
作者:
X
xionglei6
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: ondemand replace dynamic
Signed-off-by:
N
xionglei6
<
xionglei6@huawei.com
>
上级
471fad5a
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
24 addition
and
58 deletion
+24
-58
interfaces/innerkits/service_control/service_control.c
interfaces/innerkits/service_control/service_control.c
+3
-3
services/init/include/init_service.h
services/init/include/init_service.h
+4
-5
services/init/include/init_service_manager.h
services/init/include/init_service_manager.h
+1
-1
services/init/init_common_cmds.c
services/init/init_common_cmds.c
+2
-2
services/init/init_common_service.c
services/init/init_common_service.c
+2
-3
services/init/init_service_manager.c
services/init/init_service_manager.c
+3
-35
services/param/trigger/trigger_processor.c
services/param/trigger/trigger_processor.c
+1
-1
test/fuzztest/test_startup_ServiceControlStart_fuzzer/test_startup_ServiceControlStart_fuzzer.h
...rolStart_fuzzer/test_startup_ServiceControlStart_fuzzer.h
+2
-2
test/fuzztest/test_startup_ServiceControlStop_fuzzer/test_startup_ServiceControlStop_fuzzer.h
...ntrolStop_fuzzer/test_startup_ServiceControlStop_fuzzer.h
+2
-2
test/unittest/common/cmd_func_test.cpp
test/unittest/common/cmd_func_test.cpp
+1
-1
test/unittest/init/group_unittest.cpp
test/unittest/init/group_unittest.cpp
+1
-1
test/unittest/init/service_unittest.cpp
test/unittest/init/service_unittest.cpp
+2
-2
未找到文件。
interfaces/innerkits/service_control/service_control.c
浏览文件 @
262f673f
...
...
@@ -28,7 +28,7 @@
static
int
StartProcess
(
const
char
*
name
,
const
char
*
extArgv
[],
int
extArgc
)
{
if
(
name
==
NULL
)
{
BEGET_LOGE
(
"Start
dynamic
service failed, service name is null."
);
BEGET_LOGE
(
"Start
ondemand
service failed, service name is null."
);
return
-
1
;
}
int
extraArg
=
0
;
...
...
@@ -79,7 +79,7 @@ static int StartProcess(const char *name, const char *extArgv[], int extArgc)
static
int
StopProcess
(
const
char
*
serviceName
)
{
if
(
serviceName
==
NULL
)
{
BEGET_LOGE
(
"Stop
dynamic
service failed, service is null.
\n
"
);
BEGET_LOGE
(
"Stop
ondemand
service failed, service is null.
\n
"
);
return
-
1
;
}
if
(
SystemSetParameter
(
"ohos.ctl.stop"
,
serviceName
)
!=
0
)
{
...
...
@@ -112,7 +112,7 @@ static int GetCurrentServiceStatus(const char *serviceName, ServiceStatus *statu
static
int
RestartProcess
(
const
char
*
serviceName
,
const
char
*
extArgv
[],
int
extArgc
)
{
if
(
serviceName
==
NULL
)
{
BEGET_LOGE
(
"Restart
dynamic
service failed, service is null.
\n
"
);
BEGET_LOGE
(
"Restart
ondemand
service failed, service is null.
\n
"
);
return
-
1
;
}
ServiceStatus
status
=
SERVICE_IDLE
;
...
...
services/init/include/init_service.h
浏览文件 @
262f673f
...
...
@@ -48,11 +48,10 @@ extern "C" {
#define SERVICE_ATTR_CRITICAL 0x020 // critical, will reboot if it crash 4 times in 4 minutes
#define SERVICE_ATTR_DISABLED 0x040 // disabled
#define SERVICE_ATTR_CONSOLE 0x080 // console
#define SERVICE_ATTR_DYNAMIC 0x100 // dynamic service
#define SERVICE_ATTR_ONDEMAND 0x200 // ondemand, manage socket by init
#define SERVICE_ATTR_TIMERSTART 0x400 // Mark a service will be started by timer
#define SERVICE_ATTR_NEEDWAIT 0x800 // Mark a service will be started by timer
#define SERVICE_ATTR_SANDBOX 0x1000 // make service will enter sandbox
#define SERVICE_ATTR_ONDEMAND 0x100 // ondemand, manage socket by init
#define SERVICE_ATTR_TIMERSTART 0x200 // Mark a service will be started by timer
#define SERVICE_ATTR_NEEDWAIT 0x400 // Mark a service will be started by timer
#define SERVICE_ATTR_SANDBOX 0x800 // make service will enter sandbox
#define MAX_SERVICE_NAME 32
#define MAX_APL_NAME 32
...
...
services/init/include/init_service_manager.h
浏览文件 @
262f673f
...
...
@@ -54,7 +54,7 @@ Service *GetServiceByName(const char *servName);
cJSON
*
GetArrayItem
(
const
cJSON
*
fileRoot
,
int
*
arrSize
,
const
char
*
arrName
);
int
ParseOneService
(
const
cJSON
*
curItem
,
Service
*
service
);
void
StartServiceByName
(
const
char
*
serviceName
,
bool
checkDynamic
);
void
StartServiceByName
(
const
char
*
serviceName
);
void
StopServiceByName
(
const
char
*
serviceName
);
void
StopAllServices
(
int
flags
,
const
char
**
exclude
,
int
size
,
int
(
*
filter
)(
const
Service
*
service
,
const
char
**
exclude
,
int
size
));
...
...
services/init/init_common_cmds.c
浏览文件 @
262f673f
...
...
@@ -202,7 +202,7 @@ static void DoWait(const struct CmdArgs *ctx)
static
void
DoStart
(
const
struct
CmdArgs
*
ctx
)
{
INIT_LOGV
(
"DoStart %s"
,
ctx
->
argv
[
0
]);
StartServiceByName
(
ctx
->
argv
[
0
]
,
true
);
StartServiceByName
(
ctx
->
argv
[
0
]);
}
static
void
DoStop
(
const
struct
CmdArgs
*
ctx
)
...
...
@@ -226,7 +226,7 @@ static void DoReset(const struct CmdArgs *ctx)
return
;
}
}
else
{
StartServiceByName
(
ctx
->
argv
[
0
]
,
false
);
StartServiceByName
(
ctx
->
argv
[
0
]);
}
return
;
}
...
...
services/init/init_common_service.c
浏览文件 @
262f673f
...
...
@@ -397,10 +397,9 @@ static int ExecRestartCmd(Service *service)
return
SERVICE_SUCCESS
;
}
static
void
PollSocketAfresh
(
Service
*
service
)
static
void
CheckServiceSocket
(
Service
*
service
)
{
if
(
service
->
socketCfg
==
NULL
)
{
INIT_LOGE
(
"service %s socket config is NULL!"
,
service
->
name
);
return
;
}
ServiceSocket
*
tmpSock
=
service
->
socketCfg
;
...
...
@@ -468,7 +467,7 @@ void ServiceReap(Service *service)
}
// service no need to restart which socket managed by init until socket message detected
if
(
IsOnDemandService
(
service
))
{
PollSocketAfresh
(
service
);
CheckServiceSocket
(
service
);
return
;
}
...
...
services/init/init_service_manager.c
浏览文件 @
262f673f
...
...
@@ -598,25 +598,6 @@ static bool IsServiceInMainStrap(Service *curServ)
return
false
;
}
static
int
GetDynamicService
(
const
cJSON
*
curArrItem
,
Service
*
curServ
)
{
cJSON
*
item
=
cJSON_GetObjectItem
(
curArrItem
,
"dynamic"
);
if
(
item
==
NULL
)
{
return
SERVICE_SUCCESS
;
}
INIT_ERROR_CHECK
(
cJSON_IsBool
(
item
),
return
SERVICE_FAILURE
,
"Service : %s dynamic value only support bool."
,
curServ
->
name
);
INIT_INFO_CHECK
(
cJSON_IsTrue
(
item
),
return
SERVICE_SUCCESS
,
"Service : %s dynamic value is false, it will be started with init."
,
curServ
->
name
);
INIT_CHECK_RETURN_VALUE
(
!
IsServiceInMainStrap
(
curServ
),
SERVICE_SUCCESS
);
INIT_LOGI
(
"%s is dynamic service"
,
curServ
->
name
);
curServ
->
attribute
|=
SERVICE_ATTR_DYNAMIC
;
curServ
->
attribute
|=
SERVICE_ATTR_ONCE
;
return
SERVICE_SUCCESS
;
}
static
int
GetServiceOnDemand
(
const
cJSON
*
curArrItem
,
Service
*
curServ
)
{
cJSON
*
item
=
cJSON_GetObjectItem
(
curArrItem
,
"ondemand"
);
...
...
@@ -627,7 +608,7 @@ static int GetServiceOnDemand(const cJSON *curArrItem, Service *curServ)
INIT_ERROR_CHECK
(
cJSON_IsBool
(
item
),
return
SERVICE_FAILURE
,
"Service : %s ondemand value only support bool."
,
curServ
->
name
);
INIT_INFO_CHECK
(
cJSON_IsTrue
(
item
),
return
SERVICE_SUCCESS
,
"Service : %s ondemand value is false, it
will be manage socket by itself
"
,
curServ
->
name
);
"Service : %s ondemand value is false, it
should be pulled up by init
"
,
curServ
->
name
);
if
(
curServ
->
attribute
&
SERVICE_ATTR_CRITICAL
)
{
INIT_LOGE
(
"Service : %s is invalid which has both critical and ondemand attribute"
,
curServ
->
name
);
return
SERVICE_FAILURE
;
...
...
@@ -641,7 +622,7 @@ static int CheckServiceKeyName(const cJSON *curService)
{
char
*
cfgServiceKeyList
[]
=
{
"name"
,
"path"
,
"uid"
,
"gid"
,
"once"
,
"importance"
,
"caps"
,
"disabled"
,
"writepid"
,
"critical"
,
"socket"
,
"console"
,
"
dynamic"
,
"
file"
,
"ondemand"
,
"writepid"
,
"critical"
,
"socket"
,
"console"
,
"file"
,
"ondemand"
,
"d-caps"
,
"apl"
,
"jobs"
,
"start-mode"
,
"end-mode"
,
"cpucore"
,
"secon"
,
"sandbox"
};
INIT_CHECK_RETURN_VALUE
(
curService
!=
NULL
,
SERVICE_FAILURE
);
...
...
@@ -847,8 +828,6 @@ int ParseOneService(const cJSON *curItem, Service *service)
INIT_ERROR_CHECK
(
ret
==
0
,
return
SERVICE_FAILURE
,
"Failed to get sandbox for service %s"
,
service
->
name
);
ret
=
GetServiceCaps
(
curItem
,
service
);
INIT_ERROR_CHECK
(
ret
==
0
,
return
SERVICE_FAILURE
,
"Failed to get caps for service %s"
,
service
->
name
);
ret
=
GetDynamicService
(
curItem
,
service
);
INIT_ERROR_CHECK
(
ret
==
0
,
return
SERVICE_FAILURE
,
"Failed to get dynamic flag for service %s"
,
service
->
name
);
ret
=
GetServiceOnDemand
(
curItem
,
service
);
INIT_ERROR_CHECK
(
ret
==
0
,
return
SERVICE_FAILURE
,
"Failed to get ondemand flag for service %s"
,
service
->
name
);
ret
=
GetServiceMode
(
service
,
curItem
);
...
...
@@ -945,7 +924,7 @@ static Service *GetServiceByExtServName(const char *fullServName)
return
service
;
}
void
StartServiceByName
(
const
char
*
servName
,
bool
checkDynamic
)
void
StartServiceByName
(
const
char
*
servName
)
{
INIT_LOGE
(
"StartServiceByName Service %s"
,
servName
);
Service
*
service
=
GetServiceByName
(
servName
);
...
...
@@ -954,11 +933,6 @@ void StartServiceByName(const char *servName, bool checkDynamic)
}
INIT_ERROR_CHECK
(
service
!=
NULL
,
return
,
"Cannot find service %s."
,
servName
);
if
(
checkDynamic
&&
(
service
->
attribute
&
SERVICE_ATTR_DYNAMIC
))
{
INIT_LOGI
(
"%s is dynamic service."
,
servName
);
NotifyServiceChange
(
service
,
SERVICE_STOPPED
);
return
;
}
if
(
ServiceStart
(
service
)
!=
SERVICE_SUCCESS
)
{
INIT_LOGE
(
"Service %s start failed!"
,
servName
);
}
...
...
@@ -1049,12 +1023,6 @@ void StartAllServices(int startMode)
node
=
GetNextGroupNode
(
NODE_TYPE_SERVICES
,
node
);
continue
;
}
if
(
service
->
attribute
&
SERVICE_ATTR_DYNAMIC
)
{
INIT_LOGI
(
"%s is dynamic service."
,
service
->
name
);
NotifyServiceChange
(
service
,
SERVICE_STOPPED
);
node
=
GetNextGroupNode
(
NODE_TYPE_SERVICES
,
node
);
continue
;
}
if
(
ServiceStart
(
service
)
!=
SERVICE_SUCCESS
)
{
INIT_LOGE
(
"Service %s start failed!"
,
service
->
name
);
}
...
...
services/param/trigger/trigger_processor.c
浏览文件 @
262f673f
...
...
@@ -189,7 +189,7 @@ static void SendTriggerEvent(int type, const char *content, uint32_t contentLen)
}
else
if
(
strncmp
(
content
,
OHOS_SERVICE_CTRL_PREFIX
,
prefixSize
)
==
0
)
{
DoServiceCtrlTrigger
(
content
+
prefixSize
,
contentLen
-
prefixSize
,
1
);
}
else
if
(
strncmp
(
content
,
OHOS_CTRL_START
,
strlen
(
OHOS_CTRL_START
))
==
0
)
{
StartServiceByName
(
content
+
strlen
(
OHOS_CTRL_START
)
,
false
);
StartServiceByName
(
content
+
strlen
(
OHOS_CTRL_START
));
}
else
if
(
strncmp
(
content
,
OHOS_CTRL_STOP
,
strlen
(
OHOS_CTRL_STOP
))
==
0
)
{
StopServiceByName
(
content
+
strlen
(
OHOS_CTRL_STOP
));
}
else
{
...
...
test/fuzztest/test_startup_ServiceControlStart_fuzzer/test_startup_ServiceControlStart_fuzzer.h
浏览文件 @
262f673f
...
...
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef TEST_FUZZTEST_START
DYNAMIC
PROCESS_FUZZER_H
#define TEST_FUZZTEST_START
DYNAMIC
PROCESS_FUZZER_H
#ifndef TEST_FUZZTEST_START
ONDEMAND
PROCESS_FUZZER_H
#define TEST_FUZZTEST_START
ONDEMAND
PROCESS_FUZZER_H
#include "fuzz_utils.h"
#define FUZZ_PROJECT_NAME "ServiceControlStart_fuzzer"
#endif
test/fuzztest/test_startup_ServiceControlStop_fuzzer/test_startup_ServiceControlStop_fuzzer.h
浏览文件 @
262f673f
...
...
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef TEST_FUZZTEST_STOP
DYNAMIC
PROCESS_FUZZER_H
#define TEST_FUZZTEST_STOP
DYNAMIC
PROCESS_FUZZER_H
#ifndef TEST_FUZZTEST_STOP
ONDEMAND
PROCESS_FUZZER_H
#define TEST_FUZZTEST_STOP
ONDEMAND
PROCESS_FUZZER_H
#include "fuzz_utils.h"
#define FUZZ_PROJECT_NAME "ServiceControlStop_fuzzer"
#endif
test/unittest/common/cmd_func_test.cpp
浏览文件 @
262f673f
...
...
@@ -957,7 +957,7 @@ HWTEST_F(StartupInitUTest, cmdJobTest_001, TestSize.Level0)
DoJob
(
nullptr
);
DoJob
(
"job name does not exist"
);
ReleaseAllJobs
();
StartServiceByName
(
"service name does not exist"
,
false
);
StartServiceByName
(
"service name does not exist"
);
StopAllServices
(
0
,
nullptr
,
0
,
nullptr
);
ServiceReap
(
nullptr
);
EXPECT_NE
(
0
,
ServiceStart
(
nullptr
));
...
...
test/unittest/init/group_unittest.cpp
浏览文件 @
262f673f
...
...
@@ -335,7 +335,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestAddService2, TestSize.Level1)
HWTEST_F
(
InitGroupManagerUnitTest
,
TestParseServiceCpucore
,
TestSize
.
Level1
)
{
const
char
*
jsonStr
=
"{
\"
services
\"
:{
\"
name
\"
:
\"
test_service22
\"
,
\"
path
\"
:[
\"
/data/init_ut/test_service
\"
],"
"
\"
importance
\"
:-20,
\"
uid
\"
:
\"
root
\"
,
\"
writepid
\"
:[
\"
/dev/test_service
\"
],
\"
console
\"
:1,
\"
dynamic
\"
:true,
"
"
\"
importance
\"
:-20,
\"
uid
\"
:
\"
root
\"
,
\"
writepid
\"
:[
\"
/dev/test_service
\"
],
\"
console
\"
:1,"
"
\"
gid
\"
:[
\"
root
\"
],
\"
cpucore
\"
:[5, 2, 4, 1, 2, 0, 1]}}"
;
cJSON
*
jobItem
=
cJSON_Parse
(
jsonStr
);
ASSERT_NE
(
nullptr
,
jobItem
);
...
...
test/unittest/init/service_unittest.cpp
浏览文件 @
262f673f
...
...
@@ -48,7 +48,7 @@ public:
HWTEST_F
(
ServiceUnitTest
,
case01
,
TestSize
.
Level1
)
{
const
char
*
jsonStr
=
"{
\"
services
\"
:{
\"
name
\"
:
\"
test_service
\"
,
\"
path
\"
:[
\"
/data/init_ut/test_service
\"
],"
"
\"
importance
\"
:-20,
\"
uid
\"
:
\"
system
\"
,
\"
writepid
\"
:[
\"
/dev/test_service
\"
],
\"
console
\"
:1,
\"
dynamic
\"
:true,
"
"
\"
importance
\"
:-20,
\"
uid
\"
:
\"
system
\"
,
\"
writepid
\"
:[
\"
/dev/test_service
\"
],
\"
console
\"
:1,"
"
\"
gid
\"
:[
\"
system
\"
]}}"
;
cJSON
*
jobItem
=
cJSON_Parse
(
jsonStr
);
ASSERT_NE
(
nullptr
,
jobItem
);
...
...
@@ -70,7 +70,7 @@ HWTEST_F(ServiceUnitTest, case01, TestSize.Level1)
HWTEST_F
(
ServiceUnitTest
,
TestServiceStartAbnormal
,
TestSize
.
Level1
)
{
const
char
*
jsonStr
=
"{
\"
services
\"
:{
\"
name
\"
:
\"
test_service1
\"
,
\"
path
\"
:[
\"
/data/init_ut/test_service
\"
],"
"
\"
importance
\"
:-20,
\"
uid
\"
:
\"
system
\"
,
\"
writepid
\"
:[
\"
/dev/test_service
\"
],
\"
console
\"
:1,
\"
dynamic
\"
:true,
"
"
\"
importance
\"
:-20,
\"
uid
\"
:
\"
system
\"
,
\"
writepid
\"
:[
\"
/dev/test_service
\"
],
\"
console
\"
:1,"
"
\"
gid
\"
:[
\"
system
\"
]}}"
;
cJSON
*
jobItem
=
cJSON_Parse
(
jsonStr
);
ASSERT_NE
(
nullptr
,
jobItem
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录