From 216bfce30f9dbbda537b3f572875fb0d67dbd8d7 Mon Sep 17 00:00:00 2001 From: Jason Reiss Date: Mon, 21 Jun 2021 10:14:07 -0500 Subject: Change the auto restart to use process clock time rather than sx1301 counter Use exit instead of a clean shutdown, race condition between threads may have been causing the process to hang --- lora_pkt_fwd/src/lora_pkt_fwd.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lora_pkt_fwd/src/lora_pkt_fwd.c b/lora_pkt_fwd/src/lora_pkt_fwd.c index bfcca1f..fbab482 100644 --- a/lora_pkt_fwd/src/lora_pkt_fwd.c +++ b/lora_pkt_fwd/src/lora_pkt_fwd.c @@ -1873,6 +1873,10 @@ int main(int argc, char** argv) sigaction(SIGHUP, &sighupact, NULL); /* rotate logfile on HUP */ signal(SIGPIPE, SIG_IGN); /* ignore writes after closing socket */ + struct timespec start_time; + struct timespec check_time; + + clock_gettime(CLOCK_MONOTONIC, &start_time); /* main loop task : statistics collection */ while (!exit_sig && !quit_sig) { @@ -2011,16 +2015,12 @@ int main(int argc, char** argv) break; } - static uint32_t last_tstamp = 0; - static uint32_t rollover_cnt = 0; - if (trig_tstamp < last_tstamp) { - if (rollover_cnt++ > 10) { - exit_sig = true; - MSG("INFO: periodic restart, process is exiting.\n"); - break; - } + clock_gettime(CLOCK_MONOTONIC, &check_time); + + if ((int)(difftimespec(recv_time, send_time)) > (10 * 60 * 60)) { // allow forwarder to run a maximum of 10 hours before forcing a restart + MSG("INFO: periodic restart, process is exiting.\n"); + exit(1); } - last_tstamp = trig_tstamp; pthread_mutex_unlock(&mx_concent); if (i != LGW_HAL_SUCCESS) { -- cgit v1.2.3