Add wait for handling SIGBREAK
[fio.git] / backend.c
index 5159b60ddfe5836765f73a5bb0cbd1f416f4f0c4..4a6a61b83580ac3edc24a4a176cd2edcafb62bb3 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -90,6 +90,25 @@ static void sig_int(int sig)
        }
 }
 
+#ifdef WIN32
+static void sig_break(int sig)
+{
+       struct thread_data *td;
+       int i;
+
+       sig_int(sig);
+
+       /**
+        * Windows terminates all job processes on SIGBREAK after the handler
+        * returns, so give them time to wrap-up and give stats
+        */
+       for_each_td(td, i) {
+               while (td->runstate < TD_EXITED)
+                       sleep(1);
+       }
+}
+#endif
+
 void sig_show_status(int sig)
 {
        show_running_run_stats();
@@ -112,7 +131,7 @@ static void set_sig_handlers(void)
 /* Windows uses SIGBREAK as a quit signal from other applications */
 #ifdef WIN32
        memset(&act, 0, sizeof(act));
-       act.sa_handler = sig_int;
+       act.sa_handler = sig_break;
        act.sa_flags = SA_RESTART;
        sigaction(SIGBREAK, &act, NULL);
 #endif