From a8c6ef5a2d3ddc9282211a6d05c8d1117b37cf8d Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 22 Sep 2022 18:43:58 +0800 Subject: [PATCH] update: demo of update signal --- src/applet/crontab.c | 12 +++++++++++- src/cleardns.c | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/applet/crontab.c b/src/applet/crontab.c index 6b22ea5..faa91d7 100644 --- a/src/applet/crontab.c +++ b/src/applet/crontab.c @@ -1,13 +1,23 @@ +#include #include "process.h" #include "config.h" #include "logger.h" +#include "sundry.h" +#include "system.h" process* assets_load(assets_config *info) { // load assets update options log_info("assets test ok"); // TODO: update assets process // TODO: save cron exp in `/var/spool/cron/crontabs/root` - log_info("Crontab exp -> `%s %s`", info->cron, "update.sh"); + + char *cron = string_join(info->cron, " kill -14 1"); + + log_info("Crontab exp -> `%s`", cron); + + save_file("/var/spool/cron/crontabs/root", cron); + + free(cron); return process_init("Crontab", "crond"); } diff --git a/src/cleardns.c b/src/cleardns.c index 759ab4f..7ed6548 100644 --- a/src/cleardns.c +++ b/src/cleardns.c @@ -41,6 +41,10 @@ char* init(int argc, char *argv[]) { // return config file return config; } +void signal_test() { + log_info("Get alarm signal"); +} + int main(int argc, char *argv[]) { // ClearDNS service char *config_file = init(argc, argv); @@ -48,6 +52,17 @@ int main(int argc, char *argv[]) { // ClearDNS service LOG_LEVEL = LOG_DEBUG; log_info("ClearDNS server start (%s)", VERSION); + signal(SIGALRM, signal_test); + + assets_config demo; + demo.cron = "* * * * *"; + process *crontab = assets_load(&demo); + process_exec(crontab); + + for (;;) { + pause(); + } + return 0; // process *test = process_init("TEST", "lls"); // process *test = process_init("TEST", "ls");