Home | History | Annotate | only in /system/core/init
Up to higher level directory
NameDateSize
.clang-format06-Dec-2017251
action.cpp06-Dec-201711.1K
action.h06-Dec-20174.3K
Android.bp06-Dec-20174.1K
Android.mk06-Dec-20172K
bootchart.cpp06-Dec-20175.9K
bootchart.h06-Dec-2017868
builtins.cpp06-Dec-201729.6K
builtins.h06-Dec-20171.1K
capabilities.cpp06-Dec-20176.3K
capabilities.h06-Dec-20171.2K
compare-bootcharts.py06-Dec-20175.3K
descriptors.cpp06-Dec-20174.4K
descriptors.h06-Dec-20172.5K
devices.cpp06-Dec-201715.8K
devices.h06-Dec-20174.1K
devices_test.cpp06-Dec-201712.1K
firmware_handler.cpp06-Dec-20173.9K
firmware_handler.h06-Dec-2017849
grab-bootchart.sh06-Dec-2017623
import_parser.cpp06-Dec-20171.7K
import_parser.h06-Dec-20171.3K
init.cpp06-Dec-201741.4K
init.h06-Dec-20171.5K
init_first_stage.cpp06-Dec-201718.6K
init_first_stage.h06-Dec-2017832
init_parser.cpp06-Dec-20175.4K
init_parser.h06-Dec-20174.2K
init_parser_test.cpp06-Dec-20174.7K
init_test.cpp06-Dec-20176.3K
keychords.cpp06-Dec-20173.5K
keychords.h06-Dec-2017853
keyword_map.h06-Dec-20172.8K
log.cpp06-Dec-20171.8K
log.h06-Dec-2017898
MODULE_LICENSE_APACHE206-Dec-20170
NOTICE06-Dec-201710.4K
parser/06-Dec-2017
parser.cpp06-Dec-20172.8K
parser.h06-Dec-2017952
perfboot.py06-Dec-201715.8K
property_service.cpp06-Dec-201722.2K
property_service.h06-Dec-20171.2K
property_service_test.cpp06-Dec-20171.8K
README.md06-Dec-201726K
reboot.cpp06-Dec-201719.6K
reboot.h06-Dec-20171.3K
service.cpp06-Dec-201740.7K
service.h06-Dec-201710K
service_test.cpp06-Dec-20172.8K
signal_handler.cpp06-Dec-20171.9K
signal_handler.h06-Dec-2017810
test_service/06-Dec-2017
uevent.h06-Dec-20171,011
uevent_listener.cpp06-Dec-20176.9K
uevent_listener.h06-Dec-20171.8K
ueventd.cpp06-Dec-201711K
ueventd.h06-Dec-2017805
ueventd_parser.cpp06-Dec-20174.5K
ueventd_parser.h06-Dec-20171.7K
ueventd_test.cpp06-Dec-20174K
util.cpp06-Dec-201712.5K
util.h06-Dec-20172.5K
util_test.cpp06-Dec-20176.4K
watchdogd.cpp06-Dec-20172.2K
watchdogd.h06-Dec-2017811

