Android init.rc parsing "Go"

Source: Internet
Author: User
Tags unix domain socket

Transferred from: http://www.linuxidc.com/Linux/2014-10/108438.htm

This article is mainly from $android_source/system/init/readme.txt translation.

1 description

The Android init.rc file is parsed by the first INIT program launched by the system, which consists of statements consisting of four types of statements: Action,commands,services, Options. In a init.rc file, a statement usually occupies a row. The words are separated by a space character. If you need to use spaces within a word, you have to use the escape characters "\" If there is a backslash at the end of a line, then a newline collapse symbol, Should be combined with the next line to deal with, this is mainly to avoid a line of characters too long, and the meaning of the C language is consistent. The comment starts with the # sign. Action and services explicitly declare a block of statements, while commands and options belong to the most recently declared block of statements. The commands and options before the first statement block are ignored.

Some key words need to be understood before they can be explained in detail.

2 Key Words

Token: A word in computer language that is almost a concept of a word in English.

Section: A block of statements that is equivalent to a block in curly braces in the C language. A section of a section that begins with service or on. A section that starts with a service is called an action.

Services: Service.

Action: Actions

Commands: Command.

Options: Option.

Trigger: Trigger, or trigger condition.

Class: Generic, that is, you can specify the same generic genus for multiple service, which makes it easy to start or stop the operation at the same time.

How to compile ramdisk.img into the kernel and modify init.rc http://www.linuxidc.com/Linux/2013-07/87026.htm

Android init process init.rc init.*.rc http://www.linuxidc.com/Linux/2013-01/77884.htm

Android: Start the service permissions issue in Init.rc http://www.linuxidc.com/Linux/2011-04/35014.htm

Android Analytics init.rc Http://www.linuxidc.com/Linux/2011-02/32762.htm

Android Boot script init.rc http://www.linuxidc.com/Linux/2010-09/28637.htm

3 Statement parsing
3.1 Actions (Action)
An action represents a set of commands (commands). The action consists of a trigger that determines when the action is performed. When the trigger's condition is met, the action is added to the end of the queue that has been executed. If this action already exists in the queue, it will not execute.

Commands that are included in an action are executed sequentially. The syntax for the action is as follows:

On <trigger>
<command>
<command>
<command>

3.2 Service (services)
A service is a program that needs to be restarted automatically when the system initializes or exits.

Its syntax structure is as follows:

Service <name> <pathname> [<argument>]*
<option>
<option>
...

3.3 Choices (options)
option is used to modify the service. They affect how and when to run the service.

Options Describe
Critical If the service is restarted 4 times in 4 minutes, the device will reboot into restore mode, according to the critical service associated with the device.
Disabled The service does not run automatically and must be started explicitly through the server.
Setenv <name> <value> Setting environment variables
Sockets <name> <type> <perm> [<user> [<group>]] Create a UNIX domain socket under/dev/socket/and pass the created file descriptor FD to the service process. Where type must be Dgram or Stream,seqpacket. The user name and group name default to 0
User <username> Switch the user name before executing this service. The current default is root.
Group <groupname> [<groupname>]* Similar to user, switch group name
OneShot Does not restart automatically when this service exits.
Class <name> Assign a generic to the service so that it is convenient to start or stop multiple services at the same time. Default.
Onrestart Executes an instruction when the service is restarted,

3.4 Trigger (Trigger)
Triggers are used to describe a trigger condition that can be performed when the trigger condition is met.

Trigger Describe
Boot triggered when the INIT program executes and loads the/init.conf file.
<name>=<value> triggered when the value of the property name corresponds to the specified value.
Device-added-<path> Triggered when a device is added.
Device-removed-<path> Triggered when the device is removed.
Service-exited-<name> Triggered when the specified service exits.

3.5 Command (commands)

Command Describe
exec <path> [<argument>]* Executes the program under the specified path and passes the parameters.
Export <name> <value> Sets the Global environment parameter, which is set to be valid for all processes.
Ifup <interface> Makes the specified network interface "on-line", quite activates the specified network interface
Import <filename> Import an additional init configuration file.
Hostname <name> Set host name
ChDir <directory> Change the working directory.
chmod <octal-mode> <path> Changes the Read permission for the specified file.
Chown <owner> <group> <path> Changes the properties of the owning and group names of the specified file.
Chroot <directory> Change the root directory to be carried out.
Class_start <serviceclass> Starts all services for the specified class, and does not restart if the service is already started.
Class_stop <serviceclass> Stop the service of the specified generic.
DomainName <name> Set the domain name
Insmod <path> Installs the module to the specified path.
mkdir <path> [mode] [owner] [group] Creates a directory with the specified parameters and, by default, creates a directory Read permission of 755. The user name is root and the group name is root.
Mount <type> <device> <dir> [<mountoption>]* Mount instructions similar to Linux
Setkey TBD (to be determined), TBD.
SetProp <name> <value> Set properties and their corresponding values.
Setrlimit <resource> <cur> <max> Set the resource Rlimit (resource limit), do not understand Baidu a bit rlimit
Start <service> If the specified service is not started, it is started.
Stop <service> If the specified service is currently running, stop it.
Symlink <target> <path> Creates a symbolic link.
Sysclktz <mins_west_of_gmt> Sets the system base time.
Trigger <event> Trigger an event. Used to queue a action from another action. The words did not understand, looking for expert guidance.
Write <path> <string> [<string>]* Writes a string toward the specified file.

3.6 Attributes (properties)
The INIT program updates some properties of the property system at run time, providing information that is being executed inside the provider.

Property name Describe
Init.action The currently executing action, if none is an empty string ""
Init.command The command that is currently executing. No, an empty string.
Init.svc.<name> Current status of a service, can be "stopped", "Running", "restarting"

Android init.rc parsing "Go"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.