Browse Source

Handle SIGINT signal in pcitool

Suren A. Chilingaryan 12 năm trước cách đây
mục cha
commit
4be7a59b5a
2 tập tin đã thay đổi với 17 bổ sung0 xóa
  1. 1 0
      ToDo
  2. 16 0
      cli.c

+ 1 - 0
ToDo

@@ -20,6 +20,7 @@ Normal Priority (it would make just few things a bit easier)
  3. Provide OR and AND operations on registers in cli
  4. Support writting a data from a binary file in cli
  5. Use bus-addresses instead of physcial addresses for DMA 
+ 6. Use pthread_condition_t instead of polling
  
 Low Priority (only as generalization for other projects)
 ============

+ 16 - 0
cli.c

@@ -18,6 +18,7 @@
 #include <sys/types.h>
 #include <dirent.h>
 #include <pthread.h>
+#include <signal.h>
 
 #include <getopt.h>
 
@@ -284,6 +285,14 @@ argv[0]);
     exit(0);
 }
 
+static int StopFlag = 0;
+
+static void signal_exit_handler(int signo) { 
+    if (++StopFlag > 2)
+	exit(-1);
+}
+
+
 void Error(const char *format, ...) {
     va_list ap;
     
@@ -1314,6 +1323,11 @@ void *Monitor(void *user) {
     }
     
     while (ctx->run_flag) {
+	if (StopFlag) {
+	    pcilib_stop(ctx->handle, PCILIB_EVENT_FLAG_STOP_ONLY);
+	    break;
+	}
+	
 	if (timeout) {
 	    if (pcilib_calc_time_to_deadline(&deadline) == 0) {
 		memcpy(&deadline, (struct timeval*)&ctx->last_frame, sizeof(struct timeval));
@@ -2501,6 +2515,8 @@ int main(int argc, char **argv) {
 	}
     }
 
+    signal(SIGINT, signal_exit_handler);
+
     if (output) {
 	ofile = fopen(output, "a+");
 	if (!ofile) {