Android STARTUP script init. RC

Source: Internet
Author: User
Tags unix domain socket

 

Excerpted from "detailed explanation of Android system principles and development points"

Android STARTUP script init. RC

Use the startup script init. RC in Android to perform some simple initialization operations during system initialization. This script is directly installed in the root file system of the target system and parsed by the init executable program. Init. RC is the startup script executed after init is started. Its Syntax mainly includes the following:

Commands: Command
Actions: Action
Triggers: triggers
Services: Service
Options: Options
Propertise: Properties

(1) commands is some basic operations, such:
Mkdir/sdcard 0000 System
Mkdir/System
Mkdir/Data 0771 System
Mkdir/cached 0770 system cache
Mkdir/config 0500 Root
Mkdir/sqlite_stmt_journals 01777 Root
Mount tmpfs/sqlite_stmt_journals size = 4 m
These commands are parsed In the init executable program, and then relevant functions are called for implementation.

(2) actions (Action) indicates a series of commands, which are usually called in triggers (triggers). The action and trigger condition form is:
On <trigger>
<Command>
<Command>
<Command>

An example is as follows:
On init
Export path/sbin:/system/bin:/system/xbin
Mkdir/System
Init indicates a trigger condition. After this trigger event occurs, setting environment variables and creating directories is called an action"

(3) services usually start an executable program. Options are additional content of the service for use with the service.

Service vold/system/bin/vold
Socket vold stream 0660 root Mount

Service bootsound/system/bin/playmp3
User Media
Group audio
Oneshot

Vold and bootsound are the names of the two services, respectively./system/bin/vold and/system/bin/playmp3 are their corresponding executable programs.
Socket, user, group, and oneshot are the options used with the service. The oneshot option indicates that the service is started only once. If the oneshot option is not available,
This executable program will always exist-if the executable program is killed, it will be restarted.

(4) properties are some values used in the system and can be set and read.

Setprop Ro. foreground_app_mem 1536
Setprop Ro. visible_app_mem 2048
On Property: Ro. kernel. qemu = 1
Start adbd
Setprop is used to set attributes. on property can be used to determine attributes. The attributes here are consistent throughout the Android system.

For the keyword of the init script, refer to the system/CORE/init/keyword. h file of the INIT process.
For how to use init. RC, refer to the instruction file system/CORE/init/readme.txt.

To modify the startup process, you only need to modify the content in init. C (System/CORE/init) or init. RC.

Appendix: System/CORE/init/readme.txt

Android init Language
---------------------

The android init language consists of four broad classes of statements,
Which are actions, commands, services, and options.

All of these are line-oriented, consisting of tokens separated
Whitespace. The C-style backslash escapes may be used to insert
Whitespace into a token. Double quotes may also be used to prevent
Whitespace from breaking text into multiple tokens. The backslash,
When it is the last character on a line, may be used for line-folding.

Lines which start with a # (Leading whitespace allowed) are comments.

Actions and Services implicitly declare a new section. All commands
Or options belong to the Section most recently declared. Commands
Or options before the first section are ignored.

Actions and Services have unique names. If a second action or service
Is declared with the same name as an existing one, it is ignored
An error .(??? Shocould we override instead)

Actions
-------
Actions are named sequences of commands. Actions have a trigger which
Is used to determine when the action shoshould occur. When an event
Occurs which matches an action's trigger, that action is added
The tail of a to-be-executed Queue (unless it is already on
Queue ).

Each action in the queue is dequeued in sequence and each command in
That action is executed in sequence. init handles other activities
(Device creation/destruction, Property setting, process restarting)
"Between" the execution of the commands in activities.

Actions take the form:

On <trigger>
<Command>
<Command>
<Command>

Services
--------
Services are programs which init launches and (optionally) restarts
When they exit. services take the form:

Service <Name> <pathname> [<argument>] *
<Option>
<Option>
...

Options
-------
Options are modifiers to services. They affect how and when init
Runs the service.

Critical
This is a device-critical service. If it exits more than four times in
Four minutes, the device will reboot into recovery mode.

Disabled
This service will not automatically start with its class.
It must be explicitly started by name.

Setenv <Name> <value>
Set the environment variable <Name> to <value> In the launched process.

Socket <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" or "stream ".
User and group default to 0.

