Android 根文件系统启动分析
2010-05-08 18:36:00 来源:WEB开发网核心提示:action_for_each_trigger("init", action_add_queue_tail); drain_action_queue(); property_set_fd = start_property_service(); /* 为sigchld handler创建信号机制*/
action_for_each_trigger("init", action_add_queue_tail); drain_action_queue();
property_set_fd = start_property_service(); /* 为sigchld handler创建信号机制*/ if
(socketpair(AF_UNIX, SOCK_STREAM, 0, s) == 0) { signal_fd = s[0]; signal_recv_fd
= s[1]; fcntl(s[0], F_SETFD, FD_CLOEXEC); fcntl(s[0], F_SETFL, O_NONBLOCK);
fcntl(s[1], F_SETFD, FD_CLOEXEC); fcntl(s[1], F_SETFL, O_NONBLOCK); } /*
确认所有初始化工作完成 * device_fd(device init 完成) * property_set_fd(property server start
完成) * signal_recv_fd (信号机制建立) */ if ((device_fd < 0) || (property_set_fd <
0) || (signal_recv_fd < 0)) { ERROR("init startup failure
"); return 1; } /*
execute all the boot actions to get us started */
action_for_each_trigger("early-boot", action_add_queue_tail);
action_for_each_trigger("boot", action_add_queue_tail); drain_action_queue(); /*
run all property triggers based on current state of the properties */
queue_all_property_triggers(); drain_action_queue(); /* enable property triggers
*/ property_triggers_enabled = 1; /* * 注册轮询事件: * - device_fd * - property_set_fd
* -signal_recv_fd * -如果有keychord,则注册keychord_fd */ ufds[0].fd = device_fd;
ufds[0].events = POLLIN; ufds[1].fd = property_set_fd; ufds[1].events = POLLIN;
ufds[2].fd = signal_recv_fd; ufds[2].events = POLLIN; fd_count = 3; if
(keychord_fd > 0) { ufds[3].fd = keychord_fd; ufds[3].events = POLLIN;
fd_count++; } else { ufds[3].events = 0; ufds[3].revents = 0;
}/*如果支持BOOTCHART,则初始化BOOTCHART*/#if BOOTCHART bootchart_count =
bootchart_init(); if (bootchart_count < 0) { ERROR("bootcharting init
failure
"); } else if (bootchart_count > 0) { NOTICE("bootcharting started
(period=%d ms)
", bootchart_count*BOOTCHART_POLLING_MS); } else {
NOTICE("bootcharting ignored
"); }#endif /* *进入主进程循环: * - 重置轮询事件的接受状态,revents为0
* - 查询action队列并执行。 * - 重启需要重启的服务 * - 轮询注册的事件 * -
如果signal_recv_fd的revents为POLLIN,则得到一个信号,获取并处理 * -
[]
更多精彩
赞助商链接