root@camdroid:/ # kill 171
[ 784.291790] init: waitpid returned pid 171, status = 0000000f
root@camdroid:/ # [ 784.300328] init: process 'vold', pid 171 exited
[ 784.307033] init: process 'vold' killing any children in process group
[ 784.320106] init: starting 'vold'
[ 784.325261] init: Created socket '/dev/socket/vold' with mode '660', user '0', group '1009'
杀死 vold 之后, 又重新建立了一个
离线
看了一下, vold 的 PPID 是 /init 进程
root@camdroid:/ # ps
USER PID PPID VSIZE RSS WCHAN PC NAME
root 1 0 312 180 c0031a80 0001a398 S /init
root 2 0 0 0 c0046c08 00000000 S kthreadd
root 3 2 0 0 c0033d74 00000000 S ksoftirqd/0
root 6 2 0 0 c004265c 00000000 S khelper
root 7 2 0 0 c01a19c0 00000000 S kdevtmpfs
root 8 2 0 0 c007df88 00000000 S sync_supers
root 9 2 0 0 c007ecdc 00000000 S bdi-default
root 10 2 0 0 c004265c 00000000 S kblockd
root 11 2 0 0 c0198044 00000000 S sytem
root 12 2 0 0 c01de184 00000000 S khubd
root 14 2 0 0 c004265c 00000000 S cfg80211
root 16 2 0 0 c006494c 00000000 S khungtaskd
root 17 2 0 0 c0079924 00000000 S kswapd0
root 18 2 0 0 c00c1c20 00000000 S fsnotify_mark
root 19 2 0 0 c0043260 00000000 S kworker/u:1
root 28 2 0 0 c004265c 00000000 S SunxiDisCommit
root 29 2 0 0 c004265c 00000000 S Sunxi_WB
root 30 2 0 0 c019493c 00000000 S kapmd
root 31 2 0 0 c004265c 00000000 S spi.0
root 36 2 0 0 c01c4414 00000000 S mtdblock0
root 37 2 0 0 c01c4414 00000000 S mtdblock1
root 38 2 0 0 c01c4414 00000000 S mtdblock2
root 39 2 0 0 c01c4414 00000000 S mtdblock3
root 40 2 0 0 c01c4414 00000000 S mtdblock4
root 41 2 0 0 c01c4414 00000000 S mtdblock5
root 42 2 0 0 c01c4414 00000000 S mtdblock6
root 43 2 0 0 c01c4414 00000000 S mtdblock7
root 50 2 0 0 c004265c 00000000 S f_mtp
root 51 2 0 0 c01ff924 00000000 S file-storage
root 52 2 0 0 c025e17c 00000000 S cfinteractive
root 53 2 0 0 c004265c 00000000 S binder
root 54 2 0 0 c004265c 00000000 S switch_resume
root 55 2 0 0 c004265c 00000000 S codec_init
root 56 2 0 0 c004265c 00000000 S deferwq
root 59 1 348 188 c00a1044 0000efd8 S /sbin/ueventd
root 60 1 392 240 c00a1044 0000efd8 S /init
root 61 2 0 0 c00f6cdc 00000000 S jffs2_gcd_mtd3
root 63 2 0 0 c004265c 00000000 S sw_wq
system 64 60 888 320 c02869fc 400f20d8 S /system/bin/servicemanager
root 66 60 38092 3832 ffffffff 400df0d8 S /system/bin/mediaserver
root 68 60 22260 4452 ffffffff 40156260 S /system/bin/ccdr
root 69 60 3448 180 ffffffff 000160cc S /sbin/adbd
root 70 60 932 388 c02be3b8 400d5b88 S /system/bin/debuggerd
root 71 60 4300 1604 ffffffff 4013f0d8 S /system/bin/standbyservice
root 75 60 820 476 c0012d74 40137a64 S /system/bin/sh
root 267 2 0 0 c0043260 00000000 S kworker/0:0
root 278 2 0 0 c0043260 00000000 S kworker/u:2
root 423 60 3784 736 ffffffff 40142884 S /system/bin/vold
root 484 2 0 0 c0043260 00000000 S kworker/0:2
root 584 2 0 0 c0043260 00000000 S kworker/0:1
root 585 2 0 0 c00afd2c 00000000 S flush-mtd-unmap
root 812 75 1104 404 00000000 40118e68 R ps
离线
grep 搜了一下整个 camdroid 的开发目录,
vold 的启动位置在这里
camdroid/out/target/product/tiger-cdr/root/init.rc
# Copyright (C) 2012 The Android Open Source Project
#
# IMPORTANT: Do not create world writable files or directories.
# This is a common source of Android security bugs.
#
import /init.${ro.hardware}.rc
on early-init
# Set init and its forked children's oom_adj.
start ueventd
on early-fs
# create mountpoints
mkdir /mnt 0775 root root
mkdir /mnt/sdcard 0755 root root
mkdir /mnt/extsd 0755 root root
on init
sysclktz 0
loglevel 6
# setup the global environment
export PATH /sbin:/system/bin:/system/xbin
export LD_LIBRARY_PATH /system/lib
export ANDROID_ROOT /system
export ANDROID_DATA /data
# Backward compatibility
symlink /system/etc /etc
symlink /sys/kernel/debug /d
# Right now vendor lives on the same filesystem as system,
# but someday that may change.
symlink /system/vendor /vendor
mkdir /system 0777 root root
mkdir /data 0777 root root
mkdir /data/camera 0777 root root
mkdir /system/etc/hawkview 0777 root root
on fs
# mount mtd partitions
# Mount /system rw first to give the filesystem a chance to save a checkpoint
wait /dev/block/mtdblock2
setupfs /dev/block/mtdblock2
mount squashfs /dev/block/mtdblock2 /system
wait /dev/block/mtdblock3
mount jffs2 /dev/block/mtdblock3 /data
on post-fs
mount rootfs rootfs / shared rec
on post-fs-data
# We chown/chmod /data again so because mount is run as root + defaults
chown compass compass /data
chmod 0771 /data
chmod 0771 /data/camera
mkdir /data/property 0700 root root
# We restorecon /data in case the userdata partition has been reset.
restorecon /data
mkdir /data/misc 01771 system misc
mkdir /data/local 0751 root root
on boot
# basic network init
ifup lo
hostname localhost
domainname localdomain
# set RLIMIT_NICE to allow priorities from 19 to -20
setrlimit 13 40 40
# Memory management. Basic kernel parameters, and allow the high
# level system server to be able to adjust the kernel OOM driver
# parameters to match how it is managing things.
chown root radio /proc/cmdline
class_start core
class_start main
on nonencrypted
class_start late_start
## Daemon processes to be run by init.
##
service ueventd /sbin/ueventd
class core
critical
service console /system/bin/sh
class core
disabled
console
user root
group log
on property:ro.debuggable=1
start console
service servicemanager /system/bin/servicemanager
class core
user system
group system
critical
# adbd is controlled via property triggers in init.<platform>.usb.rc
service vold /system/bin/vold
class core
socket vold stream 0660 root mount
ioprio be 2
service debuggerd /system/bin/debuggerd
class main
disabled
service media /system/bin/mediaserver
class core
root media
group audio camera drmrpc mediadrm
ioprio rt 4
离线
接着搜了一下 android 的 init.rc 脚本规范: https://blog.csdn.net/nokiaguy/article/details/9109491
init.rc文件并不是普通的配置文件,而是由一种被称为“Android初始化语言”(Android Init Language,这里简称为AIL)的脚本写成的文件。在了解init如何解析init.rc文件之前,先了解AIL非常必要,否则机械地分析init.c及其相关文件的源代码毫无意义。
为了学习AIL,读者可以到自己Android手机的根目录寻找init.rc文件,最好下载到本地以便查看,如果有编译好的Android源代码,在<Android源代码根目录>out/target/product/generic/root目录也可找到init.rc文件。
AIL由如下4部分组成。
1. 动作(Actions)
2. 命令(Commands)
3. 服务(Services)
4. 选项(Options)
离线
终于找到实现的代码了: https://github.com/qq516333132/camdroid/blob/master/camdroid/system/core/init/signal_handler.c
/init 进程注册了 SIGCHLD 信号的软中断处理程序, 当子进程退出的时候 /init 进程会收到 SIGCHLD 信号,
然后调用 wait_for_one_process() 重启一个新的进程.
所以, 只要 /init 进程在,init.rc 里面service属性的进程只要挂掉都会被 /init 扶正.
离线
感谢, 学习了
离线
厉害, 学习一下。
离线