add shut detector

Signed-off-by: mashuang <mashuang13@huawei.com>
This commit is contained in:
mashuang 2023-12-11 17:11:10 +08:00
parent 740822f492
commit 708d7a024d
5 changed files with 22 additions and 17 deletions

View File

@ -403,9 +403,9 @@ int MountOneItem(FstabItem *item)
}
}
int retry_count = 3;
int retryCount = 3;
int rc = 0;
while (retry_count-- > 0) {
while (retryCount-- > 0) {
rc = Mount(item->deviceName, item->mountPoint, item->fsType, mountFlags, fsSpecificData);
if (rc == 0) {
break;

View File

@ -47,8 +47,10 @@ enum INIT_BOOTSTAGE {
INIT_SERVICE_FORK_AFTER = 60,
INIT_SERVICE_BOOTEVENT = 61,
INIT_SERVICE_REAP = 65,
INIT_SHUT_DETECTOR = 66,
INIT_SERVICE_RESTART = 71,
INIT_JOB_PARSE = 70,
INIT_ENTER_LOOP = 80,
INIT_BOOT_COMPLETE = 100,
};

View File

@ -314,6 +314,7 @@ void SystemConfig(const char *uptime)
TriggerServices(START_MODE_BOOT);
PostTrigger(EVENT_TRIGGER_BOOT, "post-init", strlen("post-init"));
TriggerServices(START_MODE_NORMAL);
HookMgrExecute(GetBootStageHookMgr(), INIT_ENTER_LOOP, NULL, NULL);
clock_gettime(CLOCK_MONOTONIC, &(g_bootJob.startTime));
}

View File

@ -92,6 +92,18 @@ static int AddBootEventItemByName(const char *paramName)
return AddBootEventItem(item, paramName);
}
static void SetServiceBooteventHookMgr(const char *serviceName, const char *paramName, int state)
{
#ifndef STARTUP_INIT_TEST
SERVICE_BOOTEVENT_CTX context;
context.serviceName = serviceName;
context.reserved = paramName;
context.state = state;
HookMgrExecute(GetBootStageHookMgr(), INIT_SERVICE_BOOTEVENT, (void*)(&context), NULL);
#endif
}
static int AddServiceBootEvent(const char *serviceName, const char *paramName)
{
ServiceExtData *extData = NULL;
@ -120,6 +132,7 @@ static int AddServiceBootEvent(const char *serviceName, const char *paramName)
return -1;
}
SetServiceBooteventHookMgr(serviceName, paramName, 1);
return 0;
}
@ -232,17 +245,6 @@ static void ReportSysEvent(void)
return;
}
static void SetServiceBooteventHookMgr(const char *name, int state)
{
#ifndef STARTUP_INIT_TEST
SERVICE_BOOTEVENT_CTX context;
context.serviceName = name;
context.reserved = NULL;
context.state = state;
HookMgrExecute(GetBootStageHookMgr(), INIT_SERVICE_BOOTEVENT, (void*)(&context), NULL);
#endif
}
static void BootCompleteClearAll(void)
{
InitGroupNode *node = GetNextGroupNode(NODE_TYPE_SERVICES, NULL);
@ -303,7 +305,7 @@ static int BootEventParaFireByName(const char *paramName)
&(found->timestamp[BOOTEVENT_READY])) == 0, 0);
g_bootEventNum--;
SetServiceBooteventHookMgr(paramName, 2); // 2: bootevent service has ready
SetServiceBooteventHookMgr(NULL, paramName, 2); // 2: bootevent service has ready
// Check if all boot event params are fired
if (g_bootEventNum > 0) {
return 0;
@ -318,7 +320,6 @@ static int BootEventParaFireByName(const char *paramName)
#ifndef STARTUP_INIT_TEST
HookMgrExecute(GetBootStageHookMgr(), INIT_BOOT_COMPLETE, NULL, NULL);
#endif
AutorunModuleMgrUnInstall("init_bootDetector");
RemoveCmdExecutor("bootevent", -1);
return 1;
}
@ -343,7 +344,6 @@ static void ServiceParseBootEventHook(SERVICE_PARSE_CTX *serviceParseCtx)
INIT_LOGI("Add service bootEvent failed %s", serviceParseCtx->serviceName);
return;
}
SetServiceBooteventHookMgr(serviceParseCtx->serviceName, 1); // 1: bootevent service is starting
return;
}
@ -356,7 +356,6 @@ static void ServiceParseBootEventHook(SERVICE_PARSE_CTX *serviceParseCtx)
INIT_LOGI("Add service bootEvent failed %s", serviceParseCtx->serviceName);
continue;
}
SetServiceBooteventHookMgr(serviceParseCtx->serviceName, 1); // 1: bootevent service is starting
}
}

View File

@ -370,6 +370,9 @@ void DoJobExecNow(const char *triggerName)
PARAM_CHECK(triggerName != NULL, return, "Invalid param");
JobNode *trigger = GetTriggerByName(&g_triggerWorkSpace, triggerName);
if (trigger != NULL) {
if (strncmp(triggerName, "reboot", strlen("reboot")) == 0) {
HookMgrExecute(GetBootStageHookMgr(), INIT_SHUT_DETECTOR, NULL, NULL);
}
StartTriggerExecute_((TriggerNode *)trigger, NULL, 0);
}
}