美文网首页
系统启动, init

系统启动, init

作者: 唐僧不爱洗头_f7b5 | 来源:发表于2017-07-03 17:03 被阅读0次

    init进程, 启动的第一个用户进程,进程id 为1
    init-创建 zygote进程,提供属性服务(property service);
    (1)zygote的创建
    (2)property service

    init的入口函数在init.cpp->main()

    在这里会解析init.rc

    parser.ParseConfig("/init.rc");```
    init.rc里面会启动zygote进程,zygote进程是Android系统其他进程的孵化进程
    

    on zygote-start && property:ro.crypto.state=unencrypted
    # A/B update verifier that marks a successful boot.
    exec_start update_verifier_nonencrypted
    start netd
    start zygote
    start zygote_secondary

    property的两个相关函数都在init:
    

    main(){
    property_init(); //初始化property,创建一块存储区域
    property_load_boot_defaults(); //加载默认的prop
    start_property_service(); //开启property service
    }

    property_service.cpp
    //property_init()->__system_property_area_init()
    void property_init() {
    if (__system_property_area_init()) { //创建一块存储区域
    LOG(ERROR) << "Failed to initialize property area";
    exit(1);
    }
    }

    //property_load_boot_defaults
    void property_load_boot_defaults() {
    //加载下面的几个prop文件
    load_properties_from_file("/default.prop", NULL);
    load_properties_from_file("/odm/default.prop", NULL);
    load_properties_from_file("/vendor/default.prop", NULL);

    update_sys_usb_config();
    

    }

    //start_property_service()
    void start_property_service() {
    //创建property socket
    property_set_fd = CreateSocket(PROP_SERVICE_NAME, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
    false, 0666, 0, 0, nullptr, sehandle);
    //注册handler
    register_epoll_handler(property_set_fd, handle_property_set_fd);
    }

    /-------截止到上面的步骤, 是init进程启动时开启property service的部分--------/

    
    后续property set通过socket进行通讯, 服务器端和客户端处理如下:
    服务器端处理函数
    

    property_service.cpp
    handle_property_set_fd(){
    SocketConnection socket(s, cr); //建立socket连接
    switch (cmd) {
    case PROP_MSG_SETPROP: {
    handle_property_set(socket, prop_value, prop_value, true);
    break;
    }
    }
    }

    static void handle_property_set(SocketConnection& socket,
    const std::string& name,
    const std::string& value,
    bool legacy_protocol){
    uint32_t result = property_set(name, value);
    }

    
    客户端调用prpperty_set:
    

    system/core/libcutils/properties.cpp
    int property_set(const char *key, const char *value) {
    return __system_property_set(key, value); //调用设置
    }

    相关文章

      网友评论

          本文标题:系统启动, init

          本文链接:https://www.haomeiwen.com/subject/kygacxtx.html