int main(int argc, char **argv) { /* Init configuration */ init_config(); parse_commandline(argc, argv); switch(config.command) { case WDCTL_STATUS: wdctl_status(); break; // 停掉 wifidog进程 case WDCTL_STOP: wdctl_stop(); break; case WDCTL_KILL: wdctl_reset(); break; case WDCTL_RESTART: wdctl_restart(); break; default: /* XXX NEVER REACHED */ fprintf(stderr, "Oops\n"); exit(1); break; } exit(0); }
// called by thread_wdctl(), 专门创建一个线程来处理wdctl进程发来的命令 // *@arg = socket fd (与wdctl进程通讯) static void * thread_wdctl_handler(void *arg) { int fd, done, i; char request[MAX_BUF]; ssize_t read_bytes, len; debug(LOG_DEBUG, "Entering thread_wdctl_handler...."); fd = (int)arg; debug(LOG_DEBUG, "Read bytes and stuff from %d", fd); /* Init variables */ read_bytes = 0; done = 0; memset(request, 0, sizeof(request)); /* Read.... */ while (!done && read_bytes < (sizeof(request) - 1)) { len = read(fd, request + read_bytes, sizeof(request) - read_bytes); /* Have we gotten a command yet? */ for (i = read_bytes; i < (read_bytes + len); i++) { if (request[i] == '\r' || request[i] == '\n') { request[i] = '\0'; done = 1; } } /* Increment position */ read_bytes += len; } debug(LOG_DEBUG, "recv wdctl cmd : %s", request); // add by lijg, 2013-05-27, for debug it if (strncmp(request, "status", 6) == 0) { wdctl_status(fd); } else if (strncmp(request, "stop", 4) == 0) { // 停掉wifidog命令 wdctl_stop(fd); } else if (strncmp(request, "reset", 5) == 0) { wdctl_reset(fd, (request + 6)); } else if (strncmp(request, "restart", 7) == 0) { wdctl_restart(fd); } if (!done) { debug(LOG_ERR, "Invalid wdctl request."); shutdown(fd, 2); close(fd); pthread_exit(NULL); } debug(LOG_DEBUG, "Request received: [%s]", request); shutdown(fd, 2); close(fd); debug(LOG_DEBUG, "Exiting thread_wdctl_handler...."); return NULL; }
int main(int argc, char **argv) { /* Init configuration */ init_config(); parse_commandline(argc, argv); switch (config.command) { case WDCTL_STATUS: wdctl_status(); break; case WDCTL_STOP: wdctl_stop(); break; case WDCTL_KILL: wdctl_reset(); break; case WDCTL_RESTART: wdctl_restart(); break; //>>> liudf added 20151225 case WDCTL_ADD_TRUSTED_DOMAINS: wdctl_add_trusted_domains(); break; case WDCTL_ADD_TRUSTED_IPLIST: wdctl_add_trusted_iplist(); break; case WDCTL_REPARSE_TRUSTED_DOMAINS: wdctl_reparse_trusted_domains(); break; case WDCTL_CLEAR_TRUSTED_DOMAINS: wdctl_clear_trusted_domains(); break; case WDCTL_SHOW_TRUSTED_DOMAINS: wdctl_show_trusted_domains(); break; case WDCTL_ADD_DOMAIN_IP: wdctl_add_domain_ip(); break; case WDCTL_ADD_ROAM_MACLIST: wdctl_add_roam_maclist(); break; case WDCTL_SHOW_ROAM_MACLIST: wdctl_show_roam_maclist(); break; case WDCTL_CLEAR_ROAM_MACLIST: wdctl_clear_roam_maclist(); break; case WDCTL_ADD_TRUSTED_MACLIST: wdctl_add_trusted_maclist(); break; case WDCTL_SHOW_TRUSTED_MACLIST: wdctl_show_trusted_maclist(); break; case WDCTL_CLEAR_TRUSTED_MACLIST: wdctl_clear_trusted_maclist(); break; case WDCTL_ADD_UNTRUSTED_MACLIST: wdctl_add_untrusted_maclist(); break; case WDCTL_SHOW_UNTRUSTED_MACLIST: wdctl_show_untrusted_maclist(); break; case WDCTL_CLEAR_UNTRUSTED_MACLIST: wdctl_clear_untrusted_maclist(); break; case WDCTL_USER_CFG_SAVE: wdctl_user_cfg_save(); break; case WDCTL_ADD_WILDCARD_DOMAIN: break; //<<< liudf end default: /* XXX NEVER REACHED */ fprintf(stderr, "Oops\n"); exit(1); break; } exit(0); }