diff --git a/src/applet/crontab.c b/src/applet/crontab.c index 9aa9604..ddd18d7 100644 --- a/src/applet/crontab.c +++ b/src/applet/crontab.c @@ -27,6 +27,7 @@ void crontab_dump(crontab *info) { // show crontab options in debug log process* crontab_load(crontab *info) { // load crontab options crontab_dump(info); + // TODO: use getpid() 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); diff --git a/src/cleardns.c b/src/cleardns.c index d69f339..8ca9c17 100644 --- a/src/cleardns.c +++ b/src/cleardns.c @@ -108,9 +108,7 @@ void cleardns() { // cleardns service process_list_run(); // start all process if (loader.crond != NULL) { // assets not disabled - pid_t my_pid = getpid(); - log_info("ClearDNS PID -> %d", my_pid); - kill(my_pid, SIGALRM); // send alarm signal to itself + kill(getpid(), SIGALRM); // send alarm signal to cleardns crontab_free(loader.crond); } process_list_daemon(); // daemon all process diff --git a/src/utils/process.c b/src/utils/process.c index a37f2cd..c48c886 100644 --- a/src/utils/process.c +++ b/src/utils/process.c @@ -15,8 +15,8 @@ process **process_list; -uint8_t EXITING = FALSE; uint8_t EXITED = FALSE; +uint8_t EXITING = FALSE; void get_sub_exit(); void get_exit_signal(); @@ -93,7 +93,6 @@ 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(50 * 1000); // delay 50ms } log_info("Process start complete"); } @@ -152,7 +151,7 @@ void get_sub_exit() { // catch child process exit return; } int status; - log_debug("Handle sub-process start"); + log_debug("Handle SIGCHLD start"); for (process **proc = process_list; *proc != NULL; ++proc) { if ((*proc)->pid == 0) { continue; // skip not running process @@ -165,9 +164,9 @@ void get_sub_exit() { // catch child process exit char *exit_msg = get_exit_msg(status); log_warn("%s (PID = %d) -> %s", (*proc)->name, (*proc)->pid, exit_msg); free(exit_msg); + // TODO: delay with global const sleep(1); // reduce restart frequency process_exec(*proc); - usleep(50 * 1000); // delay 50ms log_info("%s restart complete", (*proc)->name); return; // skip following check } @@ -181,5 +180,5 @@ void get_sub_exit() { // catch child process exit log_debug("Sub-process (PID = %d) -> %s", wait_ret, exit_msg); free(exit_msg); } - log_debug("Handle sub-process complete"); + log_debug("Handle SIGCHLD complete"); }