diff --git a/src/cleardns.c b/src/cleardns.c index e1f4f0e..3ad366a 100644 --- a/src/cleardns.c +++ b/src/cleardns.c @@ -115,12 +115,8 @@ void cleardns() { // cleardns service } int main(int argc, char *argv[]) { -// init(argc, argv); -// log_info("ClearDNS server start (%s)", VERSION); -// cleardns(); - - char *test = string_load("`%s` -> %d", "test", 2333); - printf("%s\n", test); - + init(argc, argv); + log_info("ClearDNS server start (%s)", VERSION); + cleardns(); return 0; } diff --git a/src/common/json.c b/src/common/json.c index 7d308c2..95f33e7 100644 --- a/src/common/json.c +++ b/src/common/json.c @@ -1,4 +1,3 @@ -#include #include #include #include "cJSON.h" @@ -27,8 +26,7 @@ char* to_json(const char *file) { // convert JSON / TOML / YAML to json format ( flag[8] = '\0'; char *output_file = string_join("/tmp/to-json-", flag); - char *to_json_cmd = (char *)malloc(strlen(file) + strlen(output_file) + 11); - sprintf(to_json_cmd, "toJSON %s > %s", file, output_file); + char *to_json_cmd = string_load("toJSON %s > %s", file, output_file); int to_json_ret = run_command(to_json_cmd); free(to_json_cmd); diff --git a/src/common/structure.c b/src/common/structure.c index a8b0e8a..2698e86 100644 --- a/src/common/structure.c +++ b/src/common/structure.c @@ -92,7 +92,7 @@ char* uint32_list_dump(uint32_t **uint32_list) { // [1, 2, 3, ...] strcpy(string_ret, "["); for (uint32_t **number = uint32_list; *number != NULL; ++number) { sprintf(uint32_str, "%u", **number); - string_ret = (char*)realloc(string_ret, strlen(string_ret) + 15); + string_ret = (char *)realloc(string_ret, strlen(string_ret) + 15); string_ret = strcat(strcat(string_ret, uint32_str), ", "); } string_ret[strlen(string_ret) - 2] = '\0'; diff --git a/src/common/system.c b/src/common/system.c index f59318c..476d579 100644 --- a/src/common/system.c +++ b/src/common/system.c @@ -4,6 +4,7 @@ #include #include #include "logger.h" +#include "sundry.h" #include "system.h" #include "constant.h" @@ -65,8 +66,7 @@ void save_file(const char *file, const char *content) { // save content into fil } void file_append(const char *base_file, const char *append_file) { // append_file >> base_file - char *append_cmd = (char *)malloc(strlen(base_file) + strlen(append_file) + 9); - sprintf(append_cmd, "cat %s >> %s", append_file, base_file); + char *append_cmd = string_load("cat %s >> %s", append_file, base_file); run_command(append_cmd); free(append_cmd); } @@ -108,8 +108,7 @@ void save_string_list(const char *file, char **string_list) { // save string lis 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); + char *download_cmd = string_load("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/assets.c b/src/utils/assets.c index 6b9bb89..9f31f42 100644 --- a/src/utils/assets.c +++ b/src/utils/assets.c @@ -1,4 +1,3 @@ -#include #include #include #include @@ -81,8 +80,7 @@ void extract(const char *file) { // extract one asset file from `.tar.xz` file } free(output_file); - char *extract_cmd = (char *)malloc(strlen(ASSETS_PKG) + strlen(file) + strlen(ASSETS_DIR) + 13); - sprintf(extract_cmd, "tar xf %s %s -C %s", ASSETS_PKG, file, ASSETS_DIR); + char *extract_cmd = string_load("tar xf %s %s -C %s", ASSETS_PKG, file, ASSETS_DIR); if (run_command(extract_cmd)) { log_warn("Extract asset `%s` failed", file); } else {