init.rc整理
来源:互联网 发布:mac 不能用无线鼠标 编辑:程序博客网 时间:2024/06/06 06:56
附录: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 by
whitespace.
The c-style backslash escapes may be used to insert whitespace into a token.
C风格的反斜杠转义成一个令牌可以用来插入空白。
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.
第一个section前面的命令和选项都会被忽略。
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 as
an error. (??? should we override instead)
重复则忽略
Actions
-------
Actions are named sequences of commands. Actions have a trigger which
is used to determine when the action should occur.
When an event occurs which matches an action's trigger, that action is added to
the tail of a to-be-executed queue (unless it is already on the queue).
当一个事件发生后刚好触发了action,则该action将被加入到to-be-executed队列尾部。
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 of:
on <trigger>
<command>
<command>
<command>
Services
--------
Services are programs which init launches and (optionally) restarts when they exit.
服务是一种由init启动并且在服务退出后init将其重启的程序。
Services take the form of:
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.
这是设备非常重要的服务,如果4分钟内退出超过4次,设备将重启进入recovery模式。
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. 创建一个unix domain socket(或IPC进程间通信)且命名为/dev/socket/<name>,然后将这个fd (即/dev/socket/<name>)传给启动的程序。
Unix domain socket 或者 IPC socket 是一种终端,可以使同一台操作系统上的两个或多个进程进行数据通信。
<type> must be "dgram" or "stream". User and group default to 0.
<type>必须是数据包或者流模式,默认的user和group是0.
user <username>
Change to username before exec'ing this service. Currently defaults to root.
执行这个服务之前,切换用户。一般是root用户。
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 the
supplemental groups of the process (via setgroups()).
Currently defaults to root. (??? probably should default to nobody)
oneshot
Do not restart the service when it exits.
服务退出后不重启了。
class <name>
Specify a class name for the service.
为服务指定一个类名。
All services in a named class may be started or stopped together.
同一个类名的服务将可以同时开始和结束。
A service is in the class "default" if one is not specified via the
class option.如果没有指定就是使用 "default" 这个类。
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>.
一般情况: on property:ro.secure=0
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. It is best to avoid exec as unlike the builtin 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. 启动特定网络接口
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.
start <service>
Start a service running if it is not already running.
stop <service>
Stop a service from running if it is currently running.
import <filename>
Parse an init config file, extending the current configuration.
hostname <name>
Set the host name.
domainname <name>
Set the domain 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.
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 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>.
设置系统property里面属性的值,trigger里面有提到。
setrlimit <resource> <cur> <max>
Set the rlimit for a resource.
设置进程能够创建的各种系统资源的限制使用量(不清楚)
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)
设置系统时间基准,时区 sysclktz : system clock time zone
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 into
what it's doing: Init更新一些系统属性以提供对正在发生的事件的监控能力
init.action
Equal to the name of the action currently being executed or "" if none
此属性值为正在被执行的action的名字,如果没有则为""。
init.command
Equal to the command being executed or "" if none.
此属性值为正在被执行的command的名字,如果没有则为""。
init.svc.<name>
State of a named service ("stopped", "running", "restarting")
名字为name的service的状态
On propperty:init.svc.bootanim=stopped
Example init.conf
-----------------
# not complete -- just providing some examples of usage
#
on boot
export PATH /sbin:/system/sbin:/system/bin
export LD_LIBRARY_PATH /system/lib
mkdir /dev
mkdir /proc
mkdir /sys
mount tmpfs tmpfs /dev
mkdir /dev/pts
mkdir /dev/socket
mount devpts devpts /dev/pts
mount proc proc /proc
mount sysfs sysfs /sys
write /proc/cpu/alignment 4
ifup lo
hostname localhost
domainname localhost
mount yaffs2 /system
mount yaffs2 /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 zygote 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 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
Trigger扩展 (网上摘抄)
除了boot 还有init,early-init等(新版本还会有新的添加),我们可以简单的在init.rc中直接使用。这些信号从system/core/init/init.c 中发出,且有一定的顺序。
发射这些triggers,及执行tiggers所引发的命令执行函数为(都在system/core/init/init.c 中定义):
action_for_each_trigger("init", action_add_queue_tail);
drain_action_queue();
另外trigger发送和执行在system/core/init/builtins.c 中得到封装:
int do_trigger(int nargs, char **args)
{
action_for_each_trigger(args[1], action_add_queue_tail);
drain_action_queue();
return 0;
}
从init.rc的解析代码system/core/init/parser.c 来看这个trigger 命令应该在init.rc使用也是有效的。
至此我们已经知道trigger的名字可以自己定制,
触发方式分两种:
1。在代码中触发
2。在init.rc中命令触发trigger
- init.rc整理
- init.rc
- init.rc
- init.rc
- Android init 进程 init.rc init.*.rc
- Android init 进程 init.rc init.*.rc
- Android init 进程 init.rc init.*.rc
- Android init.rc init.vendor.rc 介绍
- [init.rc] android init.rc 总结
- android init.c init.rc
- android init进程 init.rc
- android中的init.rc
- 转 android init.rc
- android init.rc 语法分析
- Android init.rc解析
- Android init.rc解析
- Android 修改init.rc
- Android init.rc解析
- 1-log4j 的使用
- UDID解决办法
- python编程最最简明教程
- 【MongoDB for Java】Java操作MongoDB
- Java类的加载过程
- init.rc整理
- Ubuntu Hudson 安装配置
- ASPX下面时间差函数实现
- var_dump()和print_r()的微小区别
- USB相关
- 美国通过9家IT公司“监听”全球
- 关于tarjan算法的应用
- Ubuntu Quickbuild 安装配置
- MonoDroid初识三:MonoDroid开发之Hello World