Closed hhromic closed 5 years ago
The main reason the signal masking code is in loop.c is because it's optional, as SDL will do its own signal masking (although I'm unsure if it's currently done before or after the thread creation). Therefore I've fixed the issue without moving the code to main.c and excluding the code cleanups with commit d7ac8654e58f5a5f309b8043f82a69b92062863d
The main reason the signal masking code is in loop.c is because it's optional, as SDL will do its own signal masking
Ah didn't think about SDL, you are right. Your commit is better in that case! Thanks for fixing the issue, appreciated.
Description
Signal masking (sigprocmask) must be done before any threads are created for the masking to be inherited by all threads. Otherwise, signals are captured by unmasked threads and the default system handlers are used instead.
Currently, for example if a
SIGTERM
signal is sent to Moonlight while in a streaming session, the program completely terminates without any de-initialisataion, i.e. the loop signal handler is not called and the event loop is abruptly finished (system default signal handler is called):Therefore, move the initialisation of signals and handlers to the main module where it can be done before any other threads are created, e.g. platform, video and connection threads.
With this change, when sending the example
SIGTERM
signal, now the loop signal handler is always properly called and Moonlight gracefully finishes the session:Also, this allows to simplify the loop module code.
Purpose
Fix signal handling in the Moonlight event loop.