之前我们分析过了ueventd处理uevent事件,这篇博客我们看下healthd和vold是如何接受相关的uevent事件的。
一、healthd接受uevent
下面是heathd的主函数
int main(int argc, char **argv) {
int ch;
int ret;
klog_set_level(KLOG_LEVEL);
healthd_mode_ops = &android_ops;
if (!strcmp(basename(argv[0]), "charger")) {
healthd_mode_ops = &charger_ops;
} else {
while ((ch = getopt(argc, argv, "cr")) != -1) {
switch (ch) {
case 'c':
healthd_mode_ops = &charger_ops;
break;
case 'r':
healthd_mode_ops = &recovery_ops;
break;
case '?':
default:
KLOG_ERROR(LOG_TAG, "Unrecognized healthd option: %c\n",
optopt);
exit(1);
}
}
}
ret = healthd_init();//初始化
if (ret) {
KLOG_ERROR("Initialization failed, exiting\n");
exit(2);
}
healthd_mainloop();//进入epoll循环
KLOG_ERROR("Main loop terminated, exiting\n");
return 3;
}
我们先来看healthd_init函数
static int healthd_init() {
epollfd = epoll_create(MAX_EPOLL_EVENTS);//创建epoll的fd
if (epollfd == -1) {
KLOG_ERROR(LOG_TAG