#200

#201 for(;;) {

#202 int nr, i, timeout = -1;

这段代码是进入死循环处理,以便这个init进程变成一个服务。

#203

#204 for (i = 0; i < fd_count; i++)

#205 ufds[i].revents = 0;

这段代码是清空每个socket的事件计数。

#206

#207 drain_action_queue();

这段代码是执行队列里的命令。

#208 restart_processes();

这句代码是用来判断那些服务需要重新启动。

#209

#210 if (process_needs_restart) {

#211 timeout = (process_needs_restart - gettime()) * 1000;

#212 if (timeout < 0)

#213 timeout = 0;

#214 }

这段代码是用来判断那些进程启动超时。

#215

#216 #if BOOTCHART

#217 if (bootchart_count > 0) {

#218 if (timeout < 0 || timeout > BOOTCHART_POLLING_MS)

#219 timeout = BOOTCHART_POLLING_MS;

#220 if (bootchart_step() < 0 || --bootchart_count == 0) {

#221 bootchart_finish();

#222 bootchart_count = 0;

#223 }

#224 }

#225 #endif

这段代码是用来计算运行性能。

#226 nr = poll(ufds, fd_count, timeout);

#227 if (nr <= 0)

#228 continue;

这段代码用来轮询几个socket是否有事件处理。

#229

#230 if (ufds[2].revents == POLLIN) {

#231 /* we got a SIGCHLD - reap and restart as needed */

#232 read(signal_recv_fd, tmp, sizeof(tmp));

#233 while (!wait_for_one_process(0))

#234 ;

#235 continue;

#236 }

这段代码是用来处理子进程的通讯,并且能删除任何已经退出或者杀死死进程,这样做可以保持系统更加健壮性,增强容错能力。

#237

#238 if (ufds[0].revents == POLLIN)

#239 handle_device_fd(device_fd);

这段代码是处理设备事件。

#240

#241 if (ufds[1].revents == POLLIN)

#242 handle_property_set_fd(property_set_fd);

这段代码是处理属性服务事件。

#243 if (ufds[3].revents == POLLIN)

#244 handle_keychord(keychord_fd);

这段代码是处理调试模式下的组合按键。

#245 }

#246

#247 return 0;

#248 }

#249

到这里已经分析完成init进程的主流程,后面再来详细地其它功能实现。

更多相关文章

  1. Android中写文本文件的方法
  2. Android(安卓)Settings 导入eclipse(含有调试好的源代码)
  3. Android学习心得(二)——短信服务
  4. Android:Eclipse如何设置格式化Java代码
  5. Android(安卓)PullToRefresh (ListView GridView 下拉刷新) 使用详
  6. Android(安卓)-- 点击双下返回退出程序
  7. android jni 理解
  8. android 比较有用的方法总结
  9. android中的alertdialog及LayoutInflater

随机推荐

  1. android实现图片压缩
  2. 去掉Android(安卓)app上的Title Bar
  3. Android(安卓)WakeLock
  4. android开发 drawable中XML
  5. 自己写的一个在线汇率转换工具-MoneyDroi
  6. Android(安卓)display架构分析(八)
  7. 详解 Android(安卓)的 Activity 组件
  8. Android(安卓)中文 API (19) —— TwoLineL
  9. Android反射机制实例
  10. eclipse android插件