GUI: handle SIGTERM correctly

issue #1143
This commit is contained in:
tildearrow 2023-07-09 19:19:37 -05:00
parent 319ed04946
commit 50dda44880
3 changed files with 21 additions and 0 deletions

View file

@ -6666,6 +6666,10 @@ bool FurnaceGUI::finish() {
return true; return true;
} }
void FurnaceGUI::requestQuit() {
quit=true;
}
FurnaceGUI::FurnaceGUI(): FurnaceGUI::FurnaceGUI():
e(NULL), e(NULL),
renderBackend(GUI_BACKEND_SDL), renderBackend(GUI_BACKEND_SDL),

View file

@ -2306,6 +2306,7 @@ class FurnaceGUI {
bool loop(); bool loop();
bool finish(); bool finish();
bool init(); bool init();
void requestQuit();
FurnaceGUI(); FurnaceGUI();
}; };

View file

@ -36,7 +36,10 @@
typedef HRESULT (WINAPI *SPDA)(PROCESS_DPI_AWARENESS); typedef HRESULT (WINAPI *SPDA)(PROCESS_DPI_AWARENESS);
#else #else
#include <signal.h>
#include <unistd.h> #include <unistd.h>
struct sigaction termsa;
#endif #endif
#include "cli/cli.h" #include "cli/cli.h"
@ -356,6 +359,14 @@ void reportError(String what) {
} }
#endif #endif
#ifndef _WIN32
#ifdef HAVE_GUI
static void handleTermGUI(int) {
g.requestQuit();
}
#endif
#endif
// TODO: CoInitializeEx on Windows? // TODO: CoInitializeEx on Windows?
// TODO: add crash log // TODO: add crash log
int main(int argc, char** argv) { int main(int argc, char** argv) {
@ -646,6 +657,11 @@ int main(int argc, char** argv) {
g.setFileName(fileName); g.setFileName(fileName);
} }
sigemptyset(&termsa.sa_mask);
termsa.sa_flags=0;
termsa.sa_handler=handleTermGUI;
sigaction(SIGTERM,&termsa,NULL);
g.loop(); g.loop();
logI("closing GUI."); logI("closing GUI.");
g.finish(); g.finish();