diff --git a/interfaces/innerkits/service_control/service_control.c b/interfaces/innerkits/service_control/service_control.c index 1a8396f6ae1f99d7f933d25e6244f984e6ba41a2..6b232b7db6e8ef51940dbe905ed2b706e214e16e 100644 --- a/interfaces/innerkits/service_control/service_control.c +++ b/interfaces/innerkits/service_control/service_control.c @@ -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; diff --git a/services/init/include/init_service.h b/services/init/include/init_service.h index 6472c0e3dd890ee4343b33217fc515274ed4a75c..6d588506431754fdd9904435d1ab4956b1f20d4c 100644 --- a/services/init/include/init_service.h +++ b/services/init/include/init_service.h @@ -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 diff --git a/services/init/include/init_service_manager.h b/services/init/include/init_service_manager.h index 19e868aeaa128e28162d2e72796b0f8500c16bb2..35080b1d64f40dc188babc2318411ce006fc6956 100644 --- a/services/init/include/init_service_manager.h +++ b/services/init/include/init_service_manager.h @@ -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)); diff --git a/services/init/init_common_cmds.c b/services/init/init_common_cmds.c index 2c0ea15542a38f891fc3885b71cf817a9d6b6b91..bb69fe877977e0284563d0b589efcc4b395a6809 100644 --- a/services/init/init_common_cmds.c +++ b/services/init/init_common_cmds.c @@ -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; } diff --git a/services/init/init_common_service.c b/services/init/init_common_service.c index b49b0f96ca1423a8122b7b4a94d277442bf18598..ae028b723e8765e514e8c08572e7206aafdc2551 100644 --- a/services/init/init_common_service.c +++ b/services/init/init_common_service.c @@ -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; } diff --git a/services/init/init_service_manager.c b/services/init/init_service_manager.c index ae758e125b2e970a2c5031f0b3208b227f3973c7..b0be5f31b4de313c36ccfc59916fd1f233ba2038 100644 --- a/services/init/init_service_manager.c +++ b/services/init/init_service_manager.c @@ -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); } diff --git a/services/param/trigger/trigger_processor.c b/services/param/trigger/trigger_processor.c index 44d8cac57f876da135b4e30c11d4cd280b431ee9..7af1adaebcb53bbc129b9ad055eb10d7c5b28b12 100644 --- a/services/param/trigger/trigger_processor.c +++ b/services/param/trigger/trigger_processor.c @@ -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 { diff --git a/test/fuzztest/test_startup_ServiceControlStart_fuzzer/test_startup_ServiceControlStart_fuzzer.h b/test/fuzztest/test_startup_ServiceControlStart_fuzzer/test_startup_ServiceControlStart_fuzzer.h index 5e0c6c64f1fffb2290795c87080e2e93c098bf32..1194742a7cb09eeaefddc1793776db0f3be1e572 100644 --- a/test/fuzztest/test_startup_ServiceControlStart_fuzzer/test_startup_ServiceControlStart_fuzzer.h +++ b/test/fuzztest/test_startup_ServiceControlStart_fuzzer/test_startup_ServiceControlStart_fuzzer.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef TEST_FUZZTEST_STARTDYNAMICPROCESS_FUZZER_H -#define TEST_FUZZTEST_STARTDYNAMICPROCESS_FUZZER_H +#ifndef TEST_FUZZTEST_STARTONDEMANDPROCESS_FUZZER_H +#define TEST_FUZZTEST_STARTONDEMANDPROCESS_FUZZER_H #include "fuzz_utils.h" #define FUZZ_PROJECT_NAME "ServiceControlStart_fuzzer" #endif diff --git a/test/fuzztest/test_startup_ServiceControlStop_fuzzer/test_startup_ServiceControlStop_fuzzer.h b/test/fuzztest/test_startup_ServiceControlStop_fuzzer/test_startup_ServiceControlStop_fuzzer.h index ee79e68b57068a0b48332858e57a7de0d4b0fb2f..2b666b200c60be8f2204ab0f28c4d9bc0a6708e7 100644 --- a/test/fuzztest/test_startup_ServiceControlStop_fuzzer/test_startup_ServiceControlStop_fuzzer.h +++ b/test/fuzztest/test_startup_ServiceControlStop_fuzzer/test_startup_ServiceControlStop_fuzzer.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef TEST_FUZZTEST_STOPDYNAMICPROCESS_FUZZER_H -#define TEST_FUZZTEST_STOPDYNAMICPROCESS_FUZZER_H +#ifndef TEST_FUZZTEST_STOPONDEMANDPROCESS_FUZZER_H +#define TEST_FUZZTEST_STOPONDEMANDPROCESS_FUZZER_H #include "fuzz_utils.h" #define FUZZ_PROJECT_NAME "ServiceControlStop_fuzzer" #endif diff --git a/test/unittest/common/cmd_func_test.cpp b/test/unittest/common/cmd_func_test.cpp index 75255e8997572602ddd6d4037e454709cfd5199e..71148222a3822f154ca3be3fe115307075307082 100644 --- a/test/unittest/common/cmd_func_test.cpp +++ b/test/unittest/common/cmd_func_test.cpp @@ -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)); diff --git a/test/unittest/init/group_unittest.cpp b/test/unittest/init/group_unittest.cpp index f60898613a4708a4f51dde9a6f42aeffcec2c95c..a6f0a1f7afdd1647b4423f579816972191f1911f 100644 --- a/test/unittest/init/group_unittest.cpp +++ b/test/unittest/init/group_unittest.cpp @@ -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); diff --git a/test/unittest/init/service_unittest.cpp b/test/unittest/init/service_unittest.cpp index d6ee85f471ddbbff79493d4ef3bc3e12ec6f4828..df6d09ea2e875c287bfbfcb9e02843241b42e5c4 100644 --- a/test/unittest/init/service_unittest.cpp +++ b/test/unittest/init/service_unittest.cpp @@ -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);