Skip to contentSkip to conversation

char: disable stdio echo on resume from suspend.

PATCH Superseded Gal Hammer 3 participants 6 messages Jan 5, 2015 – Jan 6, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Gal Hammer

author
#0 lore raw

PATCH 1/1 char: disable stdio echo on resume from suspend.

The monitor's auto-completion feature stopped working when stdio is used as an input and qemu was resumed after it was suspended (using ctrl-z).

---
 qemu-char.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
qemu-char.c +11 -0
index ef84b53..786df33 100644
@@ -1113,12 +1113,22 @@ static int old_fd0_flags;
 static bool stdio_in_use;
 static bool stdio_allow_signal;
 
+static void qemu_chr_set_echo_stdio(CharDriverState *chr, bool echo);
+
 static void term_exit(void)
 {
     tcsetattr (0, TCSANOW, &oldtty);
     fcntl(0, F_SETFL, old_fd0_flags);
 }
 
+static void term_stdio_handler(int sig)
+{
+    if (sig == SIGCONT) {
+        /* echo should be off after resume from suspend. */
+        qemu_chr_set_echo_stdio(NULL, false);
+    }
+}
+
 static void qemu_chr_set_echo_stdio(CharDriverState *chr, bool echo)
 {
     struct termios tty;
@@ -1165,6 +1175,7 @@ static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts)
     tcgetattr(0, &oldtty);
     qemu_set_nonblock(0);
     atexit(term_exit);
+    signal(SIGCONT, term_stdio_handler);
 
     chr = qemu_chr_open_fd(0, 1);
     chr->chr_close = qemu_chr_close_stdio;
Signature · 1 line
2.1.0
Tested-by on v1 1/1
#1 lore raw
Quoted 2 lines · Gal Hammer

The monitor's auto-completion feature stopped working when stdio is used as an input and qemu was resumed after it was suspended (using ctrl-z).

Thanks Gal, it works now!

Quoted 42 lines
---
  qemu-char.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
qemu-char.c +11 -0
index ef84b53..786df33 100644
@@ -1113,12 +1113,22 @@ static int old_fd0_flags;
  static bool stdio_in_use;
  static bool stdio_allow_signal;
 
+static void qemu_chr_set_echo_stdio(CharDriverState *chr, bool echo);
+
  static void term_exit(void)
  {
      tcsetattr (0, TCSANOW, &oldtty);
      fcntl(0, F_SETFL, old_fd0_flags);
  }
 
+static void term_stdio_handler(int sig)
+{
+    if (sig == SIGCONT) {
+        /* echo should be off after resume from suspend. */
+        qemu_chr_set_echo_stdio(NULL, false);
+    }
+}
+
  static void qemu_chr_set_echo_stdio(CharDriverState *chr, bool echo)
  {
      struct termios tty;
@@ -1165,6 +1175,7 @@ static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts)
      tcgetattr(0, &oldtty);
      qemu_set_nonblock(0);
      atexit(term_exit);
+    signal(SIGCONT, term_stdio_handler);
 
      chr = qemu_chr_open_fd(0, 1);
      chr->chr_close = qemu_chr_close_stdio;
#2 lore raw
In reply to Gal Hammer
Quoted 17 lines · Gal Hammer

The monitor's auto-completion feature stopped working when stdio is used as an input and qemu was resumed after it was suspended (using ctrl-z).

---
 qemu-char.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
qemu-char.c +1 -0
index ef84b53..786df33 100644
@@ -1113,12 +1113,22 @@ static int old_fd0_flags;
 static bool stdio_in_use;
 static bool stdio_allow_signal;
 
+static void qemu_chr_set_echo_stdio(CharDriverState *chr, bool echo);

qemu-char.c static int old_fd0_flags; · line 1126

Quoted 10 lines
qemu-char.c +4 -0
+
 static void term_exit(void)
 {
     tcsetattr (0, TCSANOW, &oldtty);
     fcntl(0, F_SETFL, old_fd0_flags);
 }
 
