mini2440系統(tǒng)移植篇之init啟動(dòng)流程
掃描二維碼
隨時(shí)隨地手機(jī)看文章
1.啟動(dòng)
內(nèi)核啟動(dòng)應(yīng)用程序/linuxrc
busyboxini.c
init_main
設(shè)置信號(hào)處理函數(shù)
初始化控制臺(tái)
parse_inittab解析inittab
1.1.解析inittab
file=open(INITTAB,“r”); //打開配置文件/etc/inittab
new_init_action
//1創(chuàng)建一個(gè)init_action結(jié)構(gòu),填充
//2把結(jié)構(gòu)放入init_action_list鏈表
默認(rèn)配置
::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.運(yùn)行
/*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);
}
}