第三篇了,前面两篇写的有点短,今天准备写长一点,言归正传开始工作
devfs_automounted="no" if [ -e "/dev/.devfsd" ] then mymounts="$(awk '($3 == "devfs") { print "yes"; exit 0 }' /proc/mounts)" if [ "${mymounts}" != "yes" ] then rm -f /dev/.devfsd else devfs_automounted="yes" fi fi
|
这段为的是修正bug用的,具体为什么,还没有弄清楚,跳过这段,我们接下来看
if [ "${RC_DEVICES}" = "static" ] then ebegin "Using existing device nodes in /dev" eend 0 else fellback_to_devfs="no" case "${RC_DEVICES}" in devfs) devfs="yes" udev="no" ;; udev) devfs="yes" udev="yes" fellback_to_devfs="yes" ;; auto|*) devfs="yes" udev="yes" ;; esac
if [ "${udev}" = "yes" ] then if get_bootparam "noudev" || ! has_addon udev-start.sh || \ [ ${devfs_automounted} = "yes" ] || \ [ "$(get_KV)" -lt "$(KV_to_int '2.6.0')" ] then udev="no" fi fi
if [ "${devfs}" = "yes" ] then if get_bootparam "nodevfs" || [ "${udev}" = "yes" ] || \ ! has_addon devfs-start.sh then devfs="no" fi fi
if [[ ${udev} == "yes" ]] ; then start_addon udev
elif [[ ${devfs} == "yes" ]] ; then start_addon devfs
if [[ ${fellback_to_devfs} == "yes" ]] ; then ewarn "You wanted udev but support for it was not available!" ewarn "Please review your system after it's booted!" fi fi
if [[ ${devfs} == "no" && ${udev} == "no" ]] ; then echo einfo "The Gentoo Linux system initialization scripts have detected that" einfo "your system does not support UDEV. Since Gentoo Linux has been" einfo "designed with dynamic /dev in mind, it is highly suggested that you" einfo "emerge sys-fs/udev and configure your system to use it." einfo "Please read the Gentoo Handbook for more information!" echo einfo " " echo einfo "Thanks for using Gentoo! :)" echo read -t 15 -p "(hit Enter to continue or wait 15 seconds ...)" fi fi
|
首先还是一个变量RC_DEVICES,这个变量是值是在/etc/init.d/rc里面的定义为auto,明显auto!=static所以,进入else的分支,先给变量fellback_to_devfs赋值为no,然后根据RC_DEVICES的值进行case分支语句,判断后得到 devfs="yes",udev="yes",然后通过这两个变量的值进行处理,下面介绍一些处理过程中的几个函数:1,get_bootparam这个函数在/sbin/functions.sh里面
get_bootparam() { local x copt params retval=1
[[ ! -r /proc/cmdline ]] && return 1
for copt in $(< /proc/cmdline) ; do if [[ ${copt%=*} == "gentoo" ]] ; then params=$(gawk -v PARAMS="${copt##*=}" ' BEGIN { split(PARAMS, nodes, ",") for (x in nodes) print nodes[x] }')
# Parse gentoo option
for x in ${params} ; do if [[ ${x} == "$1" ]] ; then # echo "YES"
retval=0 fi done fi done
return ${retval} }
|
先是判断/proc/cmdline这个文件是否只读,我看了一下ls -l /proc/cmdline得到的结果是-r--r--r-- 1 root root 0 Apr 22 20:19 /proc/cmdline,显然是只读的,然后我们看一下/proc/cmdline的内容,cat /proc/cmdline,内容显示为root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root=/dev/sda3 doscsi,然后分析上面这个函数,这个函数的作用就是把/proc/cmdline中以空格分开的参数,和函数传入的第一个参数化比较,如果相同,那么就返回为0.
2,has_addon,这个函数在/sbin/functions.sh里面
has_addon() { [[ -e ${svclib}/addons/$1 ]] }
|
这个函数就是检查/lib/rcscripts/addons下面是否有has_addon传入第一个参数的文件.
在回到前面的代码看看处理过程:
if [ "${udev}" = "yes" ] then if get_bootparam "noudev" || ! has_addon udev-start.sh || \ [ ${devfs_automounted} = "yes" ] || \ [ "$(get_KV)" -lt "$(KV_to_int '2.6.0')" ] then udev="no" fi fi
|
根据前面的分析,可以检测到 udev_start.sh这个文件是有的,所以udev=yes
if [ "${devfs}" = "yes" ] then if get_bootparam "nodevfs" || [ "${udev}" = "yes" ] || \ ! has_addon devfs-start.sh then devfs="no" fi fi
|
同上devfs=yes,在下面一个重要的函数就是start_addon了,我们来看看,start_addon到底干了什么呢?
start_addon() { local addon="$1" (import_addon "${addon}-start.sh") return 0 } import_addon() { local addon="${svclib}/addons/$1" if has_addon $1 ; then source "${addon}" return 0 fi return 1 }
|
其实就是source一下/lib/rcscripts/addons/xxxx-start.sh.对应上面的代码就是source /lib/rcscripts/addons/udev-start.sh和devfs-start.sh
if [[ ${fellback_to_devfs} == "yes" ]] ;
if [[ ${devfs} == "no" && ${udev} == "no" ]];
|
这两个判断是不成立,根据上面的判断可以得到,如果这两个判断成立的话,说明出错误拉!!!!!!
昨天比较忙,没有及时更新,今天继续!!!!!!不过呢,马上就要出现一句经典的话了,各位观众,大家听好了To Be Continue!!!!!!!!!!!
阅读(1977) | 评论(0) | 转发(0) |