qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] Patch Send Ctrl-C to stdio target.


From: Krumme, Chris
Subject: [Qemu-devel] Patch Send Ctrl-C to stdio target.
Date: Mon, 11 Aug 2008 13:15:22 -0700

Hello,
 
This patch will catch a SIGINT and pass it as a ctrl-c to the target
when running with the target on stdio.

 Index: vl.c
===================================================================
--- vl.c        (revision 4985)
+++ vl.c        (working copy)
@@ -2353,8 +2353,46 @@
 {
     tcsetattr (0, TCSANOW, &oldtty);
     fcntl(0, F_SETFL, old_fd0_flags);
+    {
+       struct sigaction act;
+
+       /* remove ctrl-c signal handler: term_sigint_handler */
+       sigfillset(&act.sa_mask);
+       act.sa_flags = 0;
+       act.sa_handler = SIG_DFL;
+
+       sigaction(SIGINT, &act, NULL);
+    }
 }
 
+/** stdio_chr is used to save the driver used for stdio.  When a target
device
+ *  is associated with stdio this keeps the pointer to the device.
This is
+ *  used by the term_sigint_handler function to pass the Ctrl-C to the
target
+ *  device.
+ */
+static CharDriverState *stdio_chr = 0;
+
+
+/** term_sigint_handler is a signal handler that is assigned to SIGINT.
This
+ *  will send a Ctrl-C to the target if possible.
+ *  This prevents Qemu from being killed when a Ctrl-C is needed by the
target.
+ *  If Qemu needs to be stopped the Ctrl-A monitor commands can be
used.
+ *  Part of what allows this to work is that STDIO_MAX_CLIENTS is set
to 1.
+ *  There is no question as to which Driver to send the Ctrl-C to.
+ */
+static void term_sigint_handler(int host_signum)
+{
+    /* The driver must have been set, and the fifo empty. (normal case)
+     */
+    if (!term_fifo_size && stdio_chr)
+    {
+       term_fifo[term_fifo_size++] = 3;
+       qemu_chr_read(stdio_chr, term_fifo, 1);
+       term_fifo_size--;
+    }
+}
+
+
 static void term_init(void)
 {
     struct termios tty;
@@ -2381,10 +2419,22 @@
         atexit(term_exit);
 
     fcntl(0, F_SETFL, O_NONBLOCK);
+
+    {
+       struct sigaction act;
+
+       /* add ctrl-c signal handler */
+       sigfillset(&act.sa_mask);
+       act.sa_flags = 0;
+       act.sa_handler = term_sigint_handler;
+
+       sigaction(SIGINT, &act, NULL);
+    }
 }
 
 static void qemu_chr_close_stdio(struct CharDriverState *chr)
 {
+    stdio_chr = 0;
     term_exit();
     stdio_nb_clients--;
     qemu_set_fd_handler2(0, NULL, NULL, NULL, NULL);
@@ -2401,6 +2451,7 @@
     chr->chr_close = qemu_chr_close_stdio;
     qemu_set_fd_handler2(0, stdio_read_poll, stdio_read, NULL, chr);
     stdio_nb_clients++;
+    stdio_chr = chr;
     term_init();
 
     return chr;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]