Patchwork [v2,1/2] trap signals for "-serial mon:stdio"

login
register
mail settings
Submitter Michael Tokarev
Date July 3, 2013, 6:44 a.m.
Message ID <1372833874-21416-1-git-send-email-mjt@msgid.tls.msk.ru>
Download mbox | patch
Permalink /patch/256544/
State New
Headers show

Comments

Michael Tokarev - July 3, 2013, 6:44 a.m.
From: Paolo Bonzini <pbonzini@redhat.com>

With mon:stdio you can exit the VM by switching to the monitor and
sending the "quit" command.  It is then useful to pass Ctrl-C to the
VM instead of exiting.

This in turn lets us stop tying the default signal handling behavior
to -nographic, removing gratuitous differences between "-display none"
and "-nographic".

This patch changes behavior for "-display none -serial mon:stdio", as
expected, but not for "-display none -serial stdio".

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
V2: added code comments and documentation fixes by mjt
  (hopefully the s-o-b stands still)

 qemu-char.c     |   13 +++++++++----
 qemu-options.hx |    8 +++++---
 2 files changed, 14 insertions(+), 7 deletions(-)
Paolo Bonzini - July 3, 2013, 7:08 a.m.
Il 03/07/2013 08:44, Michael Tokarev ha scritto:
> V2: added code comments and documentation fixes by mjt
>   (hopefully the s-o-b stands still)

Yes, s-o-b means I effectively donate the patch to the community.

