diff --git a/src/applet/adguard.c b/src/applet/adguard.c index 6aad475..9deaa3a 100644 --- a/src/applet/adguard.c +++ b/src/applet/adguard.c @@ -84,9 +84,9 @@ process* adguard_load(adguard *info, const char *dir) { // load adguard options log_fatal("Invalid AdGuardHome password"); } - create_folder(dir); // ensure adguard work dir exist char *adguard_config_ret; char *adguard_config_file = string_join(dir, "AdGuardHome.yaml"); + create_folder(dir); // ensure adguard work dir exist if (!is_file_exist(adguard_config_file)) { // AdGuardHome configure not exist log_info("Create AdGuardHome configure"); diff --git a/src/applet/dnsproxy.c b/src/applet/dnsproxy.c index 47512a0..ca2f480 100644 --- a/src/applet/dnsproxy.c +++ b/src/applet/dnsproxy.c @@ -74,7 +74,6 @@ process* dnsproxy_load(const char *caption, dnsproxy *info, const char *file) { log_fatal("%s without primary dns server", caption); } - create_folder(WORK_DIR); // ensure work dir exist char *config = dnsproxy_config(info); // string config with json format char *config_file = string_join(WORK_DIR, file); save_file(config_file, config); // load dnsproxy configure diff --git a/src/applet/overture.c b/src/applet/overture.c index 2f5506e..393478e 100644 --- a/src/applet/overture.c +++ b/src/applet/overture.c @@ -63,7 +63,6 @@ process* overture_load(overture *info, const char *file) { // load overture opti log_fatal("Timeout of overture with invalid value 0"); } - create_folder(WORK_DIR); // ensure work dir exist char *config = overture_config(info); // string config (JSON format) char *config_file = string_join(WORK_DIR, file); save_file(config_file, config); diff --git a/src/cleardns.c b/src/cleardns.c index 8e566e1..240da77 100644 --- a/src/cleardns.c +++ b/src/cleardns.c @@ -47,8 +47,7 @@ int main(int argc, char *argv[]) { // ClearDNS service log_info("ClearDNS server start (%s)", VERSION); create_folder(EXPOSE_DIR); create_folder(WORK_DIR); - // TODO: cd EXPOSE_DIR - assets_extract(); // extract built-in resource + chdir(EXPOSE_DIR); load_config(config_file); free(config_file); @@ -69,14 +68,14 @@ int main(int argc, char *argv[]) { // ClearDNS service dnsproxy_free(loader.domestic); dnsproxy_free(loader.foreign); assets_free(loader.resource); - if (loader.filter != NULL) { - process_list_append(adguard_load(loader.filter, ADGUARD_DIR)); - adguard_free(loader.filter); - } if (loader.crond != NULL) { process_list_append(crontab_load(loader.crond)); crontab_free(loader.crond); } + if (loader.filter != NULL) { + process_list_append(adguard_load(loader.filter, ADGUARD_DIR)); + adguard_free(loader.filter); + } for (char **script = loader.script; *script != NULL; ++script) { // run custom script log_info("Run custom script -> `%s`", *script); diff --git a/src/loader/loader.c b/src/loader/loader.c index 0861d44..5ef8029 100644 --- a/src/loader/loader.c +++ b/src/loader/loader.c @@ -95,8 +95,7 @@ overture* load_diverter(cleardns_config *config) { uint32_list_update(&diverter->reject_type, config->reject); if (!config->assets.disable) { - // TODO: extract assets - + assets_extract(); // extract built-in resource load_diverter_assets(); } return diverter; diff --git a/src/utils/assets.c b/src/utils/assets.c index 6199cbe..048024c 100644 --- a/src/utils/assets.c +++ b/src/utils/assets.c @@ -45,9 +45,10 @@ void assets_load(assets *info) { // load assets mapping } void assets_update() { // update all assets - - // TODO: skip when assets map is empty - + if (!string_list_len(update.update_file)) { // empty assets mapping + log_info("Skip update assets"); + return; + } log_info("Start assets update"); for (char **file = update.update_file; *file != NULL; ++file) { char **url = file - update.update_file + update.update_url; @@ -65,7 +66,7 @@ void assets_extract() { // init assets and load update process extract(ASSET_GFW_LIST); extract(ASSET_CHINA_IP); extract(ASSET_CHINA_LIST); - log_info("Assets loaded complete"); + log_info("Assets loading complete"); } void extract(const char *file) { // extract one asset file from `.tar.xz` file diff --git a/src/utils/process.c b/src/utils/process.c index 9e550e9..40a61b4 100644 --- a/src/utils/process.c +++ b/src/utils/process.c @@ -42,17 +42,17 @@ process* process_init(const char *caption, const char *bin) { // init process st void process_dump(process *proc) { // output process options into debug log char *process_cmd = string_list_dump(proc->cmd); char *process_env = string_list_dump(proc->env); + log_debug("%s env variable -> %s", proc->name, process_env); log_debug("%s cwd -> %s", proc->name, proc->cwd); log_debug("%s command -> %s", proc->name, process_cmd); - log_debug("%s env variable -> %s", proc->name, process_env); free(process_env); free(process_cmd); } void process_exec(process *proc) { pid_t pid; - process_dump(proc); log_info("%s start", proc->name); + process_dump(proc); if ((pid = fork()) < 0) { // fork error log_perror("%s fork error", proc->name); server_exit(EXIT_FORK_ERROR); @@ -95,7 +95,7 @@ void process_list_run() { // start process list signal(SIGCHLD, get_sub_exit); // callback when child process die for (process **proc = process_list; *proc != NULL; ++proc) { process_exec(*proc); - usleep(100 * 1000); // delay 100ms + usleep(200 * 1000); // delay 200ms } log_info("Process start complete"); } @@ -147,6 +147,7 @@ void server_exit(int exit_code) { // kill sub process and exit } EXITED = TRUE; log_info("All sub-process exited"); + log_warn("ClearDNS exit"); exit(exit_code); }