All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] Patch Send Ctrl-C to stdio target.
@ 2008-08-11 20:15 Krumme, Chris
  2008-08-11 21:13 ` Anthony Liguori
  0 siblings, 1 reply; 8+ messages in thread
From: Krumme, Chris @ 2008-08-11 20:15 UTC (permalink / raw)
  To: qemu-devel

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;

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-08-12 21:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-11 20:15 [Qemu-devel] Patch Send Ctrl-C to stdio target Krumme, Chris
2008-08-11 21:13 ` Anthony Liguori
2008-08-12 15:31   ` Krumme, Chris
2008-08-12 15:36     ` Samuel Thibault
2008-08-12 18:34       ` Krumme, Chris
2008-08-12 21:01         ` Samuel Thibault
2008-08-12 16:15     ` Anthony Liguori
2008-08-12 19:06       ` Krumme, Chris

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.