+static void term_stdio_handler(int sig)
+{
+    if (sig == SIGCONT) {

...why do we need this check? We don't register the function for any other signals...

qemu-char.c static int old_fd0_flags; · line 1128

Quoted 2 lines
qemu-char.c +2 -0
+        /* echo should be off after resume from suspend. */
+        qemu_chr_set_echo_stdio(NULL, false);

Should echo really be always off, even if the thing using the char device had set it to on?

qemu-char.c static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts) · line 1178

Quoted 11 lines
qemu-char.c +4 -0
+    }
+}
+
 static void qemu_chr_set_echo_stdio(CharDriverState *chr, bool echo)
 {
     struct termios tty;
@@ -1165,6 +1175,7 @@ static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts)
     tcgetattr(0, &oldtty);
     qemu_set_nonblock(0);
     atexit(term_exit);
+    signal(SIGCONT, term_stdio_handler);

This should probably be using sigaction() which is what we use elsewhere for signal handler registration.

-- PMM

author
#3 lore raw
Quoted 25 lines · Peter Maydell
Quoted 24 lines · Gal Hammer

The monitor's auto-completion feature stopped working when stdio is used as an input and qemu was resumed after it was suspended (using ctrl-z).

---
  qemu-char.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
qemu-char.c +2 -0
index ef84b53..786df33 100644
@@ -1113,12 +1113,22 @@ static int old_fd0_flags;
  static bool stdio_in_use;
  static bool stdio_allow_signal;
 
+static void qemu_chr_set_echo_stdio(CharDriverState *chr, bool echo);
+
  static void term_exit(void)
  {
      tcsetattr (0, TCSANOW, &oldtty);
      fcntl(0, F_SETFL, old_fd0_flags);
  }
 
Quoted 6 lines

qemu-char.c static int old_fd0_flags; · line 1126

Quoted 3 lines
qemu-char.c +3 -0
+static void term_stdio_handler(int sig)
+{
+    if (sig == SIGCONT) {

...why do we need this check? We don't register the function for any other signals...

It's a caution and not a must. It can be removed if you think it is redundant.

Quoted 6 lines

qemu-char.c static int old_fd0_flags; · line 1128

Quoted 3 lines
qemu-char.c +2 -0
+        /* echo should be off after resume from suspend. */
+        qemu_chr_set_echo_stdio(NULL, false);

Should echo really be always off, even if the thing using the char device had set it to on?

That's what the function qemu_chr_open_stdio() do, always set the stdio char device echo to off. I didn't change the current behavior I just restore it.

As I understood from my tests, the auto-complete feature doesn't work if the echo is enabled because pressing the tab key prints a tab char.

Quoted 6 lines
Quoted 6 lines
qemu-char.c +3 -0
+    }
+}
+
  static void qemu_chr_set_echo_stdio(CharDriverState *chr, bool echo)
  {
      struct termios tty;
Quoted 8 lines

qemu-char.c static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts) · line 1178

Quoted 5 lines
qemu-char.c +1 -0
@@ -1165,6 +1175,7 @@ static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts)
      tcgetattr(0, &oldtty);
      qemu_set_nonblock(0);
      atexit(term_exit);
+    signal(SIGCONT, term_stdio_handler);

This should probably be using sigaction() which is what we use elsewhere for signal handler registration.

signal() is used in the code. Although I can switch to sigaction() and earn few more LOC ;-).

Quoted 3 lines

-- PMM

Gal.

#4 lore raw
Quoted 11 lines · Gal Hammer
Quoted 10 lines · Peter Maydell
Quoted 6 lines · Gal Hammer

The monitor's auto-completion feature stopped working when stdio is used as an input and qemu was resumed after it was suspended (using ctrl-z).

qemu-char.c +2 -0
+        /* echo should be off after resume from suspend. */
+        qemu_chr_set_echo_stdio(NULL, false);
Quoted 6 lines
Quoted 2 lines

Should echo really be always off, even if the thing using the char device had set it to on?

That's what the function qemu_chr_open_stdio() do, always set the stdio char device echo to off. I didn't change the current behavior I just restore it.

But qemu_chr_open_stdio also registers this function as the chr_set_echo pointer in the CharDriverState, so if the user of the CharDriverState calls qemu_chr_fe_set_echo(chr, true) then we'll set the echo to on. And then if we ^Z and resume, your patch will end up setting the echo to off, which seems wrong.