User <username>
Change to username before exec 'ing this service.
Currently defaults to root .(??? Probably shoshould default to nobody)
Currently, if your process requires Linux capabilities then you 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 are used to set
Supplemental groups of the process (via setgroups ()).
Currently defaults to root .(??? Probably shoshould default to nobody)

Oneshot
Do not restart the service when it exits.

Class <Name>
Specify a class name for the service. All services in
Named class may be started or stopped together. A service
Is in the class "default" if one is not specified via
Class option.

Onrestart
Execute a command (see below) when service restarts.

Triggers
--------
Triggers are strings which can be used to match certain kinds
Of events and used to cause an action to occur.

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

<Name >=< value>
Triggers of this form occur when 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
--------

Exec <path> [<argument>] *
Fork and execute a program (<path>). This will block
The program completes execution. It is best to avoid Exec
As unlike the builtin commands, it runs the risk of getting
Init "stuck ".(??? Maybe there shocould be a timeout ?)

Export <Name> <value>
Set the environment variable <Name> equal to <value> in
Global Environment (which will be inherited by all processes
Started after this command is executed)

IFUP <interface>
Bring the network interface <interface> online.

Import <FILENAME>
Parse an init config file, extending the current configuration.

Hostname <Name>
Set the host name.

Chdir <directory>
Change working directory.

Chmod <octal-mode> <path>
Change file access permissions.

Chown <owner> <group> <path>
Change file owner and group.

Chroot <directory>
Change process root directory.

Class_start <serviceclass>
Start all services of the specified class if they are
Not already running.

Class_stop <serviceclass>
Stop all services of the specified class if they are
Currently running.

Domainname <Name>
Set the domain name.

Insmod <path>
Install the module at <path>

Mkdir <path> [mode] [owner] [group]
Create a directory at <path>, optionally with the given mode, owner, and
Group. If not provided, the directory is created with permissions 755 and
Owned by the root user and root group.

Mount <type> <device> <dir> [<mountoption>] *
Attempt to mount the named device at the directory <dir>
<Device> may be of the form MTD @ name to specify a MTD Block
Device by name.
<Mountoption> S include "Ro", "RW", "remount", "noatime ",...

Setkey
TBD

Setprop <Name> <value>
Set system property <Name> to <value>.

Setrlimit <resource> <cur> <max>
Set the rlimit for a resource.

Start <service>
Start a service running if it is not already running.

Stop <service>
Stop a service from running if it is currently running.

Symlink <target> <path>
Create a symbolic link at <path> with the value <target>

Sysclktz <mins_west_of_gmt>
Set the system clock base (0 if system clock ticks in GMT)

Trigger <event>
Trigger an event. Used to queue an action from another
Action.

Write <path> <string> [<string>] *
Open the file at <path> and write one or more strings
To it with write (2)

Properties
----------
Init updates some system properties to provide some insight
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 ")

Example init. conf
-----------------

# Not complete -- just providing some examples of Usage
#
On Boot
Export path/sbin:/system/bin
Export LD_LIBRARY_PATH/system/lib

Mkdir/dev
Mkdir/proc
Mkdir/sys

Mount tmpfs/dev
Mkdir/dev/PTS
Mkdir/dev/socket
Mount devpts/dev/PTS
Mount proc/proc
Mount sysfs/sys

Write/proc/CPU/alignment 4

IFUP Lo

Hostname localhost
Domainname localhost

Mount yaffs2 MTD @ system/System
Mount yaffs2 MTD @ userdata/Data

Import/system/etc/init. conf

Class_start default

Service adbd/sbin/adbd
User ADB
Group ADB

Service usbd/system/bin/usbd-R
User usbd
Group usbd
Socket usbd 666

Service zygote/system/bin/app_process-xzygote/system/bin -- zygote
Socket zygot 666

Service runtime/system/bin/Runtime
User System
GROUP SYSTEM

On device-added-/dev/compass
Start akmd

On device-removed-/dev/compass
Stop akmd

Service akmd/sbin/akmd
Disabled
User akmd
Group akmd

Debugging notes
---------------
By default, programs executed by init will drop stdout and stderr
/Dev/null. To help with debugging, You can execute your program via
Andoird program logwrapper. This will redirect stdout/stderr into
Android logging system (accessed via logcat ).

For example
Service akmd/system/bin/logwrapper/sbin/akmd

 

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.