diff --git a/src/osd/osd_main.cpp b/src/osd/osd_main.cpp index ab18f273..4ed34988 100644 --- a/src/osd/osd_main.cpp +++ b/src/osd/osd_main.cpp @@ -7,19 +7,19 @@ #include #include +#include static osd_t *osd = NULL; -static bool force_stopping = false; +static volatile sig_atomic_t stop_signal = 0; +// Only async-signal-safe calls are allowed here, the OSD is stopped by the main loop static void handle_sigint(int sig) { - if (osd && !force_stopping) + if (stop_signal) { - force_stopping = true; - osd->force_stop(0); - return; + _exit(0); } - exit(0); + stop_signal = 1; } static const char* help_text = @@ -83,9 +83,15 @@ int main(int narg, char *args[]) return 1; } osd->start(); + bool force_stopping = false; while (1) { ringloop->loop(); + if (stop_signal && !force_stopping) + { + force_stopping = true; + osd->force_stop(0); + } ringloop->wait(); } delete osd;