Paolo
Paolo Bonzini - July 3, 2013, 7:13 a.m.
Il 03/07/2013 08:44, Michael Tokarev ha scritto:
> From: Paolo Bonzini <pbonzini@redhat.com>
> 
> With mon:stdio you can exit the VM by switching to the monitor and
> sending the "quit" command.  It is then useful to pass Ctrl-C to the
> VM instead of exiting.
> 
> This in turn lets us stop tying the default signal handling behavior
> to -nographic, removing gratuitous differences between "-display none"
> and "-nographic".
> 
> This patch changes behavior for "-display none -serial mon:stdio", as
> expected, but not for "-display none -serial stdio".
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> V2: added code comments and documentation fixes by mjt
>   (hopefully the s-o-b stands still)
> 
>  qemu-char.c     |   13 +++++++++----
>  qemu-options.hx |    8 +++++---
>  2 files changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/qemu-char.c b/qemu-char.c
> index 6cec5d7..18c42a3 100644
> --- a/qemu-char.c
> +++ b/qemu-char.c
> @@ -926,7 +926,6 @@ static void qemu_chr_set_echo_stdio(CharDriverState *chr, bool echo)
>          tty.c_cc[VMIN] = 1;
>          tty.c_cc[VTIME] = 0;
>      }
> -    /* if graphical mode, we allow Ctrl-C handling */
>      if (!stdio_allow_signal)
>          tty.c_lflag &= ~ISIG;
>  
> @@ -955,7 +954,6 @@ static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts)
>      chr = qemu_chr_open_fd(0, 1);
>      chr->chr_close = qemu_chr_close_stdio;
>      chr->chr_set_echo = qemu_chr_set_echo_stdio;
> -    stdio_allow_signal = display_type != DT_NOGRAPHIC;
>      if (opts->has_signal) {
>          stdio_allow_signal = opts->signal;
>      }
> @@ -2932,6 +2930,14 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename)
>      if (strstart(filename, "mon:", &p)) {
>          filename = p;
>          qemu_opt_set(opts, "mux", "on");
> +        if (strcmp(filename, "stdio") == 0) {
> +            /* Monitor is muxed to stdio: do not exit on Ctrl+C by default
> +             * but pass it to the guest.  Handle this only for compat syntax,
> +             * for -chardev syntax we have special option for this.
> +             * This is what -nographic did, redirecting+muxing serial+monitor
> +             * to stdio causing Ctrl+C to be passed to guest. */
> +            qemu_opt_set(opts, "signal", "off");
> +        }
>      }
>  
>      if (strcmp(filename, "null")    == 0 ||
> @@ -3060,8 +3066,7 @@ static void qemu_chr_parse_stdio(QemuOpts *opts, ChardevBackend *backend,
>  {
>      backend->stdio = g_new0(ChardevStdio, 1);
>      backend->stdio->has_signal = true;
> -    backend->stdio->signal =
> -        qemu_opt_get_bool(opts, "signal", display_type != DT_NOGRAPHIC);
> +    backend->stdio->signal = qemu_opt_get_bool(opts, "signal", true);
>  }
>  
>  static void qemu_chr_parse_serial(QemuOpts *opts, ChardevBackend *backend,
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 137a39b..d676b03 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -842,7 +842,8 @@ STEXI
>  Normally, QEMU uses SDL to display the VGA output. With this option,
>  you can totally disable graphical output so that QEMU is a simple
>  command line application. The emulated serial port is redirected on
> -the console. Therefore, you can still use QEMU to debug a Linux kernel
> +the console and muxed with the monitor (unless redirected elsewhere
> +explicitly).

By default, the emulated serial port and the monitor are multiplexed on
the console; @option{-serial} and @option{-monitor} can be used to
change this default.

 Therefore, you can still use QEMU to debug a Linux kernel
>  with a serial console.
>  ETEXI
>  
> @@ -2485,14 +2486,15 @@ same as if you had specified @code{-serial tcp} except the unix domain socket
>  @item mon:@var{dev_string}
>  This is a special option to allow the monitor to be multiplexed onto
>  another serial port.  The monitor is accessed with key sequence of
> -@key{Control-a} and then pressing @key{c}. See monitor access
> -@ref{pcsys_keys} in the -nographic section for more keys.
> +@key{Control-a} and then pressing @key{c}.
>  @var{dev_string} should be any one of the serial devices specified
>  above.  An example to multiplex the monitor onto a telnet server
>  listening on port 4444 would be:
>  @table @code
>  @item -serial mon:telnet::4444,server,nowait
>  @end table
> +When monitor is multiplexed to stdio this way, Ctrl+C will not terminate
> +guest anymore but will be passed to the guest as is.

will not terminate QEMU anymore...
>  
>  @item braille
>  Braille device.  This will use BrlAPI to display the braille output on a real
> 

Also, there is another reference to -nographic here:

@item -echr @var{numeric_ascii_value}
@findex -echr
Change the escape character used for switching to the monitor when using
monitor and serial sharing.  The default is @code{0x01} when using the
@code{-nographic} option.  @code{0x01} is equal to pressing
@code{Control-a}.  You can select a different character from the ascii
control keys where 1 through 26 map to Control-a through Control-z.  For
instance you could use the either of the following to change the escape
character to Control-t.

You could remove "when using the @code{-nographic} option" from this
paragraph.

Paolo

Patch

diff --git a/qemu-char.c b/qemu-char.c
index 6cec5d7..18c42a3 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -926,7 +926,6 @@  static void qemu_chr_set_echo_stdio(CharDriverState *chr, bool echo)
         tty.c_cc[VMIN] = 1;
         tty.c_cc[VTIME] = 0;
     }
-    /* if graphical mode, we allow Ctrl-C handling */
     if (!stdio_allow_signal)
         tty.c_lflag &= ~ISIG;
 
@@ -955,7 +954,6 @@  static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts)
     chr = qemu_chr_open_fd(0, 1);
     chr->chr_close = qemu_chr_close_stdio;
     chr->chr_set_echo = qemu_chr_set_echo_stdio;
-    stdio_allow_signal = display_type != DT_NOGRAPHIC;
     if (opts->has_signal) {
         stdio_allow_signal = opts->signal;
     }
@@ -2932,6 +2930,14 @@  QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename)
     if (strstart(filename, "mon:", &p)) {
         filename = p;
         qemu_opt_set(opts, "mux", "on");
+        if (strcmp(filename, "stdio") == 0) {
+            /* Monitor is muxed to stdio: do not exit on Ctrl+C by default
+             * but pass it to the guest.  Handle this only for compat syntax,
+             * for -chardev syntax we have special option for this.
+             * This is what -nographic did, redirecting+muxing serial+monitor
+             * to stdio causing Ctrl+C to be passed to guest. */
+            qemu_opt_set(opts, "signal", "off");
+        }
     }
 
     if (strcmp(filename, "null")    == 0 ||
@@ -3060,8 +3066,7 @@  static void qemu_chr_parse_stdio(QemuOpts *opts, ChardevBackend *backend,
 {
     backend->stdio = g_new0(ChardevStdio, 1);
     backend->stdio->has_signal = true;
-    backend->stdio->signal =
-        qemu_opt_get_bool(opts, "signal", display_type != DT_NOGRAPHIC);
+    backend->stdio->signal = qemu_opt_get_bool(opts, "signal", true);
 }
 
 static void qemu_chr_parse_serial(QemuOpts *opts, ChardevBackend *backend,
diff --git a/qemu-options.hx b/qemu-options.hx
index 137a39b..d676b03 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -842,7 +842,8 @@  STEXI
 Normally, QEMU uses SDL to display the VGA output. With this option,
 you can totally disable graphical output so that QEMU is a simple
 command line application. The emulated serial port is redirected on
-the console. Therefore, you can still use QEMU to debug a Linux kernel
+the console and muxed with the monitor (unless redirected elsewhere
+explicitly). Therefore, you can still use QEMU to debug a Linux kernel
 with a serial console.
 ETEXI
 
@@ -2485,14 +2486,15 @@  same as if you had specified @code{-serial tcp} except the unix domain socket
 @item mon:@var{dev_string}
 This is a special option to allow the monitor to be multiplexed onto
 another serial port.  The monitor is accessed with key sequence of
-@key{Control-a} and then pressing @key{c}. See monitor access
-@ref{pcsys_keys} in the -nographic section for more keys.
+@key{Control-a} and then pressing @key{c}.
 @var{dev_string} should be any one of the serial devices specified
 above.  An example to multiplex the monitor onto a telnet server
 listening on port 4444 would be:
 @table @code
 @item -serial mon:telnet::4444,server,nowait
 @end table
+When monitor is multiplexed to stdio this way, Ctrl+C will not terminate
+guest anymore but will be passed to the guest as is.
 
 @item braille
 Braille device.  This will use BrlAPI to display the braille output on a real