提交 262f673f 编写于 作者: X xionglei6

fix: ondemand replace dynamic

Signed-off-by: Nxionglei6 <xionglei6@huawei.com>
上级 471fad5a
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
static int StartProcess(const char *name, const char *extArgv[], int extArgc) static int StartProcess(const char *name, const char *extArgv[], int extArgc)
{ {
if (name == NULL) { 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; return -1;
} }
int extraArg = 0; int extraArg = 0;
...@@ -79,7 +79,7 @@ static int StartProcess(const char *name, const char *extArgv[], int extArgc) ...@@ -79,7 +79,7 @@ static int StartProcess(const char *name, const char *extArgv[], int extArgc)
static int StopProcess(const char *serviceName) static int StopProcess(const char *serviceName)
{ {
if (serviceName == NULL) { 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; return -1;
} }
if (SystemSetParameter("ohos.ctl.stop", serviceName) != 0) { if (SystemSetParameter("ohos.ctl.stop", serviceName) != 0) {
...@@ -112,7 +112,7 @@ static int GetCurrentServiceStatus(const char *serviceName, ServiceStatus *statu ...@@ -112,7 +112,7 @@ static int GetCurrentServiceStatus(const char *serviceName, ServiceStatus *statu
static int RestartProcess(const char *serviceName, const char *extArgv[], int extArgc) static int RestartProcess(const char *serviceName, const char *extArgv[], int extArgc)
{ {
if (serviceName == NULL) { 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; return -1;
} }
ServiceStatus status = SERVICE_IDLE; ServiceStatus status = SERVICE_IDLE;
......
...@@ -48,11 +48,10 @@ extern "C" { ...@@ -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_CRITICAL 0x020 // critical, will reboot if it crash 4 times in 4 minutes
#define SERVICE_ATTR_DISABLED 0x040 // disabled #define SERVICE_ATTR_DISABLED 0x040 // disabled
#define SERVICE_ATTR_CONSOLE 0x080 // console #define SERVICE_ATTR_CONSOLE 0x080 // console
#define SERVICE_ATTR_DYNAMIC 0x100 // dynamic service #define SERVICE_ATTR_ONDEMAND 0x100 // ondemand, manage socket by init
#define SERVICE_ATTR_ONDEMAND 0x200 // ondemand, manage socket by init #define SERVICE_ATTR_TIMERSTART 0x200 // Mark a service will be started by timer
#define SERVICE_ATTR_TIMERSTART 0x400 // Mark a service will be started by timer #define SERVICE_ATTR_NEEDWAIT 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 0x800 // make service will enter sandbox
#define SERVICE_ATTR_SANDBOX 0x1000 // make service will enter sandbox
#define MAX_SERVICE_NAME 32 #define MAX_SERVICE_NAME 32
#define MAX_APL_NAME 32 #define MAX_APL_NAME 32
......
...@@ -54,7 +54,7 @@ Service *GetServiceByName(const char *servName); ...@@ -54,7 +54,7 @@ Service *GetServiceByName(const char *servName);
cJSON *GetArrayItem(const cJSON *fileRoot, int *arrSize, const char *arrName); cJSON *GetArrayItem(const cJSON *fileRoot, int *arrSize, const char *arrName);
int ParseOneService(const cJSON *curItem, Service *service); 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 StopServiceByName(const char *serviceName);
void StopAllServices(int flags, const char **exclude, int size, void StopAllServices(int flags, const char **exclude, int size,
int (*filter)(const Service *service, const char **exclude, int size)); int (*filter)(const Service *service, const char **exclude, int size));
......
...@@ -202,7 +202,7 @@ static void DoWait(const struct CmdArgs *ctx) ...@@ -202,7 +202,7 @@ static void DoWait(const struct CmdArgs *ctx)
static void DoStart(const struct CmdArgs *ctx) static void DoStart(const struct CmdArgs *ctx)
{ {
INIT_LOGV("DoStart %s", ctx->argv[0]); INIT_LOGV("DoStart %s", ctx->argv[0]);
StartServiceByName(ctx->argv[0], true); StartServiceByName(ctx->argv[0]);
} }
static void DoStop(const struct CmdArgs *ctx) static void DoStop(const struct CmdArgs *ctx)
...@@ -226,7 +226,7 @@ static void DoReset(const struct CmdArgs *ctx) ...@@ -226,7 +226,7 @@ static void DoReset(const struct CmdArgs *ctx)
return; return;
} }
} else { } else {
StartServiceByName(ctx->argv[0], false); StartServiceByName(ctx->argv[0]);
} }
return; return;
} }
......
...@@ -397,10 +397,9 @@ static int ExecRestartCmd(Service *service) ...@@ -397,10 +397,9 @@ static int ExecRestartCmd(Service *service)
return SERVICE_SUCCESS; return SERVICE_SUCCESS;
} }
static void PollSocketAfresh(Service *service) static void CheckServiceSocket(Service *service)
{ {
if (service->socketCfg == NULL) { if (service->socketCfg == NULL) {
INIT_LOGE("service %s socket config is NULL!", service->name);
return; return;
} }
ServiceSocket *tmpSock = service->socketCfg; ServiceSocket *tmpSock = service->socketCfg;
...@@ -468,7 +467,7 @@ void ServiceReap(Service *service) ...@@ -468,7 +467,7 @@ void ServiceReap(Service *service)
} }
// service no need to restart which socket managed by init until socket message detected // service no need to restart which socket managed by init until socket message detected
if (IsOnDemandService(service)) { if (IsOnDemandService(service)) {
PollSocketAfresh(service); CheckServiceSocket(service);
return; return;
} }
......
...@@ -598,25 +598,6 @@ static bool IsServiceInMainStrap(Service *curServ) ...@@ -598,25 +598,6 @@ static bool IsServiceInMainStrap(Service *curServ)
return false; 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) static int GetServiceOnDemand(const cJSON *curArrItem, Service *curServ)
{ {
cJSON *item = cJSON_GetObjectItem(curArrItem, "ondemand"); cJSON *item = cJSON_GetObjectItem(curArrItem, "ondemand");
...@@ -627,7 +608,7 @@ static int GetServiceOnDemand(const cJSON *curArrItem, Service *curServ) ...@@ -627,7 +608,7 @@ static int GetServiceOnDemand(const cJSON *curArrItem, Service *curServ)
INIT_ERROR_CHECK(cJSON_IsBool(item), return SERVICE_FAILURE, INIT_ERROR_CHECK(cJSON_IsBool(item), return SERVICE_FAILURE,
"Service : %s ondemand value only support bool.", curServ->name); "Service : %s ondemand value only support bool.", curServ->name);
INIT_INFO_CHECK(cJSON_IsTrue(item), return SERVICE_SUCCESS, 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) { if (curServ->attribute & SERVICE_ATTR_CRITICAL) {
INIT_LOGE("Service : %s is invalid which has both critical and ondemand attribute", curServ->name); INIT_LOGE("Service : %s is invalid which has both critical and ondemand attribute", curServ->name);
return SERVICE_FAILURE; return SERVICE_FAILURE;
...@@ -641,7 +622,7 @@ static int CheckServiceKeyName(const cJSON *curService) ...@@ -641,7 +622,7 @@ static int CheckServiceKeyName(const cJSON *curService)
{ {
char *cfgServiceKeyList[] = { char *cfgServiceKeyList[] = {
"name", "path", "uid", "gid", "once", "importance", "caps", "disabled", "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" "d-caps", "apl", "jobs", "start-mode", "end-mode", "cpucore", "secon", "sandbox"
}; };
INIT_CHECK_RETURN_VALUE(curService != NULL, SERVICE_FAILURE); INIT_CHECK_RETURN_VALUE(curService != NULL, SERVICE_FAILURE);
...@@ -847,8 +828,6 @@ int ParseOneService(const cJSON *curItem, Service *service) ...@@ -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); INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get sandbox for service %s", service->name);
ret = GetServiceCaps(curItem, service); ret = GetServiceCaps(curItem, service);
INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get caps for service %s", service->name); 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); ret = GetServiceOnDemand(curItem, service);
INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get ondemand flag for service %s", service->name); INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get ondemand flag for service %s", service->name);
ret = GetServiceMode(service, curItem); ret = GetServiceMode(service, curItem);
...@@ -945,7 +924,7 @@ static Service *GetServiceByExtServName(const char *fullServName) ...@@ -945,7 +924,7 @@ static Service *GetServiceByExtServName(const char *fullServName)
return service; return service;
} }
void StartServiceByName(const char *servName, bool checkDynamic) void StartServiceByName(const char *servName)
{ {
INIT_LOGE("StartServiceByName Service %s", servName); INIT_LOGE("StartServiceByName Service %s", servName);
Service *service = GetServiceByName(servName); Service *service = GetServiceByName(servName);
...@@ -954,11 +933,6 @@ void StartServiceByName(const char *servName, bool checkDynamic) ...@@ -954,11 +933,6 @@ void StartServiceByName(const char *servName, bool checkDynamic)
} }
INIT_ERROR_CHECK(service != NULL, return, "Cannot find service %s.", servName); 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) { if (ServiceStart(service) != SERVICE_SUCCESS) {
INIT_LOGE("Service %s start failed!", servName); INIT_LOGE("Service %s start failed!", servName);
} }
...@@ -1049,12 +1023,6 @@ void StartAllServices(int startMode) ...@@ -1049,12 +1023,6 @@ void StartAllServices(int startMode)
node = GetNextGroupNode(NODE_TYPE_SERVICES, node); node = GetNextGroupNode(NODE_TYPE_SERVICES, node);
continue; 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) { if (ServiceStart(service) != SERVICE_SUCCESS) {
INIT_LOGE("Service %s start failed!", service->name); INIT_LOGE("Service %s start failed!", service->name);
} }
......
...@@ -189,7 +189,7 @@ static void SendTriggerEvent(int type, const char *content, uint32_t contentLen) ...@@ -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) { } else if (strncmp(content, OHOS_SERVICE_CTRL_PREFIX, prefixSize) == 0) {
DoServiceCtrlTrigger(content + prefixSize, contentLen - prefixSize, 1); DoServiceCtrlTrigger(content + prefixSize, contentLen - prefixSize, 1);
} else if (strncmp(content, OHOS_CTRL_START, strlen(OHOS_CTRL_START)) == 0) { } 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) { } else if (strncmp(content, OHOS_CTRL_STOP, strlen(OHOS_CTRL_STOP)) == 0) {
StopServiceByName(content + strlen(OHOS_CTRL_STOP)); StopServiceByName(content + strlen(OHOS_CTRL_STOP));
} else { } else {
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef TEST_FUZZTEST_STARTDYNAMICPROCESS_FUZZER_H #ifndef TEST_FUZZTEST_STARTONDEMANDPROCESS_FUZZER_H
#define TEST_FUZZTEST_STARTDYNAMICPROCESS_FUZZER_H #define TEST_FUZZTEST_STARTONDEMANDPROCESS_FUZZER_H
#include "fuzz_utils.h" #include "fuzz_utils.h"
#define FUZZ_PROJECT_NAME "ServiceControlStart_fuzzer" #define FUZZ_PROJECT_NAME "ServiceControlStart_fuzzer"
#endif #endif
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef TEST_FUZZTEST_STOPDYNAMICPROCESS_FUZZER_H #ifndef TEST_FUZZTEST_STOPONDEMANDPROCESS_FUZZER_H
#define TEST_FUZZTEST_STOPDYNAMICPROCESS_FUZZER_H #define TEST_FUZZTEST_STOPONDEMANDPROCESS_FUZZER_H
#include "fuzz_utils.h" #include "fuzz_utils.h"
#define FUZZ_PROJECT_NAME "ServiceControlStop_fuzzer" #define FUZZ_PROJECT_NAME "ServiceControlStop_fuzzer"
#endif #endif
...@@ -957,7 +957,7 @@ HWTEST_F(StartupInitUTest, cmdJobTest_001, TestSize.Level0) ...@@ -957,7 +957,7 @@ HWTEST_F(StartupInitUTest, cmdJobTest_001, TestSize.Level0)
DoJob(nullptr); DoJob(nullptr);
DoJob("job name does not exist"); DoJob("job name does not exist");
ReleaseAllJobs(); ReleaseAllJobs();
StartServiceByName("service name does not exist", false); StartServiceByName("service name does not exist");
StopAllServices(0, nullptr, 0, nullptr); StopAllServices(0, nullptr, 0, nullptr);
ServiceReap(nullptr); ServiceReap(nullptr);
EXPECT_NE(0, ServiceStart(nullptr)); EXPECT_NE(0, ServiceStart(nullptr));
......
...@@ -335,7 +335,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestAddService2, TestSize.Level1) ...@@ -335,7 +335,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestAddService2, TestSize.Level1)
HWTEST_F(InitGroupManagerUnitTest, TestParseServiceCpucore, TestSize.Level1) HWTEST_F(InitGroupManagerUnitTest, TestParseServiceCpucore, TestSize.Level1)
{ {
const char *jsonStr = "{\"services\":{\"name\":\"test_service22\",\"path\":[\"/data/init_ut/test_service\"]," 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]}}"; "\"gid\":[\"root\"], \"cpucore\":[5, 2, 4, 1, 2, 0, 1]}}";
cJSON* jobItem = cJSON_Parse(jsonStr); cJSON* jobItem = cJSON_Parse(jsonStr);
ASSERT_NE(nullptr, jobItem); ASSERT_NE(nullptr, jobItem);
......
...@@ -48,7 +48,7 @@ public: ...@@ -48,7 +48,7 @@ public:
HWTEST_F(ServiceUnitTest, case01, TestSize.Level1) HWTEST_F(ServiceUnitTest, case01, TestSize.Level1)
{ {
const char *jsonStr = "{\"services\":{\"name\":\"test_service\",\"path\":[\"/data/init_ut/test_service\"]," 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\"]}}"; "\"gid\":[\"system\"]}}";
cJSON* jobItem = cJSON_Parse(jsonStr); cJSON* jobItem = cJSON_Parse(jsonStr);
ASSERT_NE(nullptr, jobItem); ASSERT_NE(nullptr, jobItem);
...@@ -70,7 +70,7 @@ HWTEST_F(ServiceUnitTest, case01, TestSize.Level1) ...@@ -70,7 +70,7 @@ HWTEST_F(ServiceUnitTest, case01, TestSize.Level1)
HWTEST_F(ServiceUnitTest, TestServiceStartAbnormal, TestSize.Level1) HWTEST_F(ServiceUnitTest, TestServiceStartAbnormal, TestSize.Level1)
{ {
const char *jsonStr = "{\"services\":{\"name\":\"test_service1\",\"path\":[\"/data/init_ut/test_service\"]," 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\"]}}"; "\"gid\":[\"system\"]}}";
cJSON* jobItem = cJSON_Parse(jsonStr); cJSON* jobItem = cJSON_Parse(jsonStr);
ASSERT_NE(nullptr, jobItem); ASSERT_NE(nullptr, jobItem);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册