mini2440系统移植篇之init启动流程
扫描二维码
随时随地手机看文章
1.启动
内核启动应用程序/linuxrc
busyboxini.c
init_main
设置信号处理函数
初始化控制台
parse_inittab解析inittab
1.1.解析inittab
file=open(INITTAB,“r”); //打开配置文件/etc/inittab
new_init_action
//1创建一个init_action结构,填充
//2把结构放入init_action_list链表
默认配置
::sysinit:/etc/init.d/rcS
::askfirst:/bin/sh
tty2::askfirst:/bin/sh
tty3::askfirst:/bin/sh
tty4::askfirst:/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/sbin/swapoff-a
::shutdown:/bin/umount-a-r
::restart:/sbin/init
1.2.运行
/*Firstrunthesysinitcommand*/
run_actions(SYSINIT);
/*Nextrunanythingthatwantstoblock*/
run_actions(WAIT);
/*Nextrunanythingtoberunonlyonce*/
run_actions(ONCE);
/*Nowruntheloopingstufffortherestofforever*/
while(1){
/*runtherespawn/askfirststuff*/
run_actions(RESPAWN|ASKFIRST);
/*Don'tconsumeallCPUtime--sleepabit*/
sleep(1);
/*Waitforanychildprocesstoexit*/
wpid=wait(NULL);
while(wpid>0){
/*Findoutwhodiedandcleanuptheircorpse*/
for(a=init_action_list;a;a=a->next){
if(a->pid==wpid){
/*Setthepidto0sothattheprocessgets
*restartedbyrun_actions()*/
a->pid=0;
message(L_LOG,"process'%s'(pid%d)exited."
"Schedulingforrestart.",
a->command,wpid);
}
}
/*seeifanyoneelseiswaitingtobereaped*/
wpid=wait_any_nohang(NULL);
}
}