Add signal handlers for a proper cleanup

Fix locking problem in get_rtlsdr_sample when it waits indefinitely
even when exitflag is non-zero; cleanup the code.
This commit is contained in:
Volo Zyko
2023-06-30 14:12:48 +03:00
parent eacbd21c50
commit 0e9b2b245d
5 changed files with 39 additions and 12 deletions

View File

@@ -26,8 +26,15 @@
#include "provoice_const.h"
#include "git_ver.h"
#include <signal.h>
volatile uint8_t exitflag; //fix for issue #136
void handler(int)
{
exitflag = 1;
}
int pretty_colors()
{
fprintf (stderr,"%sred\n", KRED);
@@ -1279,7 +1286,7 @@ if (opts->audio_out_type == 0)
openPulseOutput(opts);
}
while (1)
while (!exitflag)
{
noCarrier (opts, state);
@@ -1342,6 +1349,14 @@ cleanupAndExit (dsd_opts * opts, dsd_state * state)
closeWavOutFileR (opts, state);
}
closeSymbolOutFile (opts, state);
if (opts->rtl_started == 1)
{
cleanup_rtlsdr_stream();
}
if (opts->use_ncurses_terminal == 1)
{
ncursesClose(opts);
}
//close MBE out files
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
@@ -2570,6 +2585,9 @@ main (int argc, char **argv)
// opts.audio_out_fd = opts.audio_in_fd; //not sure that this really does much anymore, other than cause problems
}
signal(SIGINT, handler);
signal(SIGTERM, handler);
if (opts.playfiles == 1)
{
state.aout_gain = 25; //BUGFIX: No audio output when playing back .amb/.imb files