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

* Re: [Qemu-devel] Patch Send Ctrl-C to stdio target.
  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
  0 siblings, 1 reply; 8+ messages in thread
From: Anthony Liguori @ 2008-08-11 21:13 UTC (permalink / raw)
  To: qemu-devel

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

Just catching SIGINT is kind of a hack.  What about SIGSTOP and SIGCONT?

If we're going to go this route, we should do it properly by cfmakeraw() 
stdio instead of trapping individual signals.

Regards,

Anthony Liguori

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

* RE: [Qemu-devel] Patch Send Ctrl-C to stdio target.
  2008-08-11 21:13 ` Anthony Liguori
@ 2008-08-12 15:31   ` Krumme, Chris
  2008-08-12 15:36     ` Samuel Thibault
  2008-08-12 16:15     ` Anthony Liguori
  0 siblings, 2 replies; 8+ messages in thread
From: Krumme, Chris @ 2008-08-12 15:31 UTC (permalink / raw)
  To: qemu-devel

Hello Anthony,

You were quite right, the ckmakeraw function was the direction to go.

It turns out that the utility of that function had already been hard
coded in vl.c, with one twist.  The ISIG attribute was controlled by the
-nographic option.

In my use I had written a script that backdoored -nographic by setting
the various outputs to use stdio instead of VGA, but I had not used the
-nographic option. This meant I had all of the functionality of
-nographic except the ISIG attribute (and a banner message :-).  This
lead me to want to get rid of the SIGINT.

So now I have to ask: what is the connection between ISIG for Control-C
handling and using the monitor, serial port, or parallel port on stdio.
If any one of these uses stdio then I think the ISIG should be used
without regard to the -nographic option.

Thanks

Chris

Here is a patch to affect this change:
Index: vl.c
===================================================================
--- vl.c	(revision 4995)
+++ vl.c	(working copy)
@@ -2368,8 +2368,7 @@
     tty.c_oflag |= OPOST;
     tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
     /* if graphical mode, we allow Ctrl-C handling */
-    if (nographic)
-        tty.c_lflag &= ~ISIG;
+    tty.c_lflag &= ~ISIG;
     tty.c_cflag &= ~(CSIZE|PARENB);
     tty.c_cflag |= CS8;
     tty.c_cc[VMIN] = 1;




-----Original Message-----
From: qemu-devel-bounces+chris.krumme=windriver.com@nongnu.org
[mailto:qemu-devel-bounces+chris.krumme=windriver.com@nongnu.org] On
Behalf Of Anthony Liguori
Sent: Monday, August 11, 2008 4:14 PM
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] Patch Send Ctrl-C to stdio target.

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

Just catching SIGINT is kind of a hack.  What about SIGSTOP and SIGCONT?

If we're going to go this route, we should do it properly by cfmakeraw()
stdio instead of trapping individual signals.

Regards,

Anthony Liguori

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

* Re: [Qemu-devel] Patch Send Ctrl-C to stdio target.
  2008-08-12 15:31   ` Krumme, Chris
@ 2008-08-12 15:36     ` Samuel Thibault
  2008-08-12 18:34       ` Krumme, Chris
  2008-08-12 16:15     ` Anthony Liguori
  1 sibling, 1 reply; 8+ messages in thread
From: Samuel Thibault @ 2008-08-12 15:36 UTC (permalink / raw)
  To: qemu-devel

Just to make sure: are you aware of the -curses option?

Samuel

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

* Re: [Qemu-devel] Patch Send Ctrl-C to stdio target.
  2008-08-12 15:31   ` Krumme, Chris
  2008-08-12 15:36     ` Samuel Thibault
@ 2008-08-12 16:15     ` Anthony Liguori
  2008-08-12 19:06       ` Krumme, Chris
  1 sibling, 1 reply; 8+ messages in thread
From: Anthony Liguori @ 2008-08-12 16:15 UTC (permalink / raw)
  To: qemu-devel

Krumme, Chris wrote:
> Hello Anthony,
>
> You were quite right, the ckmakeraw function was the direction to go.
>
> It turns out that the utility of that function had already been hard
> coded in vl.c, with one twist.  The ISIG attribute was controlled by the
> -nographic option.
>
> In my use I had written a script that backdoored -nographic by setting
> the various outputs to use stdio instead of VGA, but I had not used the
> -nographic option. This meant I had all of the functionality of
> -nographic except the ISIG attribute (and a banner message :-).  This
> lead me to want to get rid of the SIGINT.
>
> So now I have to ask: what is the connection between ISIG for Control-C
> handling and using the monitor, serial port, or parallel port on stdio.
> If any one of these uses stdio then I think the ISIG should be used
> without regard to the -nographic option.
>   