Quoted 2 lines

As I understood from my tests, the auto-complete feature doesn't work if the echo is enabled because pressing the tab key prints a tab char.

Right, if the echo was disabled we want to make sure it is disabled. But if the echo wasn't disabled we don't want to disable it.

Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
qemu-char.c +3 -0
+    }
+}
+
  static void qemu_chr_set_echo_stdio(CharDriverState *chr, bool echo)
  {
      struct termios tty;
@@ -1165,6 +1175,7 @@ static CharDriverState
 *qemu_chr_open_stdio(ChardevStdio *opts)
Quoted 8 lines

qemu-char.c static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts) · line 1178

Quoted 4 lines
qemu-char.c +1 -0
      tcgetattr(0, &oldtty);
      qemu_set_nonblock(0);
      atexit(term_exit);
+    signal(SIGCONT, term_stdio_handler);

This should probably be using sigaction() which is what we use elsewhere for signal handler registration.

Quoted 1 line

signal() is used in the code.

Only when we're setting a signal to SIG_IGN, I think. signal()'s semantics aren't portable, which is why we use sigaction(). [See the Linux signal(2) manpage for some discussion of this.]

thanks
-- PMM

author
#5 lore raw

----- Original Message -----

Quoted 26 lines

From: "Peter Maydell" <[email protected]>
To: "Gal Hammer" <[email protected]>
Cc: "Paolo Bonzini" <[email protected]>, "QEMU Developers" <[email protected]>
Sent: Tuesday, January 6, 2015 4:36:19 PM
Subject: Re: [Qemu-devel] [PATCH] char: disable stdio echo on resume from suspend.

Quoted 11 lines · Gal Hammer
Quoted 10 lines · Peter Maydell
Quoted 6 lines · Gal Hammer

The monitor's auto-completion feature stopped working when stdio is used as an input and qemu was resumed after it was suspended (using ctrl-z).

qemu-char.c +2 -0
+        /* echo should be off after resume from suspend. */
+        qemu_chr_set_echo_stdio(NULL, false);
Quoted 7 lines
Quoted 2 lines

Should echo really be always off, even if the thing using the char device had set it to on?

That's what the function qemu_chr_open_stdio() do, always set the stdio char
device echo to off. I didn't change the current behavior I just restore it.

Quoted 5 lines

But qemu_chr_open_stdio also registers this function as the chr_set_echo pointer in the CharDriverState, so if the user of the CharDriverState calls qemu_chr_fe_set_echo(chr, true) then we'll set the echo to on. And then if we ^Z and resume, your patch will end up setting the echo to off, which seems wrong.

I've missed the fact that qemu_chr_fe_set_echo(chr, true) is called if the monitor is in qmp mode. I'll post a new version of this patch.

Quoted 25 lines
Quoted 3 lines

As I understood from my tests, the auto-complete feature doesn't work if the
echo is enabled because pressing the tab key prints a tab char.

Right, if the echo was disabled we want to make sure it is disabled. But if the echo wasn't disabled we don't want to disable it.

Quoted 18 lines
Quoted 16 lines

qemu-char.c static CharDriverState · line 1179

Quoted 12 lines
qemu-char.c +4 -0
+    }
+}
+
  static void qemu_chr_set_echo_stdio(CharDriverState *chr, bool echo)
  {
      struct termios tty;
@@ -1165,6 +1175,7 @@ static CharDriverState
 *qemu_chr_open_stdio(ChardevStdio *opts)
      tcgetattr(0, &oldtty);
      qemu_set_nonblock(0);
      atexit(term_exit);
+    signal(SIGCONT, term_stdio_handler);

This should probably be using sigaction() which is what we use elsewhere for signal handler registration.

Quoted 5 lines
Quoted 1 line

signal() is used in the code.

Only when we're setting a signal to SIG_IGN, I think. signal()'s semantics aren't portable, which is why we use sigaction(). [See the Linux signal(2) manpage for some discussion of this.]

No problem. I'll use sigaction() and won't check the signal identifier in the handler function.

Quoted 4 lines

thanks
-- PMM

Gal.