Android init Syntax parsing

Source: Internet
Author: User
Tags symlink

Specifications for the Android init scripting language

Syntax Description: system/core/init/readme.txt

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.

The Android initialization language contains four types of declarations:

Actions (behavior), Commands (command), Services (service), and options (optional)

    • All of these are in the unit of behavior, and various tokens are separated by spaces.
    • ' \ n ' is a newline flag, and the beginning of the new parsing in the INIT syntax is based on the beginning of the new line, which is parsed by progressive scan;
    • C-style backslash numbers can be used to insert spaces between tokens.
    • Double quotation marks can also be used to prevent a string from being separated into multiple tokens by a space.
    • The trailing slash at the end of the line is used for wrapping, and the comment line begins with a pound sign (#), which allows a space to begin.
    • ', ' \ t ', ' \ R ' will be ignored


Actions and services declare a new grouping section. All commands or options belong to the group that was recently declared. Commands or options that precede the first group will be ignored.
actions and services have a unique name. If there is a duplicate name, the second statement will be ignored as a mistake .

Actions (behavior)
Actions are actually a sequence of commands (commands). Actions have a trigger (trigger) that is used to determine the execution time of the action. When an event that matches the action trigger condition occurs, the action is added to the end of the execution queue, unless it is already in the queue.
Each action in the queue is extracted sequentially, and each command in the action is executed sequentially.
The actions are in the following form:
On <trigger>
<command1>
<command2>
<command3>
On is followed by a trigger, and when trigger is triggered, COMMAND1,COMMAND2,COMMAND3 executes sequentially until the next action or next service.
In a nutshell, actions are a startup script that Android defines at startup, and executes the script when the condition is met, with some command commands in the script, and different scripts using on to differentiate.

Triggers (Trigger)
A Triggers (trigger) is a string that is used to match a specific event type for the actions to occur.
Boot
This is the first triggered triggers (trigger) after Init executes. (After/init.conf (boot configuration file) is loaded)
<name>=<value>:
This form of triggers (trigger) is triggered when the property <name> is set to the <value> specified.
Device-added-<path>:
Device-removed-<path>:
This form of triggers (trigger) is triggered when a device node file is deleted or deleted.
Service-exited-<name>:
This form of triggers (trigger) is triggered when a particular service exits.
Triggers are usually used in conjunction with on.
Example:
On Init
Export Ld_library_path/system/lib
Insmod Modules/fsr.ko
Symlink/system/etc/etc
Mkdir/sdcard 0000 System System
Write/proc/cpu/alignment 4

On boot
...
On Property:ro.kernel.qemu=1
Start ADBD
Three Action:init,boot and a property trigger are declared above, and when Init is triggered, the following command is executed sequentially until the new action on boot is on. The init trigger is determined by the function Action_for_each_trigger in init.c . When the property Ro.kernel.qemu is 1 o'clock, the start adbd command is triggered.


Services (Service)
A service is a program that starts at initialization and optionally restarts when it exits. Services (service) is in the following form:
Service <name> <pathname> [<argument>]*
<option>
<option>
...
Name: Service Name
Pathname: The location of the program corresponding to the current service
Option: Options for current service settings

Options (optional)
The options (option) is a remediation of services (service). They affect when and how services are run.
Critical:
Description This is a service that is critical to the device. If he exits more than four times in four minutes, the system restarts and enters recovery (recovery) mode.

Disabled:
Indicates that the service does not start automatically with the service under the same trigger (trigger). He must be explicitly started by name.

setenv <name> <value> (setting environment variables)
Set environment variables <name> to <value> at process startup.

sockets <name> <type> <perm> [<user> [<group>]]
Create a Uinx domain named/dev/socket/<name> socket and pass its file descriptor to the started process. <type> must be "Dgram" or "stream". The User and group defaults to 0.

User <username>
Change the user name of the service before starting the service. This defaults to root. (??? If possible, it should default to nobody). Currently, if your process requires a Linux capabilities (capability), you cannot use this command. Even if you are root, you must request capabilities (ability) in the program. Then drop to the UID you want.

group <groupname> [<groupname>]*
Change the group name of the service before starting the service. In addition to the first group name (required), the attached group name is typically used to set up a supplemental group of processes (via Setgroups ()). This defaults to root. (??? If possible, it should default to nobody).

OneShot
The service does not restart when it exits.

class <name>
Specifies a service class. All services of the same class can be started and stopped at the same time. If you do not specify a class by using the Class option, the default is the "Default" class service.

Onrestart
When the service restarts, execute a command (details below).

Commands (command)
exec <path> [<argument>]*
Create and execute a program (<path>). INIT will block until the program is fully executed. Since it is not a built-in command, you should try to avoid using exec, which may cause the Init card to die. (??? Do I need a timeout setting?)
Export <name> <value>
In the Global environment variable, set the environment variable <name> to <value>. (This will be inherited by all processes running after this command)
Ifup <interface>
Start the network interface <interface>
Import <filename>
Parses an init configuration file, extending the current configuration.
Hostname <name>
Set the host name.
chmod <octal-mode> <path>
Change file access permissions.
Chown <owner> <group> <path>
Change the owner and group of the file.
Class_start <serviceclass>
Starts the non-running service under all specified service classes.
Class_stop <serviceclass>
Stops all services that are running under the specified service class.
DomainName <name>
Set the domain name.
Insmod <path>
Load the module in <path>.
mkdir <path> [mode] [owner] [group]
Create a directory <path&gt, optionally specifying mode, owner, and group. If not specified, the default permissions are 755 and belong to the root user and root group.
Mount <type> <device> <dir> [<mountoption>]*
An attempt was made to mount the specified device in directory <dir>. <device> can be in[email protected]Specifies the form of a MTD block device. <mountoption> includes "Ro", "RW", "remount", "Noatime", ...
SetProp <name> <value>
Set System Properties <name> to <value> values.
Setrlimit <resource> <cur> <max>
Set the Rlimit (resource limit) for <resource>.
Start <service>
Starts the specified service (if the service is not running).
Stop <service>
Stops the specified service (if the service is running).
Symlink <target> <path>
Create a soft link <target> to <path>.
Sysclktz <mins_west_of_gmt>
Set the system clock base (0 for clock ticks, whichever is Greenwich Mean Time (GMT))
Trigger <event>
Triggers an event. Lets you arrange an action with another action.
Write <path> <string> [<string>]*
Opens a file with a path of <path> and writes one or more strings.

Properties (Attributes)
Init updates some system properties to provide the ability to monitor the events that are occurring:
Init.action
The value of this property is the name of the action being executed, or "" if not.
Init.command
The value of this property is the name of the command being executed, or "" if not.
Init.svc.<name>
Status of the service named <name> ("Stopped" (stop), "Running" (run), "restarting" (restart))

REF:

Http://www.cnblogs.com/mr-raptor/archive/2012/07/12/2588920.html

http://m.blog.csdn.net/blog/wantianpei/8768058

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.