First we see from init.c that when the init.rc file is parsed in Init, a series of actions are obtained, and some functions are called by action.
Zygote is in the service section of Init.rc
- service zygote /system /bin/app_process -xzygote /system/bin --zygote --start-system-server
the init.rc file is parsed in Parse_new_section () and is then added to the linked list.
Services that are defined by the Service keyword are added to the service_list linked list.
The keys at the beginning of the on key will be added to the action_list linked list.
1. Execute in INIT.C
Action_for_each_trigger ("boot",...); The creation of zygote starts with the boot phase.
Drain_action_queue ()
These are the commands in the Execute action_list:
Remove the act->name from the action_list, and then call Action_add_queue_tail (Act) to insert it into the queue action_queue tail.
Drain_action_queue () removes the queue item from the Action_list queue and executes all the commands in the Act->commands list.
Init.rc COMMAND:
Class_start Default
svc->classname = "Default" when added to the service_list linked list;
Default starts the services defined by all service keywords.
Class_start is triggered will call Do_class_start ();
2.do_class_start () will be executed in
Service_for_each_class (Args[1],..); Starts after getting the service from the Service_list list.
Service_start (SVC, NULL); the service_start_if_not_disabled is activated.
3. The Service_start () is then called
In this function, a process is forked out in init.
Create a socket based on Socketinfo (zygote stream 666).
Use the EXECVE function to execute the zygote executable file/system/bin/app_process.
So the main function of App_process is started up. That's zygote.
The zygote's start-up is done with this analysis.
Next, analyze Zygote's onrestart.
4. Restart Zygote
1. Sigchld_handler () is called when the child process (zygote) exits, and the function writes data to SIGNAL_FD.
2. The socket of the INIT process then receives the message. Will be returned from the poll function in Init.
(SIGNAL_FD is one of the two sockets created by Socketpair in Init.) )
3.flag is set to svc_restarting after the command in the Onresatart that executes the service.
When returned in 4.poll (), it enters a new loop and restarts all restarting SVC via flag.
Drain_action_queue ();
Restart_process ();
It was finally restarted by the Service_start function.
Zygote (app_process) correlation analysis