diff --git a/include/constant.h b/include/constant.h index dc592c0..69441b7 100644 --- a/include/constant.h +++ b/include/constant.h @@ -4,9 +4,6 @@ #define TRUE 1 #define FALSE 0 -#define VERSION "1.3.0-dev" -#define CONFIG_FILE "cleardns.yml" - #define DNS_PORT 53 #define ADGUARD_PORT 80 #define DIVERTER_PORT 5353 @@ -15,6 +12,9 @@ #define DIVERTER_TIMEOUT 6 +#define VERSION "1.3.0-beta" +#define CONFIG_FILE "cleardns.yml" + #define ADGUARD_USER "admin" #define ADGUARD_PASSWD "cleardns" @@ -37,10 +37,9 @@ #define ASSET_CHINA_LIST "chinalist.txt" #define EXIT_NORMAL 0 -#define EXIT_FILE_ERROR 1 -#define EXIT_FORK_ERROR 2 -#define EXIT_EXEC_ERROR 3 -#define EXIT_WAIT_ERROR 4 +#define EXIT_FORK_ERROR 1 +#define EXIT_EXEC_ERROR 2 +#define EXIT_WAIT_ERROR 3 #define HELP_MSG "\ ClearDNS usage \n\ diff --git a/src/applet/crontab.c b/src/applet/crontab.c index 01ee399..9aa9604 100644 --- a/src/applet/crontab.c +++ b/src/applet/crontab.c @@ -26,9 +26,9 @@ void crontab_dump(crontab *info) { // show crontab options in debug log } process* crontab_load(crontab *info) { // load crontab options - // TODO: avoid the case that PID of cleardns is not 1 (docker --pid) - char *cron_cmd = string_join(info->cron, " kill -14 1"); // SIGALRM -> 14 - save_file("/var/spool/cron/crontabs/root", cron_cmd); + crontab_dump(info); + char *cron_cmd = string_join(info->cron, " kill -14 $(ps -o pid,comm | grep cleardns | awk '{print $1}')"); + save_file("/var/spool/cron/crontabs/root", cron_cmd); // SIGALRM -> 14 free(cron_cmd); process *proc = process_init("Crontab", "crond"); diff --git a/src/utils/process.c b/src/utils/process.c index 40a61b4..2b69232 100644 --- a/src/utils/process.c +++ b/src/utils/process.c @@ -59,12 +59,12 @@ void process_exec(process *proc) { } else if (pid == 0) { // child process if (chdir(proc->cwd)) { // change working directory log_perror("%s with invalid cwd `%s` -> ", proc->name, proc->cwd); - exit(2); + exit(EXIT_EXEC_ERROR); } prctl(PR_SET_PDEATHSIG, SIGKILL); // child process die with father process if (execvpe(*(proc->cmd), proc->cmd, proc->env) < 0) { log_perror("%s exec error -> ", proc->name); - exit(1); + exit(EXIT_EXEC_ERROR); } } proc->pid = pid; @@ -146,7 +146,6 @@ void server_exit(int exit_code) { // kill sub process and exit log_info("%s exit -> PID = %d", (*proc)->name, ret); } EXITED = TRUE; - log_info("All sub-process exited"); log_warn("ClearDNS exit"); exit(exit_code); }