Netd守护进程服务
- Netd模块是Android中专门负责网络管理和控制的后台守护进程
- 开发板路径./etc/init/netd.rc
service netd /system/bin/netd
class main
socket dnsproxyd stream 0660 root inet
socket mdns stream 0660 root system
socket fwmarkd stream 0660 root inet
onrestart restart zygote
onrestart restart zygote_secondary
# b/121354779: netd itself is not updatable, but on startup it dlopen()s the resolver library
# from the DNS resolver APEX. Mark it as updatable so init won't start it until all APEX
# packages are ready.
updatable
~
Netd源码分析
system\netd\server\main.cpp
int main() {
Stopwatch s;
gLog.info("netd 1.0 starting");
android::net::process::removePidFile(PID_FILE_PATH);
android::net::process::blockSigPipe();
// Before we do anything that could fork, mark CLOEXEC the UNIX sockets that we get from init.
// FrameworkListener does this on initialization as well, but we only initialize these
// components after having initialized other subsystems that can fork.
for (const auto& sock :
{DNSPROXYLISTENER_SOCKET_NAME, FwmarkServer::SOCKET_NAME, MDnsSdListener::SOCKET_NAME}) {
setCloseOnExec(sock);
}
// Before we start any threads, populate the resolver stub pointers.
resolv_stub_init();
// Make sure BPF programs are loaded before doing anything
while (!android::base::WaitForProperty("bpf.progs_loaded", "