5f9449b1b2
Merge pull request !2737 from 钟柠/0419_socket |
||
---|---|---|
.gitee | ||
device_info | ||
figures | ||
initsync | ||
interfaces | ||
scripts | ||
services | ||
simulator | ||
test | ||
ueventd | ||
watchdog | ||
begetd.gni | ||
bundle.json | ||
CODEOWNERS | ||
LICENSE | ||
OAT.xml | ||
README_zh.md | ||
README.md |
init
Introduction
The init module starts system service processes from the time the kernel loads the first user-space process to the time the first application is started. In addition to loading key system processes, the module needs to configure their permissions during the startup and keep the specified process alive after sub-processes are started. If a process exits abnormally, the module needs to restart it, and to perform system reset for a special process.
Directory Structure
base/startup/init/ # init module
├── LICENSE
└── services
├── include # Header files for the init module
├── src # Source files for the init module
└── test # Source files of the test cases for the init module
└── unittest
vendor
└──huawei
└──camera
└──init_configs # init configuration files (in JSON format, and deployed in /etc/init.cfg after image burning)
Constraints
Currently, the init module applies only to small-system devices reference memory ≥ 1 MB
, for example, Hi3516D V300 and Hi3518E V300.
Usage
init divides the system startup into three phases:
pre-init: operations required before system services are started, for example, mounting a file system, creating a folder, and modifying permissions
init: operations required for starting system services.
post-init: operations required after system services are started.
In the init.cfg file, each of the preceding phases is represented by a job, which corresponds to a command set. The init_lite module initializes the system by executing the commands in each job in sequence. Jobs are executed in the following sequence: pre-init > init > post-init. All jobs are stored in the jobs array in the init.cfg file.
In addition to the jobs array, the init.cfg file also provides a services array, which is used to store the names, executable file paths, permissions, and other attribute information of the key system services that need to be started by the init process.
The file is stored in /vendor/hisilicon/hispark_aries/init_configs/ under /etc/. It is in JSON format, and its size cannot exceed 100 KB.
The format and content of the init.cfg file are as follows:
{
"jobs" : [{
"name" : "pre-init",
"cmds" : [
"mkdir /testdir",
"chmod 0700 /testdir",
"chown 99 99 /testdir",
"mkdir /testdir2",
"mount vfat /dev/mmcblk0p0 /testdir2 noexec nosuid"
]
}, {
"name" : "init",
"cmds" : [
"start service1",
"start service2"
]
}, {
"name" : "post-init",
"cmds" : []
}
],
"services" : [{
"name" : "service1",
"path" : "/bin/process1",
"uid" : 1,
"gid" : 1,
"secon" : "u:r:untrusted_app:s0",
"once" : 0,
"importance" : 1,
"caps" : [0, 1, 2, 5]
}, {
"name" : "service2",
"path" : "/bin/process2",
"uid" : 2,
"gid" : 2,
"secon" : "u:r:untrusted_app:s0",
"once" : 1,
"importance" : 0,
"caps" : []
}
]
}
Table 1 Job description
A single job can hold a maximum of 30 commands only **start**, **mkdir**, **chmod**, **chown**, **mount**, and **loadcfg** are supported currently
. The command name and parameters 128 bytes or less
must be separated by only one space.
Table 2 Commands supported by a job
Table 3 Elements in the services array
Repositories Involved
[startup_init_lite]