zoukankan      html  css  js  c++  java
  • Android Init语言

    Android Init语言是一种特别简单的语言,专门用来写Android的Init进程使用的配置文件的。
    相当于Linux系统中的rc文件(这句话对于Linux者多半是句废话)。

    Android Init语言主要有四部分组成,分别是Actions, Commands, Services和Options。
    语法的四个组成部分,都是面向行的,每行都对应一个操作,在行里的用空格(注:空格, , )
    来区分不同的token。如果想要在token中插入一个空格,需要使用反斜线+空格的方式。另外双引号
    也可以让一个token中出现的空格部位一般意义的空格,而不是一个分割符。 如果某一行过长的话,
    可以在行尾使用 反斜线连接同一行的内容

    用#可以注释掉一行。Action和Service都是块(SECTION), 所有的Command或者Option属于离它
    最近的那个块。出现在第一个块之外的Command和Option都是无效的。注意下,Command组成了Action,
    而Service的属性都是Option

    Action和Service都有一个唯一的名字。如果出现第二个同名的Action或者Service,那么第二个
    Action或者Service会被认为是一个错误

    Action

    Action实际上就是一组命令的名字而已。Action的名字之后跟着一个触发器。这个触发器才是决定
    这一组命令在何时开始执行。假如系统中发生的事件,和当前Action的触发器相匹配的话,那么这个
    Action中这组命令就会被添加到一个等到执行的列表的末尾。

    每一个Action都是在执行队列中顺序执行的。Init进程在执行这个队列的之余还会处理一些其他事情,
    比如设备的插入或者拔出,属性的设定或者某些进程的重启等。

    on <trigger>
     <command>
     <command>
     <command>
    Services


    Service是一个可执行程序,这个可执行程序由init进程启动。当Service在退出时
    根据选择可以重启这个Service


    service <name> <pathname> [ <argument> ]*
    <option>
    <option>
    ...

    Options


    Option定义了Service在启动或者退出时一些属性或者操作. Option会影响Service在何时
    ,如何启动和运行一个Service

    critical
    如果一个critical Service在4分钟内退出了4次,那么设备就要重启进入Recovery模式

    disabled
    表示这个Service不会在同一类别service启动时自动启动。这样的service必须使用名字启动

    setenv <name> <value>
    设定这个service启动所在进程的环境变量

    下面这几个属性,和selinux相关的规则设置。
    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", "stream" or "seqpacket".
    User and group default to 0.

    user <username>
    Change to username before exec'ing this service.
    Currently defaults to root. (??? probably should 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 the
    supplemental groups of the process (via setgroups()).
    Currently defaults to root. (??? probably should default to nobody)

    seclabel <securitycontext>
    这个是和selinux的管理策略有关的。这个东西要细细地研究啊

    oneshot
    当service退出时,不会重新启动这个service

    class <name>
    为Service分类使用的,每个Service都属于某个类,init进程
    可以一次启动和停止一个类别中的所有service。 如果Service中
    没有这个class的话,默认的是“default”类

    onrestart
    当Service重启时会重启一些启动的依赖的Service

    Triggers

    触发器就是一个字符串,当某个字符串和触发器匹配成功时,那么这个

    action下面的一系列命令就开始执行了。

    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


    这里面的命令大部分和Linux相同,比如copy,read, write, chdir等函数,

    不过下面这些是Android特有的,在Linux基础上补充进去的

    class_start <serviceclass>

    如果某一类的服务还没有启动的话,启动serviceclass这一类别种所有的service。

    class_stop <serviceclass>
    如果某一类服务正在运行,那么停止serviceclass这一类别种所有的service。

     

    setprop <name> <value>
    设置系统属性的命令,属性就是一个键值对

    setrlimit <resource> <cur> <max>

    start <service>
    如果某个服务还没有启动的话,那么就启动这个服务

    stop <service>
    如果某个服务正在运行的话,那么久停止这个服务的运行

    trigger <event>

    从一个Action中触发另外一个Action

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

  • 相关阅读:
    cts 测试环境安装 ubuntu
    关于JS中乘除法的浮点错误解决方法
    事件移除匿名函数
    获取元素offsetLeft值
    jquery on and bind different
    获取事件相对于文档的位置
    angular 使用过程中遇到的问题
    python_文件操作
    monkerunner
    monkey_使用_脚本编写
  • 原文地址:https://www.cnblogs.com/haiming/p/4182071.html
Copyright © 2011-2022 走看看