网上已有源码详细的源码分析,此分析仅做个人记录
从main开始wifidog-gateway/src/gatway.c
/* Reads the configuration file and then starts the main loop */
int //读取配置文件,也就是/etc/wifidog.conf中的各项配置
gw_main(int argc, char **argv)
{
s_config *config = config_get_config(); //获取配置
config_init(); //初始化配置
parse_commandline(argc, argv); //这里匹配wifidog命令行命令
/* Initialize the config */
config_read(config->configfile); //从配置文件中读取配置
config_validate();
/* Initializes the linked list of connected clients */
client_list_init();
/* Init the signals to catch chld/quit/etc */
init_signals();
if (restart_orig_pid) {
/*
* We were restarted and our parent is waiting for us to talk to it over the socket
*/
get_clients_from_parent();
/*
* At this point the parent will start destroying itself and the firewall. Let it finish it's job before we continue
*/
while (kill(restart_orig_pid, 0) != -1) {
debug(LOG_INFO, "Waiting for parent PID %d to die before continuing loading", restart_orig_pid);
sleep(1);
}
debug(LOG_INFO, "Parent PID %d seems to be dead. Continuing loading.");
}
if (config->daemon) { //开启进程,默认设置为后台运行,daemon初始化默认为1
debug(LOG_INFO, "Forking into background");
switch (safe_fork()) {
case 0: /* child */
setsid();
append_x_restartargv();
main_loop(); //进入main loop,wifidog开始工作
break;
default: /* parent */
exit(0);
break;
}
} else {
append_x_restartargv();
main_loop();
}
return (0); /* never reached */
}
wifidog-gateway/src/gatway.