Thursday, October 31, 2013

Android 4.3 init.rc

init is the first process after kernel started. For Android 4.3, the corresponding source code lies in: system/core/init It does the following tasks step by step:
Initialize log system.
Parse /init.rc and /init.%hardware%.rc.
Execute early-init action in the two files parsed in step 2.
Device specific initialize. For example, make all device node in /dev and download firmwares.
Initialize property system. Actually the property system is working as a share memory. Logically it looks like a registry under Windows system.
Execute init action in the two files parsed in step 2.
Start property service.
Execute early-boot and boot actions in the two files parsed in step 2.
Execute property action in the two files parsed in step 2.
Enter into an indefinite loop to wait for device/property set/child process exit events. For example, if an SD card is plugged in, init will receive a device add event, so it can make node for the
device. Most of the important process is forked in init, so if any of them crashed, init will receive a SIGCHLD then translate it into a child process exit event, so in the loop init can handle the
process exit event and execute the commands defined in *.rc (it will run command onrestart).

The .rc file is a script file defined by Android. The default is device/system/rootdir/init.rc. We can take a loot at the file format(system/core/init/readme.txt is a good overall introduction of the
script). Basically the script file contains actions and services.

No comments: