From 9dfc3e7aa632b5884e21bd1c5ee86d7ebf8a349b Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Thu, 7 Mar 2019 18:35:47 +0000 Subject: [PATCH] Arrange to return a non-zero exit code if the SDR thread unexpectedly halts --- dump1090.c | 21 +++++++++------------ dump1090.h | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/dump1090.c b/dump1090.c index 4e55367..b654c01 100644 --- a/dump1090.c +++ b/dump1090.c @@ -224,15 +224,12 @@ void *readerThreadEntryPoint(void *arg) // Wake the main thread (if it's still waiting) pthread_mutex_lock(&Modes.data_mutex); - Modes.exit = 1; // just in case + if (!Modes.exit) + Modes.exit = 2; // unexpected exit pthread_cond_signal(&Modes.data_cond); pthread_mutex_unlock(&Modes.data_mutex); -#ifndef _WIN32 - pthread_exit(NULL); -#else return NULL; -#endif } // // ============================== Snip mode ================================= @@ -760,15 +757,15 @@ int main(int argc, char **argv) { display_total_stats(); } - log_with_timestamp("Normal exit."); - sdrClose(); -#ifndef _WIN32 - pthread_exit(0); -#else - return (0); -#endif + if (Modes.exit == 1) { + log_with_timestamp("Normal exit."); + return 0; + } else { + log_with_timestamp("Abnormal exit."); + return 1; + } } // //========================================================================= diff --git a/dump1090.h b/dump1090.h index 4e0340c..3c4b93b 100644 --- a/dump1090.h +++ b/dump1090.h @@ -304,7 +304,7 @@ struct { // Internal state double sample_rate; // actual sample rate in use (in hz) uint16_t *log10lut; // Magnitude -> log10 lookup table - int exit; // Exit from the main loop when true + int exit; // Exit from the main loop when true (2 = unclean exit) // Sample conversion int dc_filter; // should we apply a DC filter?