未验证 提交 8e511405 编写于 作者: O openharmony_ci 提交者: Gitee

!1805 启动sa进程前检查模块升级

Merge pull request !1805 from luding6/master
...@@ -51,6 +51,7 @@ extern "C" { ...@@ -51,6 +51,7 @@ extern "C" {
#define SERVICE_ATTR_WITHOUT_SANDBOX 0x800 // make service not enter sandbox #define SERVICE_ATTR_WITHOUT_SANDBOX 0x800 // make service not enter sandbox
#define SERVICE_ATTR_NOTIFY_STATE 0x1000 // service notify state #define SERVICE_ATTR_NOTIFY_STATE 0x1000 // service notify state
#define SERVICE_ATTR_MODULE_UPDATE 0x2000 // module update
#define MAX_SERVICE_NAME 32 #define MAX_SERVICE_NAME 32
#define MAX_APL_NAME 32 #define MAX_APL_NAME 32
......
...@@ -37,6 +37,7 @@ extern "C" { ...@@ -37,6 +37,7 @@ extern "C" {
#define D_CAPS_STR_IN_CFG "d-caps" #define D_CAPS_STR_IN_CFG "d-caps"
#define APL_STR_IN_CFG "apl" #define APL_STR_IN_CFG "apl"
#define CPU_CORE_STR_IN_CFG "cpucore" #define CPU_CORE_STR_IN_CFG "cpucore"
#define MODULE_UPDATE_STR_IN_CFG "module-update"
#define MAX_SERVICES_CNT_IN_FILE 100 #define MAX_SERVICES_CNT_IN_FILE 100
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include <dlfcn.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h> #include <signal.h>
...@@ -345,6 +346,22 @@ void EnterServiceSandbox(Service *service) ...@@ -345,6 +346,22 @@ void EnterServiceSandbox(Service *service)
#endif #endif
} }
void CheckModuleUpdate(int argc, char **argv)
{
INIT_LOGI("CheckModuleUpdate start");
void *handle = dlopen("libmodule_update.z.so", RTLD_NOW);
INIT_ERROR_CHECK(handle != NULL, return, "dlopen module update lib failed with error:%s", dlerror());
INIT_LOGI("dlopen success");
typedef void (*ExtFunc)(int, char **);
ExtFunc func = (ExtFunc)dlsym(handle, "CheckModuleUpdate");
if (func == NULL) {
INIT_LOGE("dlsym get func failed with error:%s", dlerror());
} else {
func(argc, argv);
}
INIT_LOGI("CheckModuleUpdate end");
}
int ServiceStart(Service *service) int ServiceStart(Service *service)
{ {
INIT_ERROR_CHECK(service != NULL, return SERVICE_FAILURE, "start service failed! null ptr."); INIT_ERROR_CHECK(service != NULL, return SERVICE_FAILURE, "start service failed! null ptr.");
...@@ -371,6 +388,9 @@ int ServiceStart(Service *service) ...@@ -371,6 +388,9 @@ int ServiceStart(Service *service)
#endif #endif
int pid = fork(); int pid = fork();
if (pid == 0) { if (pid == 0) {
if (service->attribute & SERVICE_ATTR_MODULE_UPDATE) {
CheckModuleUpdate(service->pathArgs.count, service->pathArgs.argv);
}
// fail must exit sub process // fail must exit sub process
INIT_ERROR_CHECK(InitServiceProperties(service) == 0, INIT_ERROR_CHECK(InitServiceProperties(service) == 0,
_exit(PROCESS_EXIT_CODE), "Failed init service property"); _exit(PROCESS_EXIT_CODE), "Failed init service property");
......
...@@ -850,6 +850,8 @@ int ParseOneService(const cJSON *curItem, Service *service) ...@@ -850,6 +850,8 @@ int ParseOneService(const cJSON *curItem, Service *service)
INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get console for service %s", service->name); INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get console for service %s", service->name);
ret = GetServiceAttr(curItem, service, "notify-state", SERVICE_ATTR_NOTIFY_STATE, NULL); ret = GetServiceAttr(curItem, service, "notify-state", SERVICE_ATTR_NOTIFY_STATE, NULL);
INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get notify-state for service %s", service->name); INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get notify-state for service %s", service->name);
ret = GetServiceAttr(curItem, service, MODULE_UPDATE_STR_IN_CFG, SERVICE_ATTR_MODULE_UPDATE, NULL);
INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get module-update for service %s", service->name);
ParseOneServiceArgs(curItem, service); ParseOneServiceArgs(curItem, service);
ret = GetServiceSandbox(curItem, service); ret = GetServiceSandbox(curItem, service);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册