Android Init語言

來源:互聯網
上載者:User

標籤:

Android Init語言是一種特別簡單的語言,專門用來寫Android的Init進程使用的設定檔的。
相當於Linux系統中的rc檔案(這句話對於Linux者多半是句廢話)。

Android Init語言主要有四部分組成,分別是Actions, Commands, Services和Options。
文法的四個組成部分,都是面向行的,每行都對應一個操作,在行裡的用空格(註:空格,\t, \r)
來區分不同的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")

 

Android Init語言

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.