Introduction to Android init.rc files

Source: Internet
Author: User
Tags unix domain socket

INIT.RC consists of a number of action and service. Each statement occupies one line, and each keyword is separated by a space.

Lines starting with # (spaces previously allowed) are comment lines (comment)

The beginning of an actions or services implicitly declares a new segment, and all commands or options belong to the most recent declaration. Commands or options before the first paragraph will be ignored

Each of the actions and services has a different name. After the same name occurs in the previous name, then the name of the duplicate will be ignored or considered to be an error.

actions are actually a set of named sequences of commands . Actions have a trigger condition that determines when the action is executed. When an event occurs that matches the trigger condition of the action, the action is added to the end of the pre-execution queue (unless it is already in the queue)

The commands in each action are executed sequentially. The INIT process is responsible for executing these sequence of commands between other activities (such as device creation/destruction, property settings, Process restarts).

Each of the action formats is as follows:

On <trigger>

<command>

<command>

...

Trigger is an action-triggered condition that has the following types:

1. Boot

Occurs when Init starts,/init.conf is loaded later.

2. <name>=<value>

Occurs when the value of the property named <name> is set to <value>.

3, device-added-<path>/device-removed-<path>

When a device node is added/deleted.

4. service-exited-<name> when a service exits.

There are several types of command:

1. exec <path> [<argument>]*

Fork and execute a path <path> the following program, and Init will not proceed until the program has finished executing. Try to avoid using this command, which may cause init to block. Other command does not exist for this issue.

2. Export <name> <value>

Set the value of Global environment variable <name> to <value>. All processes started after this command has been executed inherit this global variable.

3. Ifup <interface>

Bring the network Interface <interface> online. (Open a network card)

4. Import <filename>

Parse an init config file, extending the current configuration.

5. Hostname <name>

Set the host name.

6. Class_start <serviceclass>

If a class of service is not running, start them.

7. Class_stop <serviceclass>

If a class of service is running, stop them.

8. DomainName <name>

Set the domain name.

9. Insmod <path>

Installation path <path> the specified module.

10. mkdir <path>

Create <path> represent folders that can only be created on a layer-by-layer level.

11, Mount <type> <device> <dir> [<mountoption>]*

Mount <device> to the <dir> directory of file systems of system type <type>. <device> may have [email protected] in the form of a MTD block device named name.

12, Setkey

Not defined

13, SetProp <name> <value>

Set System Properties.

14, Setrlimit <resource> <cur> <max>

Set the Rlimit for a resource.

15. Start <service>

If the service is not running, start it.

16. Stop <service>

If the service is running, stop it.

17, Symlink <target> <path>

Link <target> to directory <path> below.

18. Write <path> <string> [<string>]*

Open <path> refer to the file and put <string> write.

For 3, 5, 8, see init.rc.

On boot

# Basic Network Init

Ifup Lo

hostname localhost

DomainName Localdomain

About 14, see the init.rc inside

# set Rlimit_nice to allow priorities from to-20

Setrlimit 13 40 40

When we're done with the action, let's say service.

Services are programs that are started by Init and restarted (if necessary), of course, if these programs are present.

Each of the service formats is as follows:

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

<option>

<option>

...

For example:

1

Service PPP/SYSTEM/BIN/PPPD Call GPRS
User root
Group System Radio
Disabled
OneShot

2

Service MTPD/SYSTEM/BIN/MTPD
Socket MTPD Stream System system
User VPN
Group VPN Net_admin Net_raw
Disabled
OneShot

The options is a service modifier that tells Init how and when to start the service. There are several:

1, Disableds

This service cannot be started by starting a class of services and can only be started by name alone.

2. Socket <type> <name> <perm> <user> <group>

Create a UNIX domain socket named/dev/socket/<name> and pass its FD to the loaded process. The value of <type> is Dgram or stream.

Note: When using the socket in init.rc,,<type> is placed after <name>.

The INIT program may set several special property values during the run to tell other programs what it is doing. These properties are:

(1), init.action

The name of the action currently being executed, if not, is "".

(2), Init.command

The name of the command that is currently executing, if not, is "".

(3), init.svc.<name>

The status of a service. Possible values are: "Stopped", "Running", "restarting"

3. User <username>

Before starting the service, switch the user name to <username>. Default is Root

4. Group <groupname> [<groupname>]*

Before starting the service, switch the group name to <groupname>. A service may belong to more than one group.

5, capability [<capability>]+

Set Linux capability before exec ' ing this service

6, OneShot

The service runs once and does not restart after exiting.

7. Class <name>

Set a category for the service, in which a service can start or stop at the same time. If this property is not available, the default category for the service is "default"

By default, programs that start with INIT will direct stdout and stderr to/dev/null. Sometimes for debugging convenience, you can start a program via the Android Logwrapper program. In this way, the launcher stdout and stderr are directed to the Android log system, which can be viewed through the logcat.

For example:

Service AKMD/SYSTEM/BIN/LOGWRAPER/SBIN/AKMD

Reprint: CSDN netizen http://blog.csdn.net/a345017062/archive/2011/03/11/6239204.aspx, this blog, own a partial modification, for Android software developers, It is necessary to study.

Introduction to Android init.rc files

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.