diff --git a/include/common/system.h b/include/common/system.h index e3b923a..82cd4bf 100644 --- a/include/common/system.h +++ b/include/common/system.h @@ -9,6 +9,7 @@ int run_command(const char *command); void create_folder(const char *folder); uint8_t is_file_exist(const char *file); void save_file(const char *file, const char *content); +void download_file(const char *file, const char *url); void save_string_list(const char *file, char **string_list); void file_append(const char *base_file, const char *append_file); diff --git a/include/constant.h b/include/constant.h index 2e560c9..dc592c0 100644 --- a/include/constant.h +++ b/include/constant.h @@ -5,7 +5,7 @@ #define FALSE 0 #define VERSION "1.3.0-dev" -#define CONFIG_FILE "test.yml" +#define CONFIG_FILE "cleardns.yml" #define DNS_PORT 53 #define ADGUARD_PORT 80 diff --git a/include/utils/process.h b/include/utils/process.h index d3af671..df265e6 100644 --- a/include/utils/process.h +++ b/include/utils/process.h @@ -11,7 +11,7 @@ typedef struct { char *cwd; // working directory } process; -extern process **process_list; +//extern process **process_list; void process_list_run(); void process_list_init(); diff --git a/src/applet/crontab.c b/src/applet/crontab.c index 3d19e75..16b0662 100644 --- a/src/applet/crontab.c +++ b/src/applet/crontab.c @@ -1,5 +1,6 @@ #include #include +#include #include "config.h" #include "logger.h" #include "sundry.h" @@ -15,10 +16,14 @@ void assets_update() { // update all assets for (char **file = update_file; *file != NULL; ++file) { char **url = file - update_file + update_url; log_info("Update asset `%s` -> %s", *file, *url); + download_file(*file, *url); // download asset from url } + log_info("Restart overture"); + run_command("pgrep overture | xargs kill"); // restart overture + log_info("Assets update complete"); } -void assets_free(assets_config *info) { +void assets_free(assets_config *info) { // free assets config string_list_free(info->update_file); string_list_free(info->update_url); free(info->cron); diff --git a/src/cleardns.c b/src/cleardns.c index 3007db9..89fe179 100644 --- a/src/cleardns.c +++ b/src/cleardns.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "loader.h" #include "logger.h" #include "sundry.h" diff --git a/src/common/system.c b/src/common/system.c index 1cb4c22..3c32b62 100644 --- a/src/common/system.c +++ b/src/common/system.c @@ -106,3 +106,12 @@ void save_string_list(const char *file, char **string_list) { // save string lis fclose(fp); log_debug("Save `%s` success", file); } + +void download_file(const char *file, const char *url) { // download file + log_debug("Download file `%s` -> %s", file, url); + char *download_cmd = (char *)malloc(strlen(file) + strlen(url) + 15); + sprintf(download_cmd, "wget -T 8 -O %s %s", file, url); + if (run_command(download_cmd)) { + log_warn("File `%s` download failed", url); + } +} diff --git a/src/utils/process.c b/src/utils/process.c index f099b96..3bc5a36 100644 --- a/src/utils/process.c +++ b/src/utils/process.c @@ -11,6 +11,9 @@ process **process_list; +uint8_t EXITING = FALSE; +uint8_t EXITED = FALSE; + void get_sub_exit(); void get_exit_signal(); void server_exit(int exit_code); @@ -91,12 +94,18 @@ void process_list_run() { // start process list } void process_list_daemon() { - int status; - wait(&status); + while (!EXITED) { + pause(); + } } void server_exit(int exit_code) { // kill sub process and exit - log_info("Kill subprocess"); + while (EXITING) { // only run once + pause(); + } + EXITING = TRUE; + + log_info("ClearDNS exiting"); // TODO: kill subprocess and exit cleardns @@ -105,7 +114,7 @@ void server_exit(int exit_code) { // kill sub process and exit void get_exit_signal() { // get SIGINT or SIGTERM signal log_info("Get exit signal"); - server_exit(EXIT_NORMAL); + server_exit(EXIT_NORMAL); // normally exit } void get_sub_exit() { // catch child process exit