diff --git a/src/applet/crontab.c b/src/applet/crontab.c index 0e90649..6b22ea5 100644 --- a/src/applet/crontab.c +++ b/src/applet/crontab.c @@ -7,6 +7,7 @@ process* assets_load(assets_config *info) { // load assets update options // TODO: update assets process // TODO: save cron exp in `/var/spool/cron/crontabs/root` + log_info("Crontab exp -> `%s %s`", info->cron, "update.sh"); return process_init("Crontab", "crond"); } diff --git a/src/cleardns.c b/src/cleardns.c index 8b67147..2a464b3 100644 --- a/src/cleardns.c +++ b/src/cleardns.c @@ -48,6 +48,9 @@ int main(int argc, char *argv[]) { // ClearDNS service LOG_LEVEL = LOG_DEBUG; log_info("ClearDNS server start (%s)", VERSION); +// remove_file("/tmp/test.txt"); + create_folder("/tmp/test"); + return 0; // process *test = process_init("TEST", "lls"); // process *test = process_init("TEST", "ls"); diff --git a/src/common/system.c b/src/common/system.c index 703695c..1cb4c22 100644 --- a/src/common/system.c +++ b/src/common/system.c @@ -1,10 +1,11 @@ #include #include +#include #include #include -#include #include "logger.h" #include "sundry.h" +#include "system.h" #include "constant.h" int run_command(const char *command) { // running command under system shell @@ -17,10 +18,13 @@ int run_command(const char *command) { // running command under system shell } void remove_file(const char *file) { // delete file - // TODO: use system interface (not `rm` command) - char *remove_cmd = string_join("rm -f ", file); - run_command(remove_cmd); - free(remove_cmd); + if (!is_file_exist(file)) { // file not found + log_debug("Delete file `%s` skip -> file not exist", file); + } else if (remove(file)) { // remove failed + log_perror("Delete file `%s` failed -> ", file); + } else { // remove success + log_debug("Delete file `%s` success", file); + } } void create_folder(const char *folder) { // create folder @@ -28,15 +32,15 @@ void create_folder(const char *folder) { // create folder struct stat buf; stat(folder, &buf); if (!(S_IFDIR & buf.st_mode)) { // target is not folder - log_error("Create folder failed -> target is file"); + log_error("Create folder `%s` failed -> target is file", folder); + } else { + log_debug("Create folder `%s` skip -> folder exist", folder); } - return; + } else if (mkdir(folder, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { // folder -> 755 + log_perror("Create folder `%s` failed -> ", folder); + } else { + log_debug("Create folder `%s` success", folder); } - log_debug("Create folder -> %s", folder); - // TODO: use system command (not `mkdir` command) - char *command = string_join("mkdir -p ", folder); - system(command); - free(command); } uint8_t is_file_exist(const char *file) { // whether file exist