From 844aae24b954bc7c4fb8807d564ba60755d627ed Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Tue, 5 Mar 2024 19:13:31 +0100 Subject: [PATCH] add option to configure continuous state writing interval --- help.h | 1 + readsb.c | 12 ++++++++++-- readsb.h | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/help.h b/help.h index ed123247..5baee725 100644 --- a/help.h +++ b/help.h @@ -96,6 +96,7 @@ static struct argp_option optionsReadsb[] = { {"write-prom", OptPromFile, "", 0, "Periodically write prometheus output to ", 1}, {"write-globe-history", OptGlobeHistoryDir, "", 0, "Extended Globe History", 1}, {"write-state", OptStateDir, "", 0, "Write state to disk to have traces after a restart", 1}, + {"write-state-every", OptStateInterval, "", 0, "Continuously write state to disk every X seconds (default: 3600)", 1}, {"write-state-only-on-exit", OptStateOnlyOnExit, 0, 0, "Don't continously update state.", 1}, {"heatmap-dir", OptHeatmapDir, "", 0, "Change the directory where heatmaps are saved (default is in globe history dir)", 1}, {"heatmap", OptHeatmap, "", 0, "Make Heatmap, each aircraft at most every interval seconds (creates historydir/heatmap.bin and exit after that)", 1}, diff --git a/readsb.c b/readsb.c index f1cd2550..edffc5bf 100644 --- a/readsb.c +++ b/readsb.c @@ -153,6 +153,7 @@ static void configSetDefaults(void) { Modes.netIngest = 0; Modes.uuidFile = strdup("/usr/local/share/adsbexchange/adsbx-uuid"); Modes.json_trace_interval = 20 * 1000; + Modes.state_write_interval = 1 * HOURS; Modes.heatmap_current_interval = -15; Modes.heatmap_interval = 60 * SECONDS; Modes.json_reliable = -13; @@ -1555,6 +1556,14 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { case OptStateOnlyOnExit: Modes.state_only_on_exit = 1; break; + case OptStateInterval: + Modes.state_write_interval = (int64_t) (atof(arg) * 1.0 * SECONDS); + if (Modes.state_write_interval < 59 * SECONDS) { + fprintf(stderr, "ERROR: --write-state-every less than 60 seconds (specified: %s)\n", arg); + exit(1); + Modes.state_write_interval = 1 * HOURS; + } + break; case OptStateDir: sfree(Modes.state_parent_dir); Modes.state_parent_dir = strdup(arg); @@ -2337,8 +2346,7 @@ static void miscStuff(int64_t now) { //fprintf(stderr, "save_blob: %02x\n", blob); notask_save_blob(blob); blob = (blob + 1) % STATE_BLOBS; - next_blob = now + 60 * MINUTES / STATE_BLOBS; - + next_blob = now + Modes.state_write_interval / STATE_BLOBS; return; } } diff --git a/readsb.h b/readsb.h index 7494ade2..13be44ea 100644 --- a/readsb.h +++ b/readsb.h @@ -782,6 +782,7 @@ struct _Modes int8_t dump_reduce; // only dump beast that would be sent out according to reduce_interval int8_t state_only_on_exit; int8_t free_aircraft; + int64_t state_write_interval; char *prom_file; int64_t heatmap_current_interval; int64_t heatmap_interval; // don't change data type @@ -1168,6 +1169,7 @@ enum { OptPromFile, OptGlobeHistoryDir, OptStateDir, + OptStateInterval, OptStateOnlyOnExit, OptHeatmap, OptHeatmapDir,