Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
parser/ | 03-May-2024 | - | 435 | 301 | ||
Android.mk | D | 03-May-2024 | 2.7 KiB | 132 | 102 | |
MODULE_LICENSE_APACHE2 | D | 03-May-2024 | 0 | |||
NOTICE | D | 03-May-2024 | 10.4 KiB | 191 | 158 | |
action.cpp | D | 03-May-2024 | 12.5 KiB | 429 | 334 | |
action.h | D | 03-May-2024 | 4.2 KiB | 134 | 98 | |
bootchart.cpp | D | 03-May-2024 | 8.1 KiB | 275 | 201 | |
bootchart.h | D | 03-May-2024 | 826 | 27 | 7 | |
builtins.cpp | D | 03-May-2024 | 30.9 KiB | 992 | 762 | |
builtins.h | D | 03-May-2024 | 978 | 36 | 15 | |
compare-bootcharts.py | D | 03-May-2024 | 5.3 KiB | 147 | 89 | |
devices.cpp | D | 03-May-2024 | 26.7 KiB | 1,004 | 789 | |
devices.h | D | 03-May-2024 | 1 KiB | 31 | 11 | |
grab-bootchart.sh | D | 03-May-2024 | 636 | 23 | 13 | |
import_parser.cpp | D | 03-May-2024 | 1.6 KiB | 56 | 32 | |
import_parser.h | D | 03-May-2024 | 1.3 KiB | 44 | 23 | |
init.cpp | D | 03-May-2024 | 22.6 KiB | 750 | 544 | |
init.h | D | 03-May-2024 | 1.2 KiB | 45 | 18 | |
init_parser.cpp | D | 03-May-2024 | 4.4 KiB | 149 | 112 | |
init_parser.h | D | 03-May-2024 | 1.7 KiB | 56 | 32 | |
init_parser_test.cpp | D | 03-May-2024 | 4.2 KiB | 136 | 100 | |
keychords.cpp | D | 03-May-2024 | 3.4 KiB | 116 | 81 | |
keychords.h | D | 03-May-2024 | 760 | 26 | 6 | |
keyword_map.h | D | 03-May-2024 | 2.6 KiB | 78 | 47 | |
log.cpp | D | 03-May-2024 | 2.1 KiB | 70 | 40 | |
log.h | D | 03-May-2024 | 1.2 KiB | 33 | 12 | |
parser.cpp | D | 03-May-2024 | 3.1 KiB | 142 | 127 | |
parser.h | D | 03-May-2024 | 1.1 KiB | 41 | 20 | |
perfboot.py | D | 03-May-2024 | 15.8 KiB | 463 | 352 | |
property_service.cpp | D | 03-May-2024 | 15.9 KiB | 539 | 398 | |
property_service.h | D | 03-May-2024 | 1.1 KiB | 40 | 18 | |
readme.txt | D | 03-May-2024 | 18.5 KiB | 512 | 391 | |
service.cpp | D | 03-May-2024 | 26.3 KiB | 863 | 694 | |
service.h | D | 03-May-2024 | 7.5 KiB | 209 | 154 | |
signal_handler.cpp | D | 03-May-2024 | 2.1 KiB | 76 | 45 | |
signal_handler.h | D | 03-May-2024 | 726 | 23 | 4 | |
ueventd.cpp | D | 03-May-2024 | 4.1 KiB | 173 | 120 | |
ueventd.h | D | 03-May-2024 | 1,013 | 40 | 17 | |
ueventd_keywords.h | D | 03-May-2024 | 356 | 16 | 15 | |
ueventd_parser.cpp | D | 03-May-2024 | 6 KiB | 242 | 194 | |
ueventd_parser.h | D | 03-May-2024 | 925 | 29 | 8 | |
util.cpp | D | 03-May-2024 | 14.8 KiB | 580 | 444 | |
util.h | D | 03-May-2024 | 2.1 KiB | 71 | 42 | |
util_test.cpp | D | 03-May-2024 | 1.2 KiB | 44 | 23 | |
watchdogd.cpp | D | 03-May-2024 | 2 KiB | 73 | 46 | |
watchdogd.h | D | 03-May-2024 | 727 | 23 | 4 |
readme.txt
1 2Android Init Language 3--------------------- 4 5The Android Init Language consists of five broad classes of statements, 6which are Actions, Commands, Services, Options, and Imports. 7 8All of these are line-oriented, consisting of tokens separated by 9whitespace. The c-style backslash escapes may be used to insert 10whitespace into a token. Double quotes may also be used to prevent 11whitespace from breaking text into multiple tokens. The backslash, 12when it is the last character on a line, may be used for line-folding. 13 14Lines which start with a # (leading whitespace allowed) are comments. 15 16Actions and Services implicitly declare a new section. All commands 17or options belong to the section most recently declared. Commands 18or options before the first section are ignored. 19 20Actions and Services have unique names. If a second Action is defined 21with the same name as an existing one, its commands are appended to 22the commands of the existing action. If a second Service is defined 23with the same name as an existing one, it is ignored and an error 24message is logged. 25 26 27Init .rc Files 28-------------- 29The init language is used in plaintext files that take the .rc file 30extension. These are typically multiple of these in multiple 31locations on the system, described below. 32 33/init.rc is the primary .rc file and is loaded by the init executable 34at the beginning of its execution. It is responsible for the initial 35set up of the system. It imports /init.${ro.hardware}.rc which is the 36primary vendor supplied .rc file. 37 38During the mount_all command, the init executable loads all of the 39files contained within the /{system,vendor,odm}/etc/init/ directories. 40These directories are intended for all Actions and Services used after 41file system mounting. 42 43One may specify paths in the mount_all command line to have it import 44.rc files at the specified paths instead of the default ones listed above. 45This is primarily for supporting factory mode and other non-standard boot 46modes. The three default paths should be used for the normal boot process. 47 48The intention of these directories is as follows 49 1) /system/etc/init/ is for core system items such as 50 SurfaceFlinger, MediaService, and logcatd. 51 2) /vendor/etc/init/ is for SoC vendor items such as actions or 52 daemons needed for core SoC functionality. 53 3) /odm/etc/init/ is for device manufacturer items such as 54 actions or daemons needed for motion sensor or other peripheral 55 functionality. 56 57All services whose binaries reside on the system, vendor, or odm 58partitions should have their service entries placed into a 59corresponding init .rc file, located in the /etc/init/ 60directory of the partition where they reside. There is a build 61system macro, LOCAL_INIT_RC, that handles this for developers. Each 62init .rc file should additionally contain any actions associated with 63its service. 64 65An example is the logcatd.rc and Android.mk files located in the 66system/core/logcat directory. The LOCAL_INIT_RC macro in the 67Android.mk file places logcatd.rc in /system/etc/init/ during the 68build process. Init loads logcatd.rc during the mount_all command and 69allows the service to be run and the action to be queued when 70appropriate. 71 72This break up of init .rc files according to their daemon is preferred 73to the previously used monolithic init .rc files. This approach 74ensures that the only service entries that init reads and the only 75actions that init performs correspond to services whose binaries are in 76fact present on the file system, which was not the case with the 77monolithic init .rc files. This additionally will aid in merge 78conflict resolution when multiple services are added to the system, as 79each one will go into a separate file. 80 81Actions 82------- 83Actions are named sequences of commands. Actions have a trigger which 84is used to determine when the action should occur. When an event 85occurs which matches an action's trigger, that action is added to 86the tail of a to-be-executed queue (unless it is already on the 87queue). 88 89Each action in the queue is dequeued in sequence and each command in 90that action is executed in sequence. Init handles other activities 91(device creation/destruction, property setting, process restarting) 92"between" the execution of the commands in activities. 93 94Actions take the form of: 95 96on <trigger> [&& <trigger>]* 97 <command> 98 <command> 99 <command> 100 101 102Services 103-------- 104Services are programs which init launches and (optionally) restarts 105when they exit. Services take the form of: 106 107service <name> <pathname> [ <argument> ]* 108 <option> 109 <option> 110 ... 111 112 113Options 114------- 115Options are modifiers to services. They affect how and when init 116runs the service. 117 118critical 119 This is a device-critical service. If it exits more than four times in 120 four minutes, the device will reboot into recovery mode. 121 122disabled 123 This service will not automatically start with its class. 124 It must be explicitly started by name. 125 126setenv <name> <value> 127 Set the environment variable <name> to <value> in the launched process. 128 129socket <name> <type> <perm> [ <user> [ <group> [ <seclabel> ] ] ] 130 Create a unix domain socket named /dev/socket/<name> and pass 131 its fd to the launched process. <type> must be "dgram", "stream" or "seqpacket". 132 User and group default to 0. 133 'seclabel' is the SELinux security context for the socket. 134 It defaults to the service security context, as specified by seclabel or 135 computed based on the service executable file security context. 136 137user <username> 138 Change to username before exec'ing this service. 139 Currently defaults to root. (??? probably should default to nobody) 140 As of Android M, processes should use this option even if they 141 require linux capabilities. Previously, to acquire linux 142 capabilities, a process would need to run as root, request the 143 capabilities, then drop to its desired uid. There is a new 144 mechanism through fs_config that allows device manufacturers to add 145 linux capabilities to specific binaries on a file system that should 146 be used instead. This mechanism is described on 147 http://source.android.com/devices/tech/config/filesystem.html. When 148 using this new mechanism, processes can use the user option to 149 select their desired uid without ever running as root. 150 151group <groupname> [ <groupname> ]* 152 Change to groupname before exec'ing this service. Additional 153 groupnames beyond the (required) first one are used to set the 154 supplemental groups of the process (via setgroups()). 155 Currently defaults to root. (??? probably should default to nobody) 156 157seclabel <seclabel> 158 Change to 'seclabel' before exec'ing this service. 159 Primarily for use by services run from the rootfs, e.g. ueventd, adbd. 160 Services on the system partition can instead use policy-defined transitions 161 based on their file security context. 162 If not specified and no transition is defined in policy, defaults to the init context. 163 164oneshot 165 Do not restart the service when it exits. 166 167class <name> 168 Specify a class name for the service. All services in a 169 named class may be started or stopped together. A service 170 is in the class "default" if one is not specified via the 171 class option. 172 173onrestart 174 Execute a Command (see below) when service restarts. 175 176writepid <file...> 177 Write the child's pid to the given files when it forks. Meant for 178 cgroup/cpuset usage. 179 180 181Triggers 182-------- 183Triggers are strings which can be used to match certain kinds of 184events and used to cause an action to occur. 185 186Triggers are subdivided into event triggers and property triggers. 187 188Event triggers are strings triggered by the 'trigger' command or by 189the QueueEventTrigger() function within the init executable. These 190take the form of a simple string such as 'boot' or 'late-init'. 191 192Property triggers are strings triggered when a named property changes 193value to a given new value or when a named property changes value to 194any new value. These take the form of 'property:<name>=<value>' and 195'property:<name>=*' respectively. Property triggers are additionally 196evaluated and triggered accordingly during the initial boot phase of 197init. 198 199An Action can have multiple property triggers but may only have one 200event trigger. 201 202For example: 203'on boot && property:a=b' defines an action that is only executed when 204the 'boot' event trigger happens and the property a equals b. 205 206'on property:a=b && property:c=d' defines an action that is executed 207at three times, 208 1) During initial boot if property a=b and property c=d 209 2) Any time that property a transitions to value b, while property 210 c already equals d. 211 3) Any time that property c transitions to value d, while property 212 a already equals b. 213 214 215Commands 216-------- 217 218bootchart_init 219 Start bootcharting if configured (see below). 220 This is included in the default init.rc. 221 222chmod <octal-mode> <path> 223 Change file access permissions. 224 225chown <owner> <group> <path> 226 Change file owner and group. 227 228class_start <serviceclass> 229 Start all services of the specified class if they are 230 not already running. 231 232class_stop <serviceclass> 233 Stop and disable all services of the specified class if they are 234 currently running. 235 236class_reset <serviceclass> 237 Stop all services of the specified class if they are 238 currently running, without disabling them. They can be restarted 239 later using class_start. 240 241copy <src> <dst> 242 Copies a file. Similar to write, but useful for binary/large 243 amounts of data. 244 245domainname <name> 246 Set the domain name. 247 248enable <servicename> 249 Turns a disabled service into an enabled one as if the service did not 250 specify disabled. 251 If the service is supposed to be running, it will be started now. 252 Typically used when the bootloader sets a variable that indicates a specific 253 service should be started when needed. E.g. 254 on property:ro.boot.myfancyhardware=1 255 enable my_fancy_service_for_my_fancy_hardware 256 257exec [ <seclabel> [ <user> [ <group> ]* ] ] -- <command> [ <argument> ]* 258 Fork and execute command with the given arguments. The command starts 259 after "--" so that an optional security context, user, and supplementary 260 groups can be provided. No other commands will be run until this one 261 finishes. <seclabel> can be a - to denote default. 262 263export <name> <value> 264 Set the environment variable <name> equal to <value> in the 265 global environment (which will be inherited by all processes 266 started after this command is executed) 267 268hostname <name> 269 Set the host name. 270 271ifup <interface> 272 Bring the network interface <interface> online. 273 274insmod <path> 275 Install the module at <path> 276 277load_all_props 278 Loads properties from /system, /vendor, et cetera. 279 This is included in the default init.rc. 280 281load_persist_props 282 Loads persistent properties when /data has been decrypted. 283 This is included in the default init.rc. 284 285loglevel <level> 286 Sets the kernel log level to level. Properties are expanded within <level>. 287 288mkdir <path> [mode] [owner] [group] 289 Create a directory at <path>, optionally with the given mode, owner, and 290 group. If not provided, the directory is created with permissions 755 and 291 owned by the root user and root group. If provided, the mode, owner and group 292 will be updated if the directory exists already. 293 294mount_all <fstab> [ <path> ]* 295 Calls fs_mgr_mount_all on the given fs_mgr-format fstab and imports .rc files 296 at the specified paths (e.g., on the partitions just mounted). Refer to the 297 section of "Init .rc Files" for detail. 298 299mount <type> <device> <dir> [ <flag> ]* [<options>] 300 Attempt to mount the named device at the directory <dir> 301 <device> may be of the form mtd@name to specify a mtd block 302 device by name. 303 <flag>s include "ro", "rw", "remount", "noatime", ... 304 <options> include "barrier=1", "noauto_da_alloc", "discard", ... as 305 a comma separated string, eg: barrier=1,noauto_da_alloc 306 307powerctl 308 Internal implementation detail used to respond to changes to the 309 "sys.powerctl" system property, used to implement rebooting. 310 311restart <service> 312 Like stop, but doesn't disable the service. 313 314restorecon <path> [ <path> ]* 315 Restore the file named by <path> to the security context specified 316 in the file_contexts configuration. 317 Not required for directories created by the init.rc as these are 318 automatically labeled correctly by init. 319 320restorecon_recursive <path> [ <path> ]* 321 Recursively restore the directory tree named by <path> to the 322 security contexts specified in the file_contexts configuration. 323 324rm <path> 325 Calls unlink(2) on the given path. You might want to 326 use "exec -- rm ..." instead (provided the system partition is 327 already mounted). 328 329rmdir <path> 330 Calls rmdir(2) on the given path. 331 332setprop <name> <value> 333 Set system property <name> to <value>. Properties are expanded 334 within <value>. 335 336setrlimit <resource> <cur> <max> 337 Set the rlimit for a resource. 338 339start <service> 340 Start a service running if it is not already running. 341 342stop <service> 343 Stop a service from running if it is currently running. 344 345swapon_all <fstab> 346 Calls fs_mgr_swapon_all on the given fstab file. 347 348symlink <target> <path> 349 Create a symbolic link at <path> with the value <target> 350 351sysclktz <mins_west_of_gmt> 352 Set the system clock base (0 if system clock ticks in GMT) 353 354trigger <event> 355 Trigger an event. Used to queue an action from another 356 action. 357 358umount <path> 359 Unmount the filesystem mounted at that path. 360 361verity_load_state 362 Internal implementation detail used to load dm-verity state. 363 364verity_update_state <mount_point> 365 Internal implementation detail used to update dm-verity state and 366 set the partition.<mount_point>.verified properties used by adb remount 367 because fs_mgr can't set them directly itself. 368 369wait <path> [ <timeout> ] 370 Poll for the existence of the given file and return when found, 371 or the timeout has been reached. If timeout is not specified it 372 currently defaults to five seconds. 373 374write <path> <content> 375 Open the file at <path> and write a string to it with write(2). 376 If the file does not exist, it will be created. If it does exist, 377 it will be truncated. Properties are expanded within <content>. 378 379 380Imports 381------- 382The import keyword is not a command, but rather its own section and is 383handled immediately after the .rc file that contains it has finished 384being parsed. It takes the below form: 385 386import <path> 387 Parse an init config file, extending the current configuration. 388 If <path> is a directory, each file in the directory is parsed as 389 a config file. It is not recursive, nested directories will 390 not be parsed. 391 392There are only two times where the init executable imports .rc files, 393 1) When it imports /init.rc during initial boot 394 2) When it imports /{system,vendor,odm}/etc/init/ or .rc files at specified 395 paths during mount_all 396 397 398Properties 399---------- 400Init provides information about the services that it is responsible 401for via the below properties. 402 403init.svc.<name> 404 State of a named service ("stopped", "stopping", "running", "restarting") 405 406 407Bootcharting 408------------ 409This version of init contains code to perform "bootcharting": generating log 410files that can be later processed by the tools provided by www.bootchart.org. 411 412On the emulator, use the -bootchart <timeout> option to boot with bootcharting 413activated for <timeout> seconds. 414 415On a device, create /data/bootchart/start with a command like the following: 416 417 adb shell 'echo $TIMEOUT > /data/bootchart/start' 418 419Where the value of $TIMEOUT corresponds to the desired bootcharted period in 420seconds. Bootcharting will stop after that many seconds have elapsed. 421You can also stop the bootcharting at any moment by doing the following: 422 423 adb shell 'echo 1 > /data/bootchart/stop' 424 425Note that /data/bootchart/stop is deleted automatically by init at the end of 426the bootcharting. This is not the case with /data/bootchart/start, so don't 427forget to delete it when you're done collecting data. 428 429The log files are written to /data/bootchart/. A script is provided to 430retrieve them and create a bootchart.tgz file that can be used with the 431bootchart command-line utility: 432 433 sudo apt-get install pybootchartgui 434 # grab-bootchart.sh uses $ANDROID_SERIAL. 435 $ANDROID_BUILD_TOP/system/core/init/grab-bootchart.sh 436 437One thing to watch for is that the bootchart will show init as if it started 438running at 0s. You'll have to look at dmesg to work out when the kernel 439actually started init. 440 441 442Comparing two bootcharts 443------------------------ 444A handy script named compare-bootcharts.py can be used to compare the 445start/end time of selected processes. The aforementioned grab-bootchart.sh 446will leave a bootchart tarball named bootchart.tgz at /tmp/android-bootchart. 447If two such barballs are preserved on the host machine under different 448directories, the script can list the timestamps differences. For example: 449 450Usage: system/core/init/compare-bootcharts.py base_bootchart_dir 451 exp_bootchart_dir 452 453process: baseline experiment (delta) 454 - Unit is ms (a jiffy is 10 ms on the system) 455------------------------------------ 456/init: 50 40 (-10) 457/system/bin/surfaceflinger: 4320 4470 (+150) 458/system/bin/bootanimation: 6980 6990 (+10) 459zygote64: 10410 10640 (+230) 460zygote: 10410 10640 (+230) 461system_server: 15350 15150 (-200) 462bootanimation ends at: 33790 31230 (-2560) 463 464 465Systrace 466-------- 467Systrace [1] can be used for obtaining performance analysis reports during boot 468time on userdebug or eng builds. 469Here is an example of trace events of "wm" and "am" categories: 470 471 $ANDROID_BUILD_TOP/external/chromium-trace/systrace.py wm am --boot 472 473This command will cause the device to reboot. After the device is rebooted and 474the boot sequence has finished, the trace report is obtained from the device 475and written as trace.html on the host by hitting Ctrl+C. 476 477LIMITATION 478Recording trace events is started after persistent properties are loaded, so 479the trace events that are emitted before that are not recorded. Several 480services such as vold, surfaceflinger, and servicemanager are affected by this 481limitation since they are started before persistent properties are loaded. 482Zygote initialization and the processes that are forked from the zygote are not 483affected. 484 485[1] http://developer.android.com/tools/help/systrace.html 486 487 488Debugging init 489-------------- 490By default, programs executed by init will drop stdout and stderr into 491/dev/null. To help with debugging, you can execute your program via the 492Android program logwrapper. This will redirect stdout/stderr into the 493Android logging system (accessed via logcat). 494 495For example 496service akmd /system/bin/logwrapper /sbin/akmd 497 498For quicker turnaround when working on init itself, use: 499 500 mm -j 501 m ramdisk-nodeps 502 m bootimage-nodeps 503 adb reboot bootloader 504 fastboot boot $ANDROID_PRODUCT_OUT/boot.img 505 506Alternatively, use the emulator: 507 508 emulator -partition-size 1024 -verbose -show-kernel -no-window 509 510You might want to call klog_set_level(6) after the klog_init() call 511so you see the kernel logging in dmesg (or the emulator output). 512