Browse Source

update: several adjustment

dev
Dnomd343 2 years ago
parent
commit
03631d709c
  1. 2
      src/applet/adguard.c
  2. 1
      src/applet/dnsproxy.c
  3. 1
      src/applet/overture.c
  4. 11
      src/cleardns.c
  5. 3
      src/loader/loader.c
  6. 9
      src/utils/assets.c
  7. 7
      src/utils/process.c

2
src/applet/adguard.c

@ -84,9 +84,9 @@ process* adguard_load(adguard *info, const char *dir) { // load adguard options
log_fatal("Invalid AdGuardHome password"); log_fatal("Invalid AdGuardHome password");
} }
create_folder(dir); // ensure adguard work dir exist
char *adguard_config_ret; char *adguard_config_ret;
char *adguard_config_file = string_join(dir, "AdGuardHome.yaml"); 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 if (!is_file_exist(adguard_config_file)) { // AdGuardHome configure not exist
log_info("Create AdGuardHome configure"); log_info("Create AdGuardHome configure");

1
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); 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 = dnsproxy_config(info); // string config with json format
char *config_file = string_join(WORK_DIR, file); char *config_file = string_join(WORK_DIR, file);
save_file(config_file, config); // load dnsproxy configure save_file(config_file, config); // load dnsproxy configure

1
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"); 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 = overture_config(info); // string config (JSON format)
char *config_file = string_join(WORK_DIR, file); char *config_file = string_join(WORK_DIR, file);
save_file(config_file, config); save_file(config_file, config);

11
src/cleardns.c

@ -47,8 +47,7 @@ int main(int argc, char *argv[]) { // ClearDNS service
log_info("ClearDNS server start (%s)", VERSION); log_info("ClearDNS server start (%s)", VERSION);
create_folder(EXPOSE_DIR); create_folder(EXPOSE_DIR);
create_folder(WORK_DIR); create_folder(WORK_DIR);
// TODO: cd EXPOSE_DIR chdir(EXPOSE_DIR);
assets_extract(); // extract built-in resource
load_config(config_file); load_config(config_file);
free(config_file); free(config_file);
@ -69,14 +68,14 @@ int main(int argc, char *argv[]) { // ClearDNS service
dnsproxy_free(loader.domestic); dnsproxy_free(loader.domestic);
dnsproxy_free(loader.foreign); dnsproxy_free(loader.foreign);
assets_free(loader.resource); 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) { if (loader.crond != NULL) {
process_list_append(crontab_load(loader.crond)); process_list_append(crontab_load(loader.crond));
crontab_free(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 for (char **script = loader.script; *script != NULL; ++script) { // run custom script
log_info("Run custom script -> `%s`", *script); log_info("Run custom script -> `%s`", *script);

3
src/loader/loader.c

@ -95,8 +95,7 @@ overture* load_diverter(cleardns_config *config) {
uint32_list_update(&diverter->reject_type, config->reject); uint32_list_update(&diverter->reject_type, config->reject);
if (!config->assets.disable) { if (!config->assets.disable) {
// TODO: extract assets assets_extract(); // extract built-in resource
load_diverter_assets(); load_diverter_assets();
} }
return diverter; return diverter;

9
src/utils/assets.c

@ -45,9 +45,10 @@ void assets_load(assets *info) { // load assets mapping
} }
void assets_update() { // update all assets void assets_update() { // update all assets
if (!string_list_len(update.update_file)) { // empty assets mapping
// TODO: skip when assets map is empty log_info("Skip update assets");
return;
}
log_info("Start assets update"); log_info("Start assets update");
for (char **file = update.update_file; *file != NULL; ++file) { for (char **file = update.update_file; *file != NULL; ++file) {
char **url = file - update.update_file + update.update_url; 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_GFW_LIST);
extract(ASSET_CHINA_IP); extract(ASSET_CHINA_IP);
extract(ASSET_CHINA_LIST); 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 void extract(const char *file) { // extract one asset file from `.tar.xz` file

7
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 void process_dump(process *proc) { // output process options into debug log
char *process_cmd = string_list_dump(proc->cmd); char *process_cmd = string_list_dump(proc->cmd);
char *process_env = string_list_dump(proc->env); 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 cwd -> %s", proc->name, proc->cwd);
log_debug("%s command -> %s", proc->name, process_cmd); log_debug("%s command -> %s", proc->name, process_cmd);
log_debug("%s env variable -> %s", proc->name, process_env);
free(process_env); free(process_env);
free(process_cmd); free(process_cmd);
} }
void process_exec(process *proc) { void process_exec(process *proc) {
pid_t pid; pid_t pid;
process_dump(proc);
log_info("%s start", proc->name); log_info("%s start", proc->name);
process_dump(proc);
if ((pid = fork()) < 0) { // fork error if ((pid = fork()) < 0) { // fork error
log_perror("%s fork error", proc->name); log_perror("%s fork error", proc->name);
server_exit(EXIT_FORK_ERROR); 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 signal(SIGCHLD, get_sub_exit); // callback when child process die
for (process **proc = process_list; *proc != NULL; ++proc) { for (process **proc = process_list; *proc != NULL; ++proc) {
process_exec(*proc); process_exec(*proc);
usleep(100 * 1000); // delay 100ms usleep(200 * 1000); // delay 200ms
} }
log_info("Process start complete"); log_info("Process start complete");
} }
@ -147,6 +147,7 @@ void server_exit(int exit_code) { // kill sub process and exit
} }
EXITED = TRUE; EXITED = TRUE;
log_info("All sub-process exited"); log_info("All sub-process exited");
log_warn("ClearDNS exit");
exit(exit_code); exit(exit_code);
} }

Loading…
Cancel
Save