mirror of
https://github.com/openharmony/startup_init_lite.git
synced 2026-07-19 17:07:55 -04:00
feat: Rename initstage to initsync, and apply the module in the init process.
1.Rename initstage to initsync 2.Apply the module in the init process to synchronize the init process with the application process Close #I3RCUF Change-Id: Ibd384485aef411d4d638f0717d2877dbd79a3502
This commit is contained in:
@@ -13,24 +13,26 @@
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
lite_component("initstage") {
|
||||
features = [ "//base/startup/init_lite/initstage:libinitstage_shared" ]
|
||||
lite_component("initsync") {
|
||||
features = [ "//base/startup/init_lite/initsync:libinitsync_shared" ]
|
||||
}
|
||||
|
||||
shared_library("libinitstage_shared") {
|
||||
sources = [ "src/init_stage.c" ]
|
||||
shared_library("libinitsync_shared") {
|
||||
sources = [ "src/init_sync.c" ]
|
||||
cflags = [ "-Wall" ]
|
||||
include_dirs = [
|
||||
"//base/startup/init_lite/initstage/include",
|
||||
"//base/startup/init_lite/initsync/include",
|
||||
"//base/startup/init_lite/interfaces/kits",
|
||||
]
|
||||
public_deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
|
||||
}
|
||||
|
||||
static_library("libinitstage_static") {
|
||||
sources = [ "src/init_stage.c" ]
|
||||
static_library("libinitsync_static") {
|
||||
sources = [ "src/init_sync.c" ]
|
||||
cflags = [ "-Wall" ]
|
||||
include_dirs = [
|
||||
"//base/startup/init_lite/initstage/include",
|
||||
"//base/startup/init_lite/initsync/include",
|
||||
"//base/startup/init_lite/interfaces/kits",
|
||||
]
|
||||
public_deps = [ "//third_party/bounds_checking_function:libsec_static" ]
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
#ifndef BASE_STARTUP_INITLITE_STAGE_H
|
||||
#define BASE_STARTUP_INITLITE_STAGE_H
|
||||
|
||||
#include "init_sync.h"
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -33,21 +34,19 @@ typedef enum {
|
||||
} QuickstartStage;
|
||||
|
||||
typedef enum {
|
||||
QS_UNREGISTER = QS_STAGE_LIMIT, /* quickstart dev unregister */
|
||||
QS_NOTIFY, /* quickstart notify */
|
||||
QS_LISTEN, /* quickstart listen */
|
||||
QS_NOTIFY = QS_STAGE_LIMIT, /* quickstart notify */
|
||||
QS_LISTEN, /* quickstart listen */
|
||||
QS_CTL_LIMIT
|
||||
} QuickstartConctrl;
|
||||
|
||||
typedef struct {
|
||||
unsigned int pid;
|
||||
unsigned int events;
|
||||
} QuickstartMask;
|
||||
unsigned int wait;
|
||||
} QuickstartListenArgs;
|
||||
|
||||
#define QUICKSTART_IOC_MAGIC 'T'
|
||||
#define QUICKSTART_UNREGISTER _IO(QUICKSTART_IOC_MAGIC, QS_UNREGISTER)
|
||||
#define QUICKSTART_NOTIFY _IO(QUICKSTART_IOC_MAGIC, QS_NOTIFY)
|
||||
#define QUICKSTART_LISTEN _IOR(QUICKSTART_IOC_MAGIC, QS_LISTEN, QuickstartMask)
|
||||
#define QUICKSTART_LISTEN _IOR(QUICKSTART_IOC_MAGIC, QS_LISTEN, QuickstartListenArgs)
|
||||
#define QUICKSTART_STAGE(x) _IO(QUICKSTART_IOC_MAGIC, (x))
|
||||
|
||||
#define QUICKSTART_NODE "/dev/quickstart"
|
||||
@@ -67,9 +66,8 @@ typedef struct {
|
||||
* Listen the events of a specific pid process by Init process.
|
||||
* Only be called by Init process.
|
||||
* eventMask: There needs to be a consensus between the listener and the notifier.
|
||||
|
||||
*/
|
||||
extern int InitListen(pid_t pid, unsigned short eventMask);
|
||||
extern int InitListen(unsigned long eventMask, unsigned int wait);
|
||||
|
||||
/*
|
||||
* Trigger the SystemInit stage.
|
||||
@@ -83,6 +81,11 @@ extern int SystemInitStage(QuickstartStage stage);
|
||||
*/
|
||||
extern int InitStageFinished(void);
|
||||
|
||||
/*
|
||||
* Listen event and trigger the SystemInit stage.
|
||||
* Only be called by Init process.
|
||||
*/
|
||||
extern void TriggerStage(unsigned int event, unsigned int wait, QuickstartStage stagelevel);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
@@ -30,24 +30,24 @@ static int SendCmd(int cmd, unsigned long arg)
|
||||
if (fd != -1) {
|
||||
int ret = ioctl(fd, cmd, arg);
|
||||
if (ret == -1) {
|
||||
printf("[%s][%d]Err: %s!\n", __FUNCTION__, __LINE__, strerror(errno));
|
||||
printf("[ERR][%s,%d] %s!\n", __FUNCTION__, __LINE__, strerror(errno));
|
||||
}
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
printf("[%s][%d]Err: %s!\n", __FUNCTION__, __LINE__, strerror(errno));
|
||||
printf("[ERR][%s,%d] %s!\n", __FUNCTION__, __LINE__, strerror(errno));
|
||||
return fd;
|
||||
}
|
||||
|
||||
int InitListen(pid_t pid, unsigned short eventMask)
|
||||
int InitListen(unsigned long eventMask, unsigned int wait)
|
||||
{
|
||||
QuickstartMask listenMask;
|
||||
listenMask.pid = pid;
|
||||
listenMask.events = eventMask;
|
||||
return SendCmd(QUICKSTART_LISTEN, (unsigned long)&listenMask);
|
||||
QuickstartListenArgs args;
|
||||
args.wait = wait;
|
||||
args.events = eventMask;
|
||||
return SendCmd(QUICKSTART_LISTEN, (unsigned long)&args);
|
||||
}
|
||||
|
||||
int NotifyInit(unsigned short event)
|
||||
int NotifyInit(unsigned long event)
|
||||
{
|
||||
return SendCmd(QUICKSTART_NOTIFY, event);
|
||||
}
|
||||
@@ -55,13 +55,21 @@ int NotifyInit(unsigned short event)
|
||||
int SystemInitStage(QuickstartStage stage)
|
||||
{
|
||||
if (stage >= QS_STAGE_LIMIT || stage < QS_STAGE1) {
|
||||
printf("[%s][%d]Err: the stage(%d) is Not expected!!\n", __FUNCTION__, __LINE__, stage);
|
||||
printf("[ERR][%s,%d] the stage(%d) is not expected!\n", __FUNCTION__, __LINE__, stage);
|
||||
return -1;
|
||||
}
|
||||
return SendCmd(QUICKSTART_STAGE(stage), 0);
|
||||
}
|
||||
|
||||
void TriggerStage(unsigned int event, unsigned int wait, QuickstartStage stagelevel)
|
||||
{
|
||||
int ret = InitListen(event, wait);
|
||||
if (ret != 0 && ret != -1) {
|
||||
SystemInitStage(stagelevel);
|
||||
}
|
||||
}
|
||||
|
||||
int InitStageFinished(void)
|
||||
{
|
||||
return SendCmd(QUICKSTART_UNREGISTER, 0);
|
||||
return unlink(QUICKSTART_NODE);
|
||||
}
|
||||
@@ -22,12 +22,23 @@ extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define EVENT1 0xf
|
||||
#define EVENT1_WAITTIME 10000 // 10s = 10*1000 * 1 tick(1ms)
|
||||
|
||||
#define EVENT2 0xf0
|
||||
/* Define EVENT2_WAITTIME 0 means QS_STAGE2 is no used */
|
||||
#define EVENT2_WAITTIME 0
|
||||
|
||||
#define EVENT3 0xf00
|
||||
/* Define EVENT3_WAITTIME 0 means QS_STAGE3 is no used */
|
||||
#define EVENT3_WAITTIME 0
|
||||
|
||||
/*
|
||||
* Notify the event to Init process.
|
||||
* All processes can call. Usually called by the listened process.
|
||||
* event: There needs to be a consensus between the listener(init process) and the notifier.
|
||||
*/
|
||||
extern int NotifyInit(unsigned short event);
|
||||
extern int NotifyInit(unsigned long event);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
+7
-1
@@ -40,12 +40,18 @@ if (defined(ohos_lite)) {
|
||||
|
||||
deps = [
|
||||
"//base/startup/syspara_lite/frameworks/parameter:parameter",
|
||||
"//base/startup/init_lite/initsync:initsync",
|
||||
"//build/lite/config/component/cJSON:cjson_shared",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
]
|
||||
ldflags = []
|
||||
if (ohos_kernel_type == "liteos_a") {
|
||||
include_dirs += [ "//kernel/liteos_a/syscall" ]
|
||||
include_dirs += [
|
||||
"//kernel/liteos_a/syscall",
|
||||
"//base/startup/init_lite/interfaces/kits",
|
||||
"//base/startup/init_lite/initsync/include",
|
||||
]
|
||||
deps += [ "//base/startup/init_lite/initsync:initsync" ]
|
||||
}
|
||||
if (ohos_kernel_type == "linux") {
|
||||
defines += [ "NEED_EXEC_RCS_LINUX" ]
|
||||
|
||||
@@ -27,7 +27,9 @@
|
||||
#include "init_perms.h"
|
||||
#include "init_service_manager.h"
|
||||
#include "securec.h"
|
||||
|
||||
#ifndef __LINUX__
|
||||
#include "init_stage.h"
|
||||
#endif
|
||||
|
||||
static const long MAX_JSON_FILE_LEN = 102400; // max init.cfg size 100KB
|
||||
static const int MAX_PATH_ARGS_CNT = 20; // max path and args count
|
||||
@@ -350,8 +352,21 @@ void InitReadCfg()
|
||||
|
||||
// do jobs
|
||||
DoJob("pre-init");
|
||||
#ifndef __LINUX__
|
||||
TriggerStage(EVENT1, EVENT1_WAITTIME, QS_STAGE1);
|
||||
#endif
|
||||
|
||||
DoJob("init");
|
||||
#ifndef __LINUX__
|
||||
TriggerStage(EVENT2, EVENT2_WAITTIME, QS_STAGE2);
|
||||
#endif
|
||||
|
||||
DoJob("post-init");
|
||||
#ifndef __LINUX__
|
||||
TriggerStage(EVENT3, EVENT3_WAITTIME, QS_STAGE3);
|
||||
|
||||
InitStageFinished();
|
||||
#endif
|
||||
ReleaseAllJobs();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user