That would be a bit of a pain.  When you use -nographic, you get monitor 
multiplexing which means that you can kill the qemu process by doing 
'C-a x'.  If we unconditionally set ISIG when -serial stdio then it's 
impossible to kill the QEMU process from the same tty which is a bit 
annoying.

In the very least, it needs to be a non default option for stdio.  
However, I should ask, why are you not just using -nographic?

Regards,

Anthony Liguori

> Thanks
>
> Chris
>
> Here is a patch to affect this change:
> Index: vl.c
> ===================================================================
> --- vl.c	(revision 4995)
> +++ vl.c	(working copy)
> @@ -2368,8 +2368,7 @@
>      tty.c_oflag |= OPOST;
>      tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
>      /* if graphical mode, we allow Ctrl-C handling */
> -    if (nographic)
> -        tty.c_lflag &= ~ISIG;
> +    tty.c_lflag &= ~ISIG;
>      tty.c_cflag &= ~(CSIZE|PARENB);
>      tty.c_cflag |= CS8;
>      tty.c_cc[VMIN] = 1;
>
>
>
>
> -----Original Message-----
> From: qemu-devel-bounces+chris.krumme=windriver.com@nongnu.org
> [mailto:qemu-devel-bounces+chris.krumme=windriver.com@nongnu.org] On
> Behalf Of Anthony Liguori
> Sent: Monday, August 11, 2008 4:14 PM
> To: qemu-devel@nongnu.org
> Subject: Re: [Qemu-devel] Patch Send Ctrl-C to stdio target.
>
> Krumme, Chris wrote:
>   
>> Hello,
>>  
>> This patch will catch a SIGINT and pass it as a ctrl-c to the target 
>> when running with the target on stdio.
>>   
>>     
>
> Just catching SIGINT is kind of a hack.  What about SIGSTOP and SIGCONT?
>
> If we're going to go this route, we should do it properly by cfmakeraw()
> stdio instead of trapping individual signals.
>
> Regards,
>
> Anthony Liguori
>
>
>
>
>
>   

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

* RE: [Qemu-devel] Patch Send Ctrl-C to stdio target.
  2008-08-12 15:36     ` Samuel Thibault
@ 2008-08-12 18:34       ` Krumme, Chris
  2008-08-12 21:01         ` Samuel Thibault
  0 siblings, 1 reply; 8+ messages in thread
From: Krumme, Chris @ 2008-08-12 18:34 UTC (permalink / raw)
  To: qemu-devel

Hello Samuel,

Okay, I see the -curses option. I have looked at the code a bit. I have
not used curses recently.

While I see this as a fancy way of doing terminal control, I do not
appreciate how it helps.

One of the features seems to deal with SIGWINCH, but there is no way to
pass that to the target OS so it seems limited to helping the monitor.

The code without the -curses option uses the termio package, is curses
that much better at initing the terminal?

Thanks

Chris 

-----Original Message-----
From: qemu-devel-bounces+chris.krumme=windriver.com@nongnu.org
[mailto:qemu-devel-bounces+chris.krumme=windriver.com@nongnu.org] On
Behalf Of Samuel Thibault
Sent: Tuesday, August 12, 2008 10:36 AM
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] Patch Send Ctrl-C to stdio target.

Just to make sure: are you aware of the -curses option?

Samuel

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

* RE: [Qemu-devel] Patch Send Ctrl-C to stdio target.
  2008-08-12 16:15     ` Anthony Liguori
