瀏覽代碼

resource: add SIGINT handler to data compiler under POSIX

Daniele Bartolini 6 年之前
父節點
當前提交
3f974e0d6d
共有 1 個文件被更改,包括 13 次插入0 次删除
  1. 13 0
      src/resource/data_compiler.cpp

+ 13 - 0
src/resource/data_compiler.cpp

@@ -40,6 +40,9 @@
 #include "resource/unit_resource.h"
 #include <algorithm>
 #include <inttypes.h>
+#if CROWN_PLATFORM_POSIX
+#include <signal.h>
+#endif
 
 LOG_SYSTEM(DATA_COMPILER, "data_compiler")
 
@@ -50,6 +53,8 @@ LOG_SYSTEM(DATA_COMPILER, "data_compiler")
 
 namespace crown
 {
+static volatile bool _quit = false;
+
 static void notify_add_file(const char* path)
 {
 	TempAllocator512 ta;
@@ -1010,6 +1015,14 @@ void DataCompiler::filemonitor_callback(void* thiz, FileMonitorEvent::Enum fme,
 
 int main_data_compiler(const DeviceOptions& opts)
 {
+#if CROWN_PLATFORM_POSIX
+	struct sigaction act;
+	act.sa_handler = [](int /*signum*/) { _quit = true; };
+	sigemptyset(&act.sa_mask);
+	act.sa_flags = 0;
+	sigaction(SIGINT, &act, NULL);
+#endif // CROWN_PLATFORM_POSIX
+
 	console_server_globals::init();
 	console_server()->listen(CROWN_DEFAULT_COMPILER_PORT, opts._wait_console);