Android 6 init 源码分析

init 的源码在/system/core/init/init.cpp  下

1. main 

int main(int argc, char** argv) {
    if (!strcmp(basename(argv[0]), "ueventd")) {
        return ueventd_main(argc, argv);
    }

    if (!strcmp(basename(argv[0]), "watchdogd")) {
        return watchdogd_main(argc, argv);
    }
... ...
}
    // Clear the umask.
    umask(0);
 
    add_environment("PATH", _PATH_DEFPATH);//添加环境变量
 
    bool is_first_stage = (argc == 1) || (strcmp(argv[1], "--second-stage") != 0);
 
    // Get the basic filesystem setup we need put together in the initramdisk
    // on / and then we'll let the rc file figure out the rest.
    if (is_first_stage) {
        mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755");
        mkdir("/dev/pts", 0755);
        mkdir("/dev/socket", 0755);
        mount("devpts", "/dev/pts", "devpts", 0, NULL);
        mount("proc", "/proc", "proc", 0, NULL);
        mount("sysfs", "/sys", "sysfs", 0, NULL);
    }

  1.初始化 环境变量;

  2.各种设备的初始化创建 以及 挂载;

猜你喜欢

转载自blog.csdn.net/pirionFordring/article/details/83828144
今日推荐