mirror of https://github.com/dnomd343/ClearDNS
Dnomd343
2 years ago
7 changed files with 66 additions and 39 deletions
@ -1,10 +1,16 @@ |
|||||
#ifndef CRONTAB_H_ |
#ifndef CRONTAB_H_ |
||||
#define CRONTAB_H_ |
#define CRONTAB_H_ |
||||
|
|
||||
#include "config.h" |
#include <stdint.h> |
||||
#include "process.h" |
#include "process.h" |
||||
|
|
||||
void assets_free(assets_config *info); |
typedef struct { |
||||
process* assets_load(assets_config *info); |
uint8_t debug; // bool value
|
||||
|
char *cron; // cron expression
|
||||
|
} crontab; |
||||
|
|
||||
|
void crontab_free(crontab *info); |
||||
|
crontab* crontab_init(char *cron); |
||||
|
process* crontab_load(crontab *info); |
||||
|
|
||||
#endif |
#endif |
||||
|
@ -1,6 +1,7 @@ |
|||||
#ifndef ASSETS_H_ |
#ifndef ASSETS_H_ |
||||
#define ASSETS_H_ |
#define ASSETS_H_ |
||||
|
|
||||
void extract_assets(); |
void assets_init(); |
||||
|
//void assets_update();
|
||||
|
|
||||
#endif |
#endif |
||||
|
@ -1,4 +1,4 @@ |
|||||
cmake_minimum_required(VERSION 2.8.12) |
cmake_minimum_required(VERSION 2.8.12) |
||||
|
|
||||
add_library(applet adguard.c dnsproxy.c overture.c crontab.c) |
add_library(applet adguard.c dnsproxy.c overture.c crontab.c) |
||||
target_link_libraries(applet bcrypt utils) |
target_link_libraries(applet bcrypt) |
||||
|
@ -1,47 +1,41 @@ |
|||||
#include <stdlib.h> |
#include <stdlib.h> |
||||
#include <signal.h> |
|
||||
#include <stdio.h> |
|
||||
#include "config.h" |
|
||||
#include "logger.h" |
#include "logger.h" |
||||
#include "sundry.h" |
#include "sundry.h" |
||||
#include "system.h" |
#include "system.h" |
||||
|
#include "crontab.h" |
||||
#include "process.h" |
#include "process.h" |
||||
#include "structure.h" |
#include "constant.h" |
||||
|
|
||||
char **update_file; |
void crontab_dump(crontab *info); |
||||
char **update_url; |
|
||||
|
|
||||
void assets_update() { // update all assets
|
void crontab_free(crontab *info) { // free crontab options
|
||||
log_info("Start assets update"); |
|
||||
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) { // free assets config
|
|
||||
string_list_free(info->update_file); |
|
||||
string_list_free(info->update_url); |
|
||||
free(info->cron); |
free(info->cron); |
||||
free(info); |
free(info); |
||||
} |
} |
||||
|
|
||||
process* assets_load(assets_config *info) { // load assets update options
|
crontab* crontab_init(char *cron) { // init crontab options
|
||||
update_url = string_list_init(); |
crontab *info = (crontab *)malloc(sizeof(crontab)); |
||||
update_file = string_list_init(); |
info->debug = FALSE; |
||||
string_list_update(&update_url, info->update_url); |
info->cron = string_init(UPDATE_CRON); |
||||
string_list_update(&update_file, info->update_file); |
return info; |
||||
signal(SIGALRM, assets_update); // receive SIGALRM signal
|
} |
||||
|
|
||||
char *cron = string_join(info->cron, " kill -14 1"); |
void crontab_dump(crontab *info) { // show crontab options in debug log
|
||||
save_file("/var/spool/cron/crontabs/root", cron); |
log_debug("Crontab debug -> %s", show_bool(info->debug)); |
||||
free(cron); |
log_debug("Crontab expression -> `%s`", info->cron); |
||||
|
} |
||||
|
|
||||
|
process* crontab_load(crontab *info) { // load crontab options
|
||||
|
// TODO: avoid the case that PID of cleardns is not 1 (docker --pid)
|
||||
|
char *cron_cmd = string_join(info->cron, " kill -14 1"); // SIGALRM -> 14
|
||||
|
save_file("/var/spool/cron/crontabs/root", cron_cmd); |
||||
|
free(cron_cmd); |
||||
|
|
||||
process *proc = process_init("Crontab", "crond"); |
process *proc = process_init("Crontab", "crond"); |
||||
process_add_arg(proc, "-f"); // foreground
|
process_add_arg(proc, "-f"); // foreground
|
||||
|
if (info->debug) { |
||||
|
process_add_arg(proc, "-l"); |
||||
|
process_add_arg(proc, "0"); // verbose mode
|
||||
|
} |
||||
return proc; |
return proc; |
||||
} |
} |
||||
|
Loading…
Reference in new issue