@ 2008-08-12 19:06       ` Krumme, Chris
  0 siblings, 0 replies; 8+ messages in thread
From: Krumme, Chris @ 2008-08-12 19:06 UTC (permalink / raw)
  To: qemu-devel

 

> -----Original Message-----
> From: 
> qemu-devel-bounces+chris.krumme=windriver.com@nongnu.org 
> [mailto:qemu-devel-bounces+chris.krumme=windriver.com@nongnu.o
rg] On Behalf Of Anthony Liguori
> Sent: Tuesday, August 12, 2008 11:16 AM
> To: qemu-devel@nongnu.org
> Subject: Re: [Qemu-devel] Patch Send Ctrl-C to stdio target.
> 
> Krumme, Chris wrote:
> > Hello Anthony,
> >
> > You were quite right, the ckmakeraw function was the 
> direction to go.
> >
> > It turns out that the utility of that function had already 
> been hard 
> > coded in vl.c, with one twist.  The ISIG attribute was 
> controlled by 
> > the -nographic option.
> >
> > In my use I had written a script that backdoored -nographic 
> by setting 
> > the various outputs to use stdio instead of VGA, but I had not used 
> > the -nographic option. This meant I had all of the functionality of 
> > -nographic except the ISIG attribute (and a banner message 
> :-).  This 
> > lead me to want to get rid of the SIGINT.
> >
> > So now I have to ask: what is the connection between ISIG for 
> > Control-C handling and using the monitor, serial port, or 
> parallel port on stdio.
> > If any one of these uses stdio then I think the ISIG should be used 
> > without regard to the -nographic option.
> >   
> 
> That would be a bit of a pain.  When you use -nographic, you 
> get monitor multiplexing which means that you can kill the 
> qemu process by doing 'C-a x'.  If we unconditionally set 
> ISIG when -serial stdio then it's impossible to kill the QEMU 
> process from the same tty which is a bit annoying.
> 
> In the very least, it needs to be a non default option for stdio.  
> However, I should ask, why are you not just using -nographic?
> 

You refer to -nographic as causing the multiplexing, the multiplexing is
caused by the mon:stdio option. -nographic has this side effect.

Since I was working on writing a script that helped the user by having a
limited set of options and taking care of some things for the user such
as creating the tftpboot directory with the right files and setting up
some of the networking and redirection for them. I don't think I am in
the -nographic mode since I actually have a vnc option. (The vga does
not have a shell in my kernel, so it is just startup messages.) I may
start using -nographic or -curses, though the advantage of each are not
well documented.

So now for the issue of quitting Qemu. There are a few cases:
Multiplexing: ^a x works. Only -serial stdio: Monitor is still available
on vga, just not part of the stdio, 'quit' works. -monitor none: in this
case ^c is not available for killing qemu, only 'kill' would work.

I ask the question the other way around: since ^c is used for line
editing in many shells when would you ever not want to send the ^c to
the target?

I only want to kill qemu occasionally when using a stdio shell. I find
it very annoying to be typing a command, then decide to go another
direction and press ^c to find not just my line gone but my entire
system :-)

Obviously personal usage is a big part of this. You say you don't think
this is a good default, you think it would be better to add another
option? Or to add a stdio sub-options?

Thanks

Chris

> Regards,
> 
> Anthony Liguori
> 
> > Thanks
> >
> > Chris
> >
> > Here is a patch to affect this change:
> > Index: vl.c
> > ===================================================================
> > --- vl.c	(revision 4995)
> > +++ vl.c	(working copy)
> > @@ -2368,8 +2368,7 @@
> >      tty.c_oflag |= OPOST;
> >      tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
> >      /* if graphical mode, we allow Ctrl-C handling */
> > -    if (nographic)
> > -        tty.c_lflag &= ~ISIG;
> > +    tty.c_lflag &= ~ISIG;
> >      tty.c_cflag &= ~(CSIZE|PARENB);
> >      tty.c_cflag |= CS8;
> >      tty.c_cc[VMIN] = 1;
> >
> >
> >
> >
> > -----Original Message-----
> > From: qemu-devel-bounces+chris.krumme=windriver.com@nongnu.org
> > 
> [mailto:qemu-devel-bounces+chris.krumme=windriver.com@nongnu.org] On 
> > Behalf Of Anthony Liguori
> > Sent: Monday, August 11, 2008 4:14 PM
> > To: qemu-devel@nongnu.org
> > Subject: Re: [Qemu-devel] Patch Send Ctrl-C to stdio target.
> >
> > Krumme, Chris wrote:
> >   
> >> Hello,
> >>  
> >> This patch will catch a SIGINT and pass it as a ctrl-c to 
> the target 
> >> when running with the target on stdio.
> >>   
> >>     
> >
> > Just catching SIGINT is kind of a hack.  What about SIGSTOP 
> and SIGCONT?
> >
> > If we're going to go this route, we should do it properly by 
> > cfmakeraw() stdio instead of trapping individual signals.
> >
> > Regards,
> >
> > Anthony Liguori
> >
> >
> >
> >
> >
> >   
> 
> 
> 
> 

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

* Re: [Qemu-devel] Patch Send Ctrl-C to stdio target.
  2008-08-12 18:34       ` Krumme, Chris
@ 2008-08-12 21:01         ` Samuel Thibault
  0 siblings, 0 replies; 8+ messages in thread
From: Samuel Thibault @ 2008-08-12 21:01 UTC (permalink / raw)
  To: qemu-devel

Krumme, Chris, le Tue 12 Aug 2008 11:34:56 -0700, a écrit :
> One of the features seems to deal with SIGWINCH, but there is no way to
> pass that to the target OS so it seems limited to helping the monitor.

Indeed.  The interface with the target OS remains the VGA layer. But you
can resize the screen from the OS itself by using e.g. stty rows which
tinkers with VGA registers.

> The code without the -curses option uses the termio package, is curses
> that much better at initing the terminal?

curses is _the_ library which is supposed to know how to handle such
issues.  So by definition nothing can be better.

Samuel

^ 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.