Android Init process (ii) initialization language (INIT.RC) parsing

Source: Internet
Author: User
Tags root directory

The software version used in this article

android:4.2.2

Linux kernel: 3.1.10

The first phase of Init initialization is described in the previous article, which is dealing with various properties. In this article, we will analyze the most important part of Init: parsing init.rc files.

The init.rc file is not a normal configuration file, but rather a file written by a script called the Android Initialization language (Android Init Language, here for short ail). Before understanding how Init parses init.rc files, it is necessary to understand ail, otherwise it is meaningless to mechanically analyze the source code of INIT.C and its associated files.

To learn ail, readers can go to their Android phone's root directory to find init.rc files, preferably downloaded to the local to view, if there is a compiled Android source code, in the <android source code root directory >out/target/product Init.rc files can also be found in the/generic/root directory.

The AIL consists of the following 4 parts.

1. Actions (Actions)

2. Order (Commands)

3. Service (services)

4. Option (Options)

These 4 sections are line-oriented, meaning that a carriage return line break is used as a separator for each statement. The code for each line is represented by multiple symbols (tokens). You can use the backslash escape character to insert a space in the token. Double quotes can synthesize multiple tokens separated by spaces into a tokens. If a line doesn't fit, you can connect the next line by adding a backslash at the end of the row. That is, you can use backslashes to concatenate multiple lines of code into one line of code.

The ail annotation is a line with many shell scripts, starting with #.

Ail needs to be written in multiple sections (section), and each part needs to specify actions or services at the beginning. In other words, each of the actions or services determines a section. All commands and options only belong to the recently defined section. If commands and options are defined before the first section, they will be ignored.

The names of actions and services must be unique. If two or more action or service names have the same name, Init will throw errors and ignore these action and service when executing them.

Here's how the actions, Services, commands, and options should be set up separately.

The syntax of the actions is as follows:

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

That is, the actions start with the keyword on, followed by a trigger, followed by several commands. For example, the following is a standard action.

On boot
    ifup lo
    hostname localhost
    domainname localdomain

Where boot is a trigger, the following three lines are command

So what triggers do init.rc support? Currently, INIT.RC supports the following 5 types of triggers.

1. Boot

This is the first triggered trigger after Init execution, which is to execute the/init.rc after it is loaded trigger

2. <name>=<value>

Triggered when property <name> is set to <value>. For example

On Property:vold.decrypt=trigger_reset_main

Class_reset Main

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.