Browse Source

UI: Fix crash when using ctrl-c in Linux terminal

This fixes a seg fault that would happen when launching OBS from the
terminal and then hitting ctrl-c.
Clayton Groeneveld 6 years ago
parent
commit
cc1f239420
1 changed files with 15 additions and 0 deletions
  1. 15 0
      UI/obs-app.cpp

+ 15 - 0
UI/obs-app.cpp

@@ -2221,10 +2221,25 @@ static void upgrade_settings(void)
 	os_closedir(dir);
 	os_closedir(dir);
 }
 }
 
 
+void ctrlc_handler (int s) {
+	UNUSED_PARAMETER(s);
+
+	OBSBasic *main = reinterpret_cast<OBSBasic*>(App()->GetMainWindow());
+	main->close();
+}
+
 int main(int argc, char *argv[])
 int main(int argc, char *argv[])
 {
 {
 #ifndef _WIN32
 #ifndef _WIN32
 	signal(SIGPIPE, SIG_IGN);
 	signal(SIGPIPE, SIG_IGN);
+
+	struct sigaction sig_handler;
+
+	sig_handler.sa_handler = ctrlc_handler;
+	sigemptyset(&sig_handler.sa_mask);
+	sig_handler.sa_flags = 0;
+
+	sigaction(SIGINT, &sig_handler, NULL);
 #endif
 #endif
 
 
 #ifdef _WIN32
 #ifdef _WIN32