android init.rc语法分析
来源:互联网 发布:php echo输出中文乱码 编辑:程序博客网 时间:2024/06/07 14:13
转自http://www.cnblogs.com/leaven/archive/2010/12/25/1917007.html
此文来自于对http://source.android.com/porting/index.html中bring up段的简译。其中有一处与源码的
-----------------------------------------------
---------------
By default, programs executed by init will drop stdout and stderr into
/dev/null. To help with debugging, you can execute your program via the
Andoird program logwrapper. This will redirect stdout/stderr into the
Android logging system (accessed via logcat).
For example
service akmd /system/bin/logwrapper /sbin/akmd
Set the system clock base (0 if system clock ticks in GMT)
注3:triggers
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.
------------------------------------------
init 由如下四种类型语句组成:
- Actionn :行为
- Commands
- Services
- Options
- 每一个语句占据一行,并且各个关键字被空格分开。c规范中的(如 \n)反斜杠将被忽略(backslash escapes)而被认为是一个空格 ,双引号用来保证空格不会把一个文字串分分为多个关键字。行最后的反斜杠用作续行。
- 由 # (前面允许有空格)开始的行都是注释行(comment)
- 一个actions 或 services 的开始隐含声明了一个新的段,所有commands 或 options 属于最近的声明。在第一个段之前的 commands 或 options 都会被忽略
- 每一个actions 和 services 都有不同的名字。后面与前面发生重名的,那么这个后面重名的将被忽略或被认为是一个错误
Actions其实就是一组被命名的命令序列。actions 都有一个触发条件,触发条件决定了action何时执行。当一个事件发生如果匹配action的触发条件,那么这个action将会被添加到预备执行队列的尾部(除非它已经在队列当中)
每一个action中的命令将被顺序执行。init进程负责在其它activities(如:设备创建/销毁,属性设置,进程重启)之间执行这些命令序列。
Services
services 是一些由init 启动 和 重新(如果有需要)启动的程序,当然这些程序如果是存在的。
Options
options 是service的修饰符,用来告诉init 怎样及何时启动service。
disabled
This service will not automatically start with its class. It must be explicitly started by name.socket <type> <name> <perm> [ <user> [ <group> ] ]
Create a unix domain socket named /dev/socket/<name>
and pass its fd to the launched process. Valid<type>
dgram
and stream
. user
andgroup
default to 0.(type 实际中是放在name之后)
user <username>
Change to username before exec'ing this service. Currently defaults to root.group <groupname> [ <groupname> ]*
Change to groupname before exec'ing this service. Additional groupnames beyond the first, which is required, are used to set additional groups of the process (withsetgroups()
). Currently defaults to root.capability [ <capability> ]+
Set linux capability before exec'ing this serviceoneshot
Do not restart the service when it exits.class <name>
Specify a class name for the service. All services in a named class must start and stop together. A service is considered of class "default" if one is not specified via the class option.
Triggers
Triggers are strings used to match certain kinds of events that cause an action to occur.
boot
This is the first trigger that occurs 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 until the program completes execution. Try to avoid exec. Unlike thebuiltin
commands, it runs the risk of getting init "stuck".export <name> <value>
Set the environment variable <name>
equal to <value>
in the 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.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>
Make a directory at <path>
.mount <type> <device> <dir> [ <mountoption> ]*
Attempt to mount the named device at the directory <dir>
<device>
. This may be of the form mtd@name to specify a mtd block device by name.setkey
- currenlty undefined -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>
.write <path> <string> [ <string> ]*
Open the file at <path>
and write one or more strings to it with write(2).Properties
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", or "restarting").在init.rc中使用属性的范例如下:
setprop ro.FOREGROUND_APP_MEM 1536
setprop ro.VISIBLE_APP_MEM 2048
on property:ro.kernel.qemu=1
start adbd
setprop用于设置属性,on property可以用于判断属性,这里的属性在整个Android系统运行中都是一致的。
init脚本中的关键字可以参考:system/core/init/keywords.h
- android init.rc 语法分析
- android init.rc 语法分析
- android init.rc 语法分析
- android init.rc 语法分析
- android init.rc语法分析
- android init.rc 语法分析
- android init.rc 语法分析
- android init.rc 语法分析
- android init.rc语法分析
- Android Init.rc 语法分析
- android init.rc 语法分析
- Android初始化语言init.rc语法分析
- [摘]Android初始化语言init.rc语法分析
- android init.rc 语法分析
- android init.rc 语法分析
- init.rc的语法分析
- Android启动文件init.rc文件实例语法分析
- init.rc 状态服务器相关语法分析
- 卢松松:周一的文章最难写 晚上发文最合适
- Eclipse For Mac && Windows:格式化模版、注释模版的导入方法
- hdu2602 dp 01背包
- adb 与log
- ORA-27102: out of memory 故障
- android init.rc语法分析
- MFC 单文档多视图实现(不是完全原创的,但是也不是直接转的,核心看法原创)
- jquery如何把参数列严格转换成数组
- 堆栈的应用-进制的转换
- poj3624 dp 01背包
- Windows phone8 基础篇(二) XAML简介
- 黑马程序员--深入探究多线程
- linux下几个简易的系统监控脚本
- STL中sort()函数的使用