Detect termination signals (#127)

This commit is contained in:
Isaac0-dev 2022-06-06 12:11:15 +10:00 committed by GitHub
parent fe4aab50b1
commit db7b82fc01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <signal.h>
#ifdef TARGET_WEB #ifdef TARGET_WEB
#include <emscripten.h> #include <emscripten.h>
@ -260,12 +261,17 @@ void game_deinit(void) {
} }
void game_exit(void) { void game_exit(void) {
LOG_INFO("exiting cleanly");
game_deinit(); game_deinit();
#ifndef TARGET_WEB #ifndef TARGET_WEB
exit(0); exit(0);
#endif #endif
} }
void inthand(UNUSED int signum) {
game_exit();
}
#ifdef TARGET_WEB #ifdef TARGET_WEB
static void em_main_loop(void) { static void em_main_loop(void) {
} }
@ -431,6 +437,9 @@ void main_func(void) {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
signal(SIGINT, inthand);
signal(SIGQUIT, inthand);
signal(SIGTERM, inthand);
parse_cli_opts(argc, argv); parse_cli_opts(argc, argv);
main_func(); main_func();
return 0; return 0;