android init.rc 编辑,android init.rc命令快速对照表

这篇博客深入解析了Android系统的init.rc配置文件,包括如何通过logwrapper辅助调试,设置系统时钟基座sysclktz,以及服务和服务类的定义和选项。init进程根据触发条件执行命令序列,如设备添加/移除、服务退出等触发的服务启动和停止。此外,介绍了如何使用setprop设置和响应系统属性,以及init更新的一些关键系统属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

注1:另外还讲述了怎样输出log:

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注2:讲述了一个新的命令

sysclktz

Set the system clock base (0 if system clock ticks in GMT)

注3:triggers

boot

This is the first trigger that will occur when init starts

(after /init.conf is loaded)

=

Triggers of this form occur when the property is set

to the specific value .

device-added-

device-removed-

Triggers of these forms occur when a device node is added

or removed.

service-exited-

Triggers of this form occur when the specified service exits.

------------------------------------------

init 由如下四种类型语句组成:

Actionn       :行为

Commands

Services

Options语法(language syntax)结构如下:

每一个语句占据一行,并且各个关键字被空格分开。c规范中的(如

)反斜杠将被忽略(backslash escapes)而被认为是一个空格 ,双引号用来保证空格不会把一个文字串分分为多个关键字。行最后的反斜杠用作续行。

由 # (前面允许有空格)开始的行都是注释行(comment)

一个actions 或 services 的开始隐含声明了一个新的段,所有commands 或 options 属于最近的声明。在第一个段之前的 commands 或 options 都会被忽略

每一个actions 和 services 都有不同的名字。后面与前面发生重名的,那么这个后面重名的将被忽略或被认为是一个错误Actions

Actions其实就是一组被命名的命令序列。actions 都有一个触发条件,触发条件决定了action何时执行。当一个事件发生如果匹配action的触发条件,那么这个action将会被添加到预备执行队列的尾部(除非它已经在队列当中)

每一个action中的命令将被顺序执行。init进程负责在其它activities(如:设备创建/销毁,属性设置,进程重启)之间执行这些命令序列。

action 的格式如下

on      

Services

services 是一些由init 启动 和 重新(如果有需要)启动的程序,当然这些程序如果是存在的。

services 的格式如下:

service [ ]*       ...

Options

options 是service的修饰符,用来告诉init 怎样及何时启动service。

OptionDescription

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

socket [ [ ] ]Create a unix domain socket named /dev/socket/and pass its fd to the launched process. Validdgram and stream. user and group default to 0.(type 实际中是放在name之后)values include

user Change to username before exec'ing this service. Currently defaults to root.

group [ ]*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 (with setgroups()). Currently defaults to root.

capability [ ]+Set linux capability before exec'ing this service

oneshotDo not restart the service when it exits.

class 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.TriggerDescription

bootThis is the first trigger that occurs when init starts (after /init.conf is loaded).

=Triggers of this form occur when the property  is set to the specific value.

device-added-

device-removed-Triggers of these forms occur when a device node is added or removed.

service-exited-Triggers of this form occur when the specified service exits.

Commands

CommandDescription

exec [ ]*Fork and execute a program (). This will block until the program completes execution. Try to avoid exec. Unlike thebuiltin commands, it runs the risk of getting init "stuck".

export Set the environment variable  equal to  in the global environment (which will be inherited by all processes started after this command is executed).

ifup Bring the network interface  online.

import Parse an init config file, extending the current configuration.

hostname Set the host name.

class_start Start all services of the specified class if they are not already running.

class_stop Stop all services of the specified class if they are currently running.

domainname Set the domain name.

insmod Install the module at .

mkdir Make a directory at .

mount

setkey- currenlty undefined -

setprop Set system property  to .

setrlimit Set the rlimit for a resource.

start Start a service running if it is not already running.

stop Stop a service from running if it is currently running.

symlink Create a symbolic link at  with the value .

write [ ]*Open the file at  and write one or more strings to it with write(2).

PropertiesInit updates some system properties to provide some insight intowhat it's doing:PropertyDescription

init.actionEqual to the name of the action currently being executed or "" if none.

init.commandEqual to the command being executed or "" if none.

init.svc.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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值