Android Init language

Source: Internet
Author: User

The Android Init language is a particularly simple language that is specifically used to write the configuration files used by the Init process of Android.
Equivalent to the RC file in the Linux system (this sentence is mostly nonsense for Linux).

The Android init language has four main components, namely, actions, Commands, services and options.
The four components of the syntax are line-oriented, each line corresponds to an action, with spaces in the row (note: space, \ t, \ r)
to differentiate different tokens. If you want to insert a space in token, you need to use a backslash + space. Another double quote
You can also make a space in a token that appears in a space of a general meaning, rather than a separator. If a line is too long,
You can use backslashes to connect the same line of content at the end of a row

Use # to comment out a line. Both the action and service are blocks (section), and all command or option belongs to the
The nearest block. command and option that appear outside the first block are not valid. Notice that the command makes up the action,
and the service's properties are all option

Both the action and service have a unique name. If a second action or service with the same name appears, the second
Action or service will be considered a mistake

Action

An action is actually the name of a set of commands. The action's name follows a trigger. This trigger is the decision.
When this set of commands starts to execute. If the event that occurs in the system matches the trigger of the current action, then this
This set of commands in the action is added to the end of the list waiting to be executed.

Each action is executed sequentially in the execution queue. The init process also handles some other things while executing this queue,
such as the insertion or removal of a device, the setting of attributes, or the restart of certain processes.

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


The service is an executable program that is started by the Init process. When the service exits
Depending on the selection, you can restart the service


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

Options


option defines some of the properties or actions that the service starts or exits. option will affect when the service
, how to start and run a service

Critical
If a critical service exits 4 times in 4 minutes, the device will reboot into recovery mode

Disabled
Indicates that the service does not start automatically when the same category of service is started. Such service must be started with a name

Setenv <name> <value>
Set the environment variables for the process where the service starts

The following are some of the properties, and SELinux-related rule settings.
Sockets <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.

User <username>
Change to username before exec ' ing this service.
currently defaults to root. (??? probably should default to nobody)
Currently, if your process requires Linux capabilities then your cannot use
This command. You must instead request the capabilities in-process while
Still root, and then drop to your desired UID.

Group <groupname> [<groupname>]*
Change to groupname before exec ' ing this service. Additional
Groupnames beyond the (required) first one is used to set the
Supplemental groups of the process (via Setgroups ()).
currently defaults to root. (??? probably should default to nobody)

Seclabel <securitycontext>
This is related to SELinux's management strategy. This thing needs to be studied carefully.

OneShot
When the service exits, the service is not restarted

Class <name>
Used for service classifications, each service belongs to a class, and the Init process
You can start and stop all the service in one category at a time. If the service
Without this class, the default class

Onrestart
Restarting some of the dependent service starts when the service restarts

Triggers

A trigger is a string, and when a string and trigger match successfully, the

A sequence of commands below the action is executed.

Boot
This was the first trigger that would occur when Init starts
(After/init.conf is loaded)

<name>=<value>
Triggers of this form occur if the property <name> is set
To the specific value <value>.

Device-added-<path>
Device-removed-<path>
Triggers of these forms occur when a device node is added
or removed.

Service-exited-<name>
Triggers of this form occur when the specified service exits.

Commands


Most of the commands are the same as Linux, such as Copy,read, write, chdir, etc.

But these are Android-specific, added to Linux based

Class_start <serviceclass>

If a certain type of service has not yet started, start serviceclass all services in this category.

Class_stop <serviceclass>
If a class of services is running, stop serviceclass all service types in this category.

SetProp <name> <value>
A command that sets the properties of a system, which is a key-value pair

Setrlimit <resource> <cur> <max>

Start <service>
If a service has not yet started, start the service

Stop <service>
If a service is running, stop running this service for a long time

Trigger <event>

Trigger another action from one action

Properties
Init updates some system properties to provide some insight into
What it ' s doing:

Init.action
Equal to the name of the action currently being executed or "" if none

Init.command
Equal to the command being executed or "" if none.

Init.svc.<name>
State of a named service ("Stopped", "Running", "restarting")

Android Init language

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.