How to Write Android init. RC (Android
Init LANGUAGE)
The android initialization language consists of four categories of statements: Actions, commands, services, and options ).
* The initialization language is in the unit of action and consists of language symbols separated by spaces. The C-style backslash escape character can be used to insert white space to the language symbol. Double quotation marks can also be used to prevent text from being divided into multiple language symbols by spaces. When the backslash is at the end of a row, it is used as a line break.
* Start with # (spaces are allowed before.
* Actions and services implicitly declare a new paragraph. The declaration of commands or options for all sections belongs to this section. Commands or options before the first paragraph are ignored.
* Actions and services have unique names. Classes with the same name declared after them will be treated as errors and ignored.
Actions
-------
Actions is the name of a series of commands. Actions has a trigger used to determine when an action is executed. When an action meets the trigger condition and is not added to the queue to be executed, it is added to the end of the queue.
The actions in the queue are executed in sequence, and the commands in the actions are also executed in sequence. Init processes other activities (device creation/destruction, Property setting, and process restart) in the execution of commands ).
Actions:
On <trigger>
<Command>
<Command>
<Command>
Services
--------
Services are started by init and restarted when they exit (optional ). Service Format:
Service <Name> <pathname>
[<Argument>] *
<Option>
<Option>
...
Options
-------
Options is the modification of services, which affects the time and how to run the service in init.
Critical
This is a device-critical service. If it exits more than four times in four minutes, the device restarts and enters the recovery mode.
Disabled
The service level will not be started automatically. It must be started according to the service name.
Setenv <Name> <value>
Set the value of the environment variable <Name> of the started Process <value>
Socket <Name> <type>
<Perm> [<user> [<group>]
Create a Unix domin socket named/dev/socket/<Name> and send its FD to the started process. <Type> the value must be "dgram" or "stream". The default value is 0 for users and groups.
User <username>
Change the user name before executing the service. The default value is root. If your process requires Linux capabilities, you cannot use this command. You must request the capacity when you are still the root user and drop it to the uid you need.
Group <groupname> [
<Groupname>] *
Change the group before executing the service. The group after the first group will be set as the process additional group (via setgroups (). The current default is root.
Oneshot
Do not restart after the service exits.
Class <Name>
Specify a category name for the service. All services with the same class name can be started or stopped together. If no category is specified, the default service type is "default.
Onrestart
Execute a command when the service is restarted.
Triggers
--------
Triggers is a string that can be used to match certain types of events and execute an action.
Boot
This is the first trigger executed after init starts (when/init. conf is loaded)
<Name >=< value>
Triggered when property <Name> is set to the specified value <value>.
Device-added-<path>
Device-removed-<path>
Triggered when a device node is added or removed.
Service-Exited-<Name>
Triggered when the specified service exists
Commands
--------
Exec <path> [<argument>
] *
Fork and execute a program (<path>). This will be blocked until the program is completed. It is best to avoid executing programs other than built-in commands, which may cause init to be blocked.
Export <Name> <value>
Set the value of the global environment variable <Name> <value>. All processes can obtain the value after the command is executed.
IFUP <interface>
Bring the network interface <interface> online.
Import <FILENAME>
Parse an init configuration file to expand the current configuration file.
Hostname <Name>
Set Host Name
Chmod <octal-mode> <path>
Change File Access Permissions
Chown <owner> <group>
<Path>
Change the file owner and group
Class_start <serviceclass>
When a service of the specified category is not running, start all services of the category.
Class_stop <serviceclass>
When a service of the specified category is running, stop all services of this category.
Domainname <Name>
Set the domain name.
Insmod <path>
Module for loading the path <path>
Mkdir <path> [mode] [owner]
[Group]
Create a directory in <path>. The optional options are mod, owner, and group. If this parameter is not specified, the directory is created with the 755 permission, the owner is root, and the group is root.
Mount <type> <device>
<Dir> [<mountoption>] *
Try to mount <device> to the directory <dir>. <device> You can specify an MTD block device by using the MTD @ name format. <Mountoption> contains "Ro", "RW", "remount", "noatime ".
Setkey
No
Setprop <Name> <value>
Set the value of system property <Name> <value>.
Setrlimit <resource> <cur>
<Max>
Set resource rlimit.
Start <service>
Start a service that is not running.
Stop <service>
Stop a running service.
Symlink <target> <path>
Create a <path> symbolic link to <target>
Sysclktz <mins_west_of_gmt>
Set the system time zone (GMT 0)
Trigger <event>
Trigger an event. Used to call other actions.
Write <path> <string> [
<String>] *
Open the <path> file and write one or more strings.
Properties
----------
Init updates some system properties to check what it is doing.
Init. Action
The action currently being executed. If not, it is ""
Init. Command
The command to be executed. If not, it is ""
Init. SVC. <Name>
The status of the service named <Name> ("STOPPED ",
"Running", "Restarting ")
Init. RC
Example:
-----------------
# Not complete -- just providing some
Examples of Usage
#
On Boot
Export path
/Sbin:/system/bin
Export LD_LIBRARY_PATH
/System/lib
Mkdir/dev
Mkdir/proc
Mkdir/sys
Mount tmpfs/dev
Mkdir/dev/PTS
Mkdir/dev/socket
Mount devpts
/Dev/PTS
Mount proc/proc
Mount sysfs/sys
Write
/Proc/CPU/alignment 4
IFUP Lo
Hostname localhost
Domainname localhost
Mount yaffs2 MTD @ system/System
Mount yaffs2 MTD @ userdata/Data
Import
/System/etc/init. conf
Class_start default
Service adbd/sbin/adbd
User ADB
Group ADB
Service usbd/system/bin/usbd-R
User usbd
Group usbd
Socket usbd 666
Service zygote
/System/bin/app_process-xzygote/system/bin -- zygote
Socket zygot 666
Service runtime/system/bin/Runtime
User System
GROUP SYSTEM
On device-added-/dev/compass
Start akmd
On device-removed-/dev/compass
Stop akmd
Service akmd/sbin/akmd
Disabled
User akmd
Group akmd
Debugging
---------------
By default, the output information and errors of the Program executed by init are/dev/null. To debug, you can run your program through the android program logwrapper. This will reset the output/error to the android logging system (accessed through logcat ).
For example
Service akmd/system/bin/logwrapper
/Sbin/akmd