• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cerrno>
17 #include "bootstage.h"
18 #include "init_log.h"
19 #include "init_module_engine.h"
20 
HandleModuleUpdate(void)21 static void HandleModuleUpdate(void)
22 {
23     pid_t pid = fork();
24     if (pid < 0) {
25         INIT_LOGE("HandleModuleUpdate, fork fail.");
26     } else if (pid == 0) {
27         INIT_LOGI("HandleModuleUpdate, exec chekc_module_update.");
28         int ret = execv("/system/bin/check_module_update_init", nullptr);
29         if (ret != 0) {
30             INIT_LOGE("exec error, ret = [%d], err = [%s].", ret, strerror(errno));
31         }
32         _exit(0);
33     }
34 }
35 
CheckModuleUpdate(const HOOK_INFO * hookInfo,void * ctx)36 static int CheckModuleUpdate(const HOOK_INFO *hookInfo, void *ctx)
37 {
38     INIT_LOGI("check_module_update start.");
39     static bool isExecuted = false;
40     if (isExecuted) {
41         INIT_LOGI("check_module_update has been executed.");
42         return 0;
43     }
44     isExecuted = true;
45     HandleModuleUpdate();
46     return 0;
47 }
48 
InitBootCompleted(const HOOK_INFO * hookInfo,void * ctx)49 static int InitBootCompleted(const HOOK_INFO *hookInfo, void *ctx)
50 {
51     INIT_LOGI("boot completed, uninstall module_update_init.");
52     AutorunModuleMgrUnInstall("module_update_init");
53     return 0;
54 }
55 
MODULE_CONSTRUCTOR(void)56 MODULE_CONSTRUCTOR(void)
57 {
58     INIT_LOGI("module_update_init add hookMgr.");
59     HookMgrAdd(GetBootStageHookMgr(), INIT_MOUNT_STAGE, 0, CheckModuleUpdate);
60     HookMgrAdd(GetBootStageHookMgr(), INIT_BOOT_COMPLETE, 0, InitBootCompleted);
61 }
62 
MODULE_DESTRUCTOR(void)63 MODULE_DESTRUCTOR(void)
64 {
65     INIT_LOGI("module_update_init destroy.");
66     HookMgrDel(GetBootStageHookMgr(), INIT_MOUNT_STAGE, CheckModuleUpdate);
67     HookMgrDel(GetBootStageHookMgr(), INIT_BOOT_COMPLETE, InitBootCompleted);
68 }
69