README.md

      1 Android Init Language
      2 ---------------------
      3 
      4 The Android Init Language consists of five broad classes of statements:
      5 Actions, Commands, Services, Options, and Imports.
      6 
      7 All of these are line-oriented, consisting of tokens separated by
      8 whitespace.  The c-style backslash escapes may be used to insert
      9 whitespace into a token.  Double quotes may also be used to prevent
     10 whitespace from breaking text into multiple tokens.  The backslash,
     11 when it is the last character on a line, may be used for line-folding.
     12 
     13 Lines which start with a # (leading whitespace allowed) are comments.
     14 
     15 Actions and Services implicitly declare a new section.  All commands
     16 or options belong to the section most recently declared.  Commands
     17 or options before the first section are ignored.
     18 
     19 Services have unique names.  If a second Service is defined
     20 with the same name as an existing one, it is ignored and an error
     21 message is logged.
     22 
     23 
     24 Init .rc Files
     25 --------------
     26 The init language is used in plain text files that take the .rc file
     27 extension.  There are typically multiple of these in multiple
     28 locations on the system, described below.
     29 
     30 /init.rc is the primary .rc file and is loaded by the init executable
     31 at the beginning of its execution.  It is responsible for the initial
     32 set up of the system.
     33 
     34 Devices that mount /system, /vendor through the first stage mount mechanism
     35 load all of the files contained within the
     36 /{system,vendor,odm}/etc/init/ directories immediately after loading
     37 the primary /init.rc.  This is explained in more details in the
     38 Imports section of this file.
     39 
     40 Legacy devices without the first stage mount mechanism do the following:
     41 1. /init.rc imports /init.${ro.hardware}.rc which is the primary
     42    vendor supplied .rc file.
     43 2. During the mount\_all command, the init executable loads all of the
     44    files contained within the /{system,vendor,odm}/etc/init/ directories.
     45    These directories are intended for all Actions and Services used after
     46    file system mounting.
     47 
     48 One may specify paths in the mount\_all command line to have it import
     49 .rc files at the specified paths instead of the default ones listed above.
     50 This is primarily for supporting factory mode and other non-standard boot
     51 modes.  The three default paths should be used for the normal boot process.
     52 
     53 The intention of these directories is:
     54 
     55    1. /system/etc/init/ is for core system items such as
     56       SurfaceFlinger, MediaService, and logcatd.
     57    2. /vendor/etc/init/ is for SoC vendor items such as actions or
     58       daemons needed for core SoC functionality.
     59    3. /odm/etc/init/ is for device manufacturer items such as
     60       actions or daemons needed for motion sensor or other peripheral
     61       functionality.
     62 
     63 All services whose binaries reside on the system, vendor, or odm
     64 partitions should have their service entries placed into a
     65 corresponding init .rc file, located in the /etc/init/
     66 directory of the partition where they reside.  There is a build
     67 system macro, LOCAL\_INIT\_RC, that handles this for developers.  Each
     68 init .rc file should additionally contain any actions associated with
     69 its service.
     70 
     71 An example is the logcatd.rc and Android.mk files located in the
     72 system/core/logcat directory.  The LOCAL\_INIT\_RC macro in the
     73 Android.mk file places logcatd.rc in /system/etc/init/ during the
     74 build process.  Init loads logcatd.rc during the mount\_all command and
     75 allows the service to be run and the action to be queued when
     76 appropriate.
     77 
     78 This break up of init .rc files according to their daemon is preferred
     79 to the previously used monolithic init .rc files.  This approach
     80 ensures that the only service entries that init reads and the only
     81 actions that init performs correspond to services whose binaries are in
     82 fact present on the file system, which was not the case with the
     83 monolithic init .rc files.  This additionally will aid in merge
     84 conflict resolution when multiple services are added to the system, as
     85 each one will go into a separate file.
     86 
     87 There are two options "early" and "late" in mount\_all command
     88 which can be set after optional paths. With "--early" set, the
     89 init executable will skip mounting entries with "latemount" flag
     90 and triggering fs encryption state event. With "--late" set,
     91 init executable will only mount entries with "latemount" flag but skip
     92 importing rc files. By default, no option is set, and mount\_all will
     93 process all entries in the given fstab.
     94 
     95 Actions
     96 -------
     97 Actions are named sequences of commands.  Actions have a trigger which
     98 is used to determine when the action is executed.  When an event
     99 occurs which matches an action's trigger, that action is added to
    100 the tail of a to-be-executed queue (unless it is already on the
    101 queue).
    102 
    103 Each action in the queue is dequeued in sequence and each command in
    104 that action is executed in sequence.  Init handles other activities
    105 (device creation/destruction, property setting, process restarting)
    106 "between" the execution of the commands in activities.
    107 
    108 Actions take the form of:
    109 
    110     on <trigger> [&& <trigger>]*
    111        <command>
    112        <command>
    113        <command>
    114 
    115 Actions are added to the queue and executed based on the order that
    116 the file that contains them was parsed (see the Imports section), then
    117 sequentially within an individual file.
    118 
    119 For example if a file contains:
    120 
    121     on boot
    122        setprop a 1
    123        setprop b 2
    124 
    125     on boot && property:true=true
    126        setprop c 1
    127        setprop d 2
    128 
    129     on boot
    130        setprop e 1
    131        setprop f 2
    132 
    133 Then when the `boot` trigger occurs and assuming the property `true`
    134 equals `true`, then the order of the commands executed will be:
    135 
    136     setprop a 1
    137     setprop b 2
    138     setprop c 1
    139     setprop d 2
    140     setprop e 1
    141     setprop f 2
    142 
    143 
    144 Services
    145 --------
    146 Services are programs which init launches and (optionally) restarts
    147 when they exit.  Services take the form of:
    148 
    149     service <name> <pathname> [ <argument> ]*
    150        <option>
    151        <option>
    152        ...
    153 
    154 
    155 Options
    156 -------
    157 Options are modifiers to services.  They affect how and when init
    158 runs the service.
    159 
    160 `console [<console>]`
    161 > This service needs a console. The optional second parameter chooses a
    162   specific console instead of the default. The default "/dev/console" can
    163   be changed by setting the "androidboot.console" kernel parameter. In
    164   all cases the leading "/dev/" should be omitted, so "/dev/tty0" would be
    165   specified as just "console tty0".
    166 
    167 `critical`
    168 > This is a device-critical service. If it exits more than four times in
    169   four minutes, the device will reboot into recovery mode.
    170 
    171 `disabled`
    172 > This service will not automatically start with its class.
    173   It must be explicitly started by name.
    174 
    175 `setenv <name> <value>`
    176 > Set the environment variable _name_ to _value_ in the launched process.
    177 
    178 `socket <name> <type> <perm> [ <user> [ <group> [ <seclabel> ] ] ]`
    179 > Create a unix domain socket named /dev/socket/_name_ and pass its fd to the
    180   launched process.  _type_ must be "dgram", "stream" or "seqpacket".  User and
    181   group default to 0.  'seclabel' is the SELinux security context for the
    182   socket.  It defaults to the service security context, as specified by
    183   seclabel or computed based on the service executable file security context.
    184   For native executables see libcutils android\_get\_control\_socket().
    185 
    186 `file <path> <type>`
    187 > Open a file path and pass its fd to the launched process. _type_ must be
    188   "r", "w" or "rw".  For native executables see libcutils
    189   android\_get\_control\_file().
    190 
    191 `user <username>`
    192 > Change to 'username' before exec'ing this service.
    193   Currently defaults to root.  (??? probably should default to nobody)
    194   As of Android M, processes should use this option even if they
    195   require Linux capabilities.  Previously, to acquire Linux
    196   capabilities, a process would need to run as root, request the
    197   capabilities, then drop to its desired uid.  There is a new
    198   mechanism through fs\_config that allows device manufacturers to add
    199   Linux capabilities to specific binaries on a file system that should
    200   be used instead. This mechanism is described on
    201   <http://source.android.com/devices/tech/config/filesystem.html>.  When
    202   using this new mechanism, processes can use the user option to
    203   select their desired uid without ever running as root.
    204   As of Android O, processes can also request capabilities directly in their .rc
    205   files. See the "capabilities" option below.
    206 
    207 `group <groupname> [ <groupname>\* ]`
    208 > Change to 'groupname' before exec'ing this service.  Additional
    209   groupnames beyond the (required) first one are used to set the
    210   supplemental groups of the process (via setgroups()).
    211   Currently defaults to root.  (??? probably should default to nobody)
    212 
    213 `capabilities <capability> [ <capability>\* ]`
    214 > Set capabilities when exec'ing this service. 'capability' should be a Linux
    215   capability without the "CAP\_" prefix, like "NET\_ADMIN" or "SETPCAP". See
    216   http://man7.org/linux/man-pages/man7/capabilities.7.html for a list of Linux
    217   capabilities.
    218 
    219 `seclabel <seclabel>`
    220 > Change to 'seclabel' before exec'ing this service.
    221   Primarily for use by services run from the rootfs, e.g. ueventd, adbd.
    222   Services on the system partition can instead use policy-defined transitions
    223   based on their file security context.
    224   If not specified and no transition is defined in policy, defaults to the init context.
    225 
    226 `oneshot`
    227 > Do not restart the service when it exits.
    228 
    229 `class <name> [ <name>\* ]`
    230 > Specify class names for the service.  All services in a
    231   named class may be started or stopped together.  A service
    232   is in the class "default" if one is not specified via the
    233   class option. Additional classnames beyond the (required) first
    234   one are used to group services.
    235 `animation class`
    236 > 'animation' class should include all services necessary for both
    237   boot animation and shutdown animation. As these services can be
    238   launched very early during bootup and can run until the last stage
    239   of shutdown, access to /data partition is not guaranteed. These
    240   services can check files under /data but it should not keep files opened
    241   and should work when /data is not available.
    242 
    243 `onrestart`
    244 > Execute a Command (see below) when service restarts.
    245 
    246 `writepid <file> [ <file>\* ]`
    247 > Write the child's pid to the given files when it forks. Meant for
    248   cgroup/cpuset usage. If no files under /dev/cpuset/ are specified, but the
    249   system property 'ro.cpuset.default' is set to a non-empty cpuset name (e.g.
    250   '/foreground'), then the pid is written to file /dev/cpuset/_cpuset\_name_/tasks.
    251 
    252 `priority <priority>`
    253 > Scheduling priority of the service process. This value has to be in range
    254   -20 to 19. Default priority is 0. Priority is set via setpriority().
    255 
    256 `namespace <pid|mnt>`
    257 > Enter a new PID or mount namespace when forking the service.
    258 
    259 `oom_score_adjust <value>`
    260 > Sets the child's /proc/self/oom\_score\_adj to the specified value,
    261   which must range from -1000 to 1000.
    262 
    263 `memcg.swappiness <value>`
    264 > Sets the child's memory.swappiness to the specified value (only if memcg is mounted),
    265   which must be equal or greater than 0.
    266 
    267 `memcg.soft_limit_in_bytes <value>`
    268 > Sets the child's memory.soft_limit_in_bytes to the specified value (only if memcg is mounted),
    269   which must be equal or greater than 0.
    270 
    271 `memcg.limit_in_bytes <value>`
    272 > Sets the child's memory.limit_in_bytes to the specified value (only if memcg is mounted),
    273   which must be equal or greater than 0.
    274 
    275 `shutdown <shutdown_behavior>`
    276 > Set shutdown behavior of the service process. When this is not specified,
    277   the service is killed during shutdown process by using SIGTERM and SIGKILL.
    278   The service with shutdown_behavior of "critical" is not killed during shutdown
    279   until shutdown times out. When shutdown times out, even services tagged with
    280   "shutdown critical" will be killed. When the service tagged with "shutdown critical"
    281   is not running when shut down starts, it will be started.
    282 
    283 
    284 Triggers
    285 --------
    286 Triggers are strings which can be used to match certain kinds of
    287 events and used to cause an action to occur.
    288 
    289 Triggers are subdivided into event triggers and property triggers.
    290 
    291 Event triggers are strings triggered by the 'trigger' command or by
    292 the QueueEventTrigger() function within the init executable.  These
    293 take the form of a simple string such as 'boot' or 'late-init'.
    294 
    295 Property triggers are strings triggered when a named property changes
    296 value to a given new value or when a named property changes value to
    297 any new value.  These take the form of 'property:<name>=<value>' and
    298 'property:<name>=\*' respectively.  Property triggers are additionally
    299 evaluated and triggered accordingly during the initial boot phase of
    300 init.
    301 
    302 An Action can have multiple property triggers but may only have one
    303 event trigger.
    304 
    305 For example:
    306 `on boot && property:a=b` defines an action that is only executed when
    307 the 'boot' event trigger happens and the property a equals b.
    308 
    309 `on property:a=b && property:c=d` defines an action that is executed
    310 at three times:
    311 
    312    1. During initial boot if property a=b and property c=d.
    313    2. Any time that property a transitions to value b, while property c already equals d.
    314    3. Any time that property c transitions to value d, while property a already equals b.
    315 
    316 
    317 Commands
    318 --------
    319 
    320 `bootchart [start|stop]`
    321 > Start/stop bootcharting. These are present in the default init.rc files,
    322   but bootcharting is only active if the file /data/bootchart/enabled exists;
    323   otherwise bootchart start/stop are no-ops.
    324 
    325 `chmod <octal-mode> <path>`
    326 > Change file access permissions.
    327 
    328 `chown <owner> <group> <path>`
    329 > Change file owner and group.
    330 
    331 `class_start <serviceclass>`
    332 > Start all services of the specified class if they are
    333   not already running.  See the start entry for more information on
    334   starting services.
    335 
    336 `class_stop <serviceclass>`
    337 > Stop and disable all services of the specified class if they are
    338   currently running.
    339 
    340 `class_reset <serviceclass>`
    341 > Stop all services of the specified class if they are
    342   currently running, without disabling them. They can be restarted
    343   later using `class_start`.
    344 
    345 `class_restart <serviceclass>`
    346 > Restarts all services of the specified class.
    347 
    348 `copy <src> <dst>`
    349 > Copies a file. Similar to write, but useful for binary/large
    350   amounts of data.
    351   Regarding to the src file, copying from symbolic link file and world-writable
    352   or group-writable files are not allowed.
    353   Regarding to the dst file, the default mode created is 0600 if it does not
    354   exist. And it will be truncated if dst file is a normal regular file and
    355   already exists.
    356 
    357 `domainname <name>`
    358 > Set the domain name.
    359 
    360 `enable <servicename>`
    361 > Turns a disabled service into an enabled one as if the service did not
    362   specify disabled.
    363   If the service is supposed to be running, it will be started now.
    364   Typically used when the bootloader sets a variable that indicates a specific
    365   service should be started when needed. E.g.
    366 
    367     on property:ro.boot.myfancyhardware=1
    368         enable my_fancy_service_for_my_fancy_hardware
    369 
    370 `exec [ <seclabel> [ <user> [ <group>\* ] ] ] -- <command> [ <argument>\* ]`
    371 > Fork and execute command with the given arguments. The command starts
    372   after "--" so that an optional security context, user, and supplementary
    373   groups can be provided. No other commands will be run until this one
    374   finishes. _seclabel_ can be a - to denote default. Properties are expanded
    375   within _argument_.
    376   Init halts executing commands until the forked process exits.
    377 
    378 `exec_start <service>`
    379 > Start a given service and halt the processing of additional init commands
    380   until it returns.  The command functions similarly to the `exec` command,
    381   but uses an existing service definition in place of the exec argument vector.
    382 
    383 `export <name> <value>`
    384 > Set the environment variable _name_ equal to _value_ in the
    385   global environment (which will be inherited by all processes
    386   started after this command is executed)
    387 
    388 `hostname <name>`
    389 > Set the host name.
    390 
    391 `ifup <interface>`
    392 > Bring the network interface _interface_ online.
    393 
    394 `insmod [-f] <path> [<options>]`
    395 > Install the module at _path_ with the specified options.
    396   -f: force installation of the module even if the version of the running kernel
    397   and the version of the kernel for which the module was compiled do not match.
    398 
    399 `load_all_props`
    400 > Loads properties from /system, /vendor, et cetera.
    401   This is included in the default init.rc.
    402 
    403 `load_persist_props`
    404 > Loads persistent properties when /data has been decrypted.
    405   This is included in the default init.rc.
    406 
    407 `loglevel <level>`
    408 > Sets the kernel log level to level. Properties are expanded within _level_.
    409 
    410 `mkdir <path> [mode] [owner] [group]`
    411 > Create a directory at _path_, optionally with the given mode, owner, and
    412   group. If not provided, the directory is created with permissions 755 and
    413   owned by the root user and root group. If provided, the mode, owner and group
    414   will be updated if the directory exists already.
    415 
    416 `mount_all <fstab> [ <path> ]\* [--<option>]`
    417 > Calls fs\_mgr\_mount\_all on the given fs\_mgr-format fstab and imports .rc files
    418   at the specified paths (e.g., on the partitions just mounted) with optional
    419   options "early" and "late".
    420   Refer to the section of "Init .rc Files" for detail.
    421 
    422 `mount <type> <device> <dir> [ <flag>\* ] [<options>]`
    423 > Attempt to mount the named device at the directory _dir_
    424   _flag_s include "ro", "rw", "remount", "noatime", ...
    425   _options_ include "barrier=1", "noauto\_da\_alloc", "discard", ... as
    426   a comma separated string, eg: barrier=1,noauto\_da\_alloc
    427 
    428 `restart <service>`
    429 > Stops and restarts a running service, does nothing if the service is currently
    430   restarting, otherwise, it just starts the service.
    431 
    432 `restorecon <path> [ <path>\* ]`
    433 > Restore the file named by _path_ to the security context specified
    434   in the file\_contexts configuration.
    435   Not required for directories created by the init.rc as these are
    436   automatically labeled correctly by init.
    437 
    438 `restorecon_recursive <path> [ <path>\* ]`
    439 > Recursively restore the directory tree named by _path_ to the
    440   security contexts specified in the file\_contexts configuration.
    441 
    442 `rm <path>`
    443 > Calls unlink(2) on the given path. You might want to
    444   use "exec -- rm ..." instead (provided the system partition is
    445   already mounted).
    446 
    447 `rmdir <path>`
    448 > Calls rmdir(2) on the given path.
    449 
    450 `setprop <name> <value>`
    451 > Set system property _name_ to _value_. Properties are expanded
    452   within _value_.
    453 
    454 `setrlimit <resource> <cur> <max>`
    455 > Set the rlimit for a resource.
    456 
    457 `start <service>`
    458 > Start a service running if it is not already running.
    459   Note that this is _not_ synchronous, and even if it were, there is
    460   no guarantee that the operating system's scheduler will execute the
    461   service sufficiently to guarantee anything about the service's status.
    462 
    463 > This creates an important consequence that if the service offers
    464   functionality to other services, such as providing a
    465   communication channel, simply starting this service before those
    466   services is _not_ sufficient to guarantee that the channel has
    467   been set up before those services ask for it.  There must be a
    468   separate mechanism to make any such guarantees.
    469 
    470 `stop <service>`
    471 > Stop a service from running if it is currently running.
    472 
    473 `swapon_all <fstab>`
    474 > Calls fs\_mgr\_swapon\_all on the given fstab file.
    475 
    476 `symlink <target> <path>`
    477 > Create a symbolic link at _path_ with the value _target_
    478 
    479 `sysclktz <mins_west_of_gmt>`
    480 > Set the system clock base (0 if system clock ticks in GMT)
    481 
    482 `trigger <event>`
    483 > Trigger an event.  Used to queue an action from another
    484   action.
    485 
    486 `umount <path>`
    487 > Unmount the filesystem mounted at that path.
    488 
    489 `verity_load_state`
    490 > Internal implementation detail used to load dm-verity state.
    491 
    492 `verity_update_state <mount-point>`
    493 > Internal implementation detail used to update dm-verity state and
    494   set the partition._mount-point_.verified properties used by adb remount
    495   because fs\_mgr can't set them directly itself.
    496 
    497 `wait <path> [ <timeout> ]`
    498 > Poll for the existence of the given file and return when found,
    499   or the timeout has been reached. If timeout is not specified it
    500   currently defaults to five seconds.
    501 
    502 `wait_for_prop <name> <value>`
    503 > Wait for system property _name_ to be _value_. Properties are expanded
    504   within _value_. If property _name_ is already set to _value_, continue
    505   immediately.
    506 
    507 `write <path> <content>`
    508 > Open the file at _path_ and write a string to it with write(2).
    509   If the file does not exist, it will be created. If it does exist,
    510   it will be truncated. Properties are expanded within _content_.
    511 
    512 
    513 Imports
    514 -------
    515 `import <path>`
    516 > Parse an init config file, extending the current configuration.
    517   If _path_ is a directory, each file in the directory is parsed as
    518   a config file. It is not recursive, nested directories will
    519   not be parsed.
    520 
    521 The import keyword is not a command, but rather its own section,
    522 meaning that it does not happen as part of an Action, but rather,
    523 imports are handled as a file is being parsed and follow the below logic.
    524 
    525 There are only three times where the init executable imports .rc files:
    526 
    527    1. When it imports /init.rc or the script indicated by the property
    528       `ro.boot.init_rc` during initial boot.
    529    2. When it imports /{system,vendor,odm}/etc/init/ for first stage mount
    530       devices immediately after importing /init.rc.
    531    3. When it imports /{system,vendor,odm}/etc/init/ or .rc files at specified
    532       paths during mount_all.
    533 
    534 The order that files are imported is a bit complex for legacy reasons
    535 and to keep backwards compatibility.  It is not strictly guaranteed.
    536 
    537 The only correct way to guarantee that a command has been run before a
    538 different command is to either 1) place it in an Action with an
    539 earlier executed trigger, or 2) place it in an Action with the same
    540 trigger within the same file at an earlier line.
    541 
    542 Nonetheless, the defacto order for first stage mount devices is:
    543 1. /init.rc is parsed then recursively each of its imports are
    544    parsed.
    545 2. The contents of /system/etc/init/ are alphabetized and parsed
    546    sequentially, with imports happening recursively after each file is
    547    parsed.
    548 3. Step 2 is repeated for /vendor/etc/init then /odm/etc/init
    549 
    550 The below pseudocode may explain this more clearly:
    551 
    552     fn Import(file)
    553       Parse(file)
    554       for (import : file.imports)
    555         Import(import)
    556 
    557     Import(/init.rc)
    558     Directories = [/system/etc/init, /vendor/etc/init, /odm/etc/init]
    559     for (directory : Directories)
    560       files = <Alphabetical order of directory's contents>
    561       for (file : files)
    562         Import(file)
    563 
    564 
    565 Properties
    566 ----------
    567 Init provides information about the services that it is responsible
    568 for via the below properties.
    569 
    570 `init.svc.<name>`
    571 > State of a named service ("stopped", "stopping", "running", "restarting")
    572 
    573 
    574 Boot timing
    575 -----------
    576 Init records some boot timing information in system properties.
    577 
    578 `ro.boottime.init`
    579 > Time after boot in ns (via the CLOCK\_BOOTTIME clock) at which the first
    580   stage of init started.
    581 
    582 `ro.boottime.init.selinux`
    583 > How long it took the first stage to initialize SELinux.
    584 
    585 `ro.boottime.init.cold_boot_wait`
    586 > How long init waited for ueventd's coldboot phase to end.
    587 
    588 `ro.boottime.<service-name>`
    589 > Time after boot in ns (via the CLOCK\_BOOTTIME clock) that the service was
    590   first started.
    591 
    592 
    593 Bootcharting
    594 ------------
    595 This version of init contains code to perform "bootcharting": generating log
    596 files that can be later processed by the tools provided by <http://www.bootchart.org/>.
    597 
    598 On the emulator, use the -bootchart _timeout_ option to boot with bootcharting
    599 activated for _timeout_ seconds.
    600 
    601 On a device:
    602 
    603     adb shell 'touch /data/bootchart/enabled'
    604 
    605 Don't forget to delete this file when you're done collecting data!
    606 
    607 The log files are written to /data/bootchart/. A script is provided to
    608 retrieve them and create a bootchart.tgz file that can be used with the
    609 bootchart command-line utility:
    610 
    611     sudo apt-get install pybootchartgui
    612     # grab-bootchart.sh uses $ANDROID_SERIAL.
    613     $ANDROID_BUILD_TOP/system/core/init/grab-bootchart.sh
    614 
    615 One thing to watch for is that the bootchart will show init as if it started
    616 running at 0s. You'll have to look at dmesg to work out when the kernel
    617 actually started init.
    618 
    619 
    620 Comparing two bootcharts
    621 ------------------------
    622 A handy script named compare-bootcharts.py can be used to compare the
    623 start/end time of selected processes. The aforementioned grab-bootchart.sh
    624 will leave a bootchart tarball named bootchart.tgz at /tmp/android-bootchart.
    625 If two such barballs are preserved on the host machine under different
    626 directories, the script can list the timestamps differences. For example:
    627 
    628 Usage: system/core/init/compare-bootcharts.py _base-bootchart-dir_ _exp-bootchart-dir_
    629 
    630     process: baseline experiment (delta) - Unit is ms (a jiffy is 10 ms on the system)
    631     ------------------------------------
    632     /init: 50 40 (-10)
    633     /system/bin/surfaceflinger: 4320 4470 (+150)
    634     /system/bin/bootanimation: 6980 6990 (+10)
    635     zygote64: 10410 10640 (+230)
    636     zygote: 10410 10640 (+230)
    637     system_server: 15350 15150 (-200)
    638     bootanimation ends at: 33790 31230 (-2560)
    639 
    640 
    641 Systrace
    642 --------
    643 Systrace (<http://developer.android.com/tools/help/systrace.html>) can be
    644 used for obtaining performance analysis reports during boot
    645 time on userdebug or eng builds.
    646 
    647 Here is an example of trace events of "wm" and "am" categories:
    648 
    649     $ANDROID_BUILD_TOP/external/chromium-trace/systrace.py \
    650           wm am --boot
    651 
    652 This command will cause the device to reboot. After the device is rebooted and
    653 the boot sequence has finished, the trace report is obtained from the device
    654 and written as trace.html on the host by hitting Ctrl+C.
    655 
    656 Limitation: recording trace events is started after persistent properties are loaded, so
    657 the trace events that are emitted before that are not recorded. Several
    658 services such as vold, surfaceflinger, and servicemanager are affected by this
    659 limitation since they are started before persistent properties are loaded.
    660 Zygote initialization and the processes that are forked from the zygote are not
    661 affected.
    662 
    663 
    664 Debugging init
    665 --------------
    666 By default, programs executed by init will drop stdout and stderr into
    667 /dev/null. To help with debugging, you can execute your program via the
    668 Android program logwrapper. This will redirect stdout/stderr into the
    669 Android logging system (accessed via logcat).
    670 
    671 For example
    672 service akmd /system/bin/logwrapper /sbin/akmd
    673 
    674 For quicker turnaround when working on init itself, use:
    675 
    676     mm -j &&
    677     m ramdisk-nodeps &&
    678     m bootimage-nodeps &&
    679     adb reboot bootloader &&
    680     fastboot boot $ANDROID_PRODUCT_OUT/boot.img
    681 
    682 Alternatively, use the emulator:
    683 
    684     emulator -partition-size 1024 \
    685         -verbose -show-kernel -no-window
    686