Mid init. RC syntax analysis
By yww
For the most primitive init. RC tutorial, see system/CORE/init/readme.txt In the android source code directory.
The init language in Android consists of four types of statements. As follows:
· ActionN: Action
· Commands
· Services
· Options
The syntax structure is as follows:
Each statement occupies one row and each keyword is separated by spaces. The backslash (for example, \ n) in the C Specification will be ignored (backslash escapes) and is considered as a space. Double quotation marks are used to ensure that spaces do not divide a text string into multiple keywords. The backslash at the end of the row is used as a continuation.
· All rows starting from # (with spaces allowed) are comments)
· The beginning of an actions or services implicitly declares a new segment. All commands or options are recent declarations. Commands or options before the first segment are ignored.
· Each actions and services has different names. If the name follows the same name as the previous one, the latter name will be ignored or considered as an error.
Take the Statement Analysis in init. RC as an example to explain the four statements respectively.
1. Actions
Actions is composed of a series of commands, and a trigger is used to indicate
When some commands are executed. If an event matches the trigger condition of the action, the action will be added to the end of the pre-execution Queue (unless it is already in the queue ). The syntax format of actions is as follows:
On <trigger>
<Command>
<Command>
Eg:
# Adbd on at boot in emulator
On Property: Ro. kernel. qemu = 1
Start adbd
Here, the trigger categories are as follows:
Triggers
--------
Triggers are strings which can be used to match certain kinds of events and used to cause an action to occur.
U boot
This is the first trigger that will occur when init starts (after/init. conf is loaded)
U <name >=< value>
Triggers of this form occur when the property <Name> is set to the specific value <value>.
U device-added-<path>
U device-removed-<path>
Triggers of these forms occur when a device node is added or removed.
U service-Exited-<Name>
Triggers of this form occur when the specified service exits.
2. Services
Services is an existing initialization Startup Program. The syntax format is as follows:
Service <Name> <pathname> [<argument>] *
<Option>
<Option>
Eg:
# Adbd is controlled by the persist. Service. ADB. Enable System Property
Service adbd/sbin/adbd
Disabled
3. Options
Options is the modifier of the service, used to tell the INIT process when and how to run the service.
U critical
This is a device-critical service. If it exits more than four times in four minutes, the device will reboot into recovery mode.
U disabled
This service will not automatically start with its class. It must be explicitly started by name.
U setenv <Name> <value>
Set the environment variable <Name> to <value> In the launched process.
U socket <Name> <type> <perm> [<user> [<group>]
Create a Unix domain socket named/dev/socket/<Name> and pass its FD to the launched process. <type> must be "dgram", "stream" or "seqpacket ". user and group default to 0.
U user <username>
Change to username before exec 'ing this service. Currently defaults to root .(??? Probably shoshould default to nobody) Currently, if your process requires Linux capabilities then you cannot use this command. you must instead request the capabilities in-process while still root, and then drop to your desired uid.
U group <groupname> [<groupname>] *
Change to groupname before exec 'ing this service. additional groupnames beyond the (required) First one are used to set the supplemental groups of the process (via setgroups ()). currently defaults to root. (??? Probably shoshould default to nobody)
U oneshot
Do not restart the service when it exits.
U class <Name>
Specify a class name for the service. All services in a named class may be started or stopped together. A service is in the class "default" if one is not specified via the class option.
U onrestart
Execute a command (see below) when service restarts.
4. Commands
U exec <path> [<argument>] *
Fork and execute a program (<path> ). this will block until the program completes execution. it is best to avoid Exec as unlike the builtin commands, it runs the risk of getting init "stuck ". (??? Maybe there shocould be a timeout ?)
U export <Name> <value>
Set the environment variable <Name> equal to <value> In the Global Environment (which will be inherited by all processes started after this command is executed)
U ifup <interface>
Bring the network interface <interface> online.
U import <FILENAME>
Parse an init config file, extending the current configuration.
U hostname <Name>
Set the host name.
U chdir <directory>
Change working directory.
U chmod <octal-mode> <path>
Change file access permissions.
U chown <owner> <group> <path>
Change file owner and group.
U chroot <directory>
Change process root directory.
U class_start <serviceclass>
Start all services of the specified class if they are not already running.
U class_stop <serviceclass>
Stop all services of the specified class if they are currently running.
U domainname <Name>
Set the domain name.
U insmod <path>
Install the module at <path>
U mkdir <path> [mode] [owner] [group]
Create a directory at <path>, optionally with the given mode, owner, and group. If not provided, the directory is created with permissions 755 and owned by the root user and root group.
U Mount <type> <device> <dir> [<mountoption>] *
Attempt to mount the named device at the directory <dir> <device> may be of the form MTD @ name to specify a MTD block device by name. <mountoption> S include "Ro", "RW", "remount", "noatime ",...
U setkey
TBD
U setprop <Name> <value>
Set system property <Name> to <value>.
U setrlimit <resource> <cur> <max>
Set the rlimit for a resource.
U start <service>
Start a service running if it is not already running.
U stop <service>
Stop a service from running if it is currently running.
U symlink <target> <path>
Create a symbolic link at <path> with the value <target>
U sysclktz <mins_west_of_gmt>
Set the system clock base (0 if system clock ticks in GMT)
U trigger <event>
Trigger an event. Used to queue an action from another action.
U write <path> <string> [<string>] *
Open the file at <path> and write one or more strings to it with write (2)