From ea0593a22cc71bebfcbce46836940d363c674b7c 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 f6f126c..d1f74ba 100644 --- a/lora_pkt_fwd/src/lora_pkt_fwd.c +++ b/lora_pkt_fwd/src/lora_pkt_fwd.c @@ -1869,6 +1869,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) { @@ -2007,16 +2011,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; /* read the currrent temperature */ pthread_mutex_unlock(&mx_concent); -- cgit v1.2.3