Skip to contentSkip to conversation

make -qmp stdio usable

PATCH In review Paolo Bonzini 2 participants 3 messages Aug 11, 2010 – Aug 23, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 make -qmp stdio usable

Currently -qmp stdio (or the equivalent -mon/-chardev combination) sets up the terminal attributes even though it does not go through readline to actually do I/O. As a result, echo is disabled and you cannot see anything you type. This patch fixes it by adding a "cooked" option to the stdio chardev backend, that when set will disable switching the tty to raw mode.

---
 qemu-char.c   |   26 ++++++++++++++------------
 qemu-config.c |    3 +++
 vl.c          |    3 +++
 3 files changed, 20 insertions(+), 12 deletions(-)
qemu-char.c +14 -12
index 6a3952c..15e1891 100644
@@ -735,19 +735,21 @@ static void term_init(QemuOpts *opts)
     oldtty = tty;
     old_fd0_flags = fcntl(0, F_GETFL);
 
-    tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
+    if (!qemu_opt_get_bool(opts, "cooked", 0)) {
+        tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
                           |INLCR|IGNCR|ICRNL|IXON);
-    tty.c_oflag |= OPOST;
-    tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
-    /* if graphical mode, we allow Ctrl-C handling */
-    if (!qemu_opt_get_bool(opts, "signal", display_type != DT_NOGRAPHIC))
-        tty.c_lflag &= ~ISIG;
-    tty.c_cflag &= ~(CSIZE|PARENB);
-    tty.c_cflag |= CS8;
-    tty.c_cc[VMIN] = 1;
-    tty.c_cc[VTIME] = 0;
-
-    tcsetattr (0, TCSANOW, &tty);
+        tty.c_oflag |= OPOST;
+        tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
+        /* if graphical mode, we allow Ctrl-C handling */
+        if (!qemu_opt_get_bool(opts, "signal", display_type != DT_NOGRAPHIC))
+            tty.c_lflag &= ~ISIG;
+        tty.c_cflag &= ~(CSIZE|PARENB);
+        tty.c_cflag |= CS8;
+        tty.c_cc[VMIN] = 1;
+        tty.c_cc[VTIME] = 0;
+
+	tcsetattr (0, TCSANOW, &tty);
+    }
 
     if (!term_atexit_done++)
         atexit(term_exit);
qemu-config.c +3 -0
index 95abe61..8c525b0 100644
@@ -146,6 +146,9 @@ QemuOptsList qemu_chardev_opts = {
         },{
             .name = "signal",
             .type = QEMU_OPT_BOOL,
+        },{
+            .name = "cooked",
+            .type = QEMU_OPT_BOOL,
         },
         { /* end if list */ }
     },
vl.c +3 -0
index b3e3676..be122e7 100644
@@ -1596,6 +1596,9 @@ static void monitor_parse(const char *optarg, const char *mode)
             fprintf(stderr, "parse error: %s\n", optarg);
             exit(1);
         }
+        if (!strcmp(mode, "control")) {
+            qemu_opt_set(opts, "cooked", "on");
+        }
     }
 
     opts = qemu_opts_create(&qemu_mon_opts, label, 1);
Signature · 1 line
1.7.1
#1 lore raw
Quoted 7 lines · Paolo Bonzini

Currently -qmp stdio (or the equivalent -mon/-chardev combination) sets up the terminal attributes even though it does not go through readline to actually do I/O. As a result, echo is disabled and you cannot see anything you type. This patch fixes it by adding a "cooked" option to the stdio chardev backend, that when set will disable switching the tty to raw mode.

cooked doesn't make a whole lot of sense to me (and it's not documented anywhere).

Maybe raw=on|off or even echo=on|off would make more sense?

Regards,

Anthony Liguori

Quoted 75 lines
---
  qemu-char.c   |   26 ++++++++++++++------------
  qemu-config.c |    3 +++
  vl.c          |    3 +++
  3 files changed, 20 insertions(+), 12 deletions(-)
qemu-char.c +14 -12
index 6a3952c..15e1891 100644
@@ -735,19 +735,21 @@ static void term_init(QemuOpts *opts)
      oldtty = tty;
      old_fd0_flags = fcntl(0, F_GETFL);
 
-    tty.c_iflag&= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
+    if (!qemu_opt_get_bool(opts, "cooked", 0)) {
+        tty.c_iflag&= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
                            |INLCR|IGNCR|ICRNL|IXON);
-    tty.c_oflag |= OPOST;
-    tty.c_lflag&= ~(ECHO|ECHONL|ICANON|IEXTEN);
-    /* if graphical mode, we allow Ctrl-C handling */
-    if (!qemu_opt_get_bool(opts, "signal", display_type != DT_NOGRAPHIC))
-        tty.c_lflag&= ~ISIG;
-    tty.c_cflag&= ~(CSIZE|PARENB);
-    tty.c_cflag |= CS8;
-    tty.c_cc[VMIN] = 1;
-    tty.c_cc[VTIME] = 0;
-
-    tcsetattr (0, TCSANOW,&tty);
+        tty.c_oflag |= OPOST;
+        tty.c_lflag&= ~(ECHO|ECHONL|ICANON|IEXTEN);
+        /* if graphical mode, we allow Ctrl-C handling */
+        if (!qemu_opt_get_bool(opts, "signal", display_type != DT_NOGRAPHIC))
+            tty.c_lflag&= ~ISIG;
+        tty.c_cflag&= ~(CSIZE|PARENB);
+        tty.c_cflag |= CS8;
+        tty.c_cc[VMIN] = 1;
+        tty.c_cc[VTIME] = 0;
+
+	tcsetattr (0, TCSANOW,&tty);
+    }
 
      if (!term_atexit_done++)
          atexit(term_exit);
qemu-config.c +3 -0
index 95abe61..8c525b0 100644
@@ -146,6 +146,9 @@ QemuOptsList qemu_chardev_opts = {
          },{
              .name = "signal",
              .type = QEMU_OPT_BOOL,
+        },{
+            .name = "cooked",
+            .type = QEMU_OPT_BOOL,
          },
          { /* end if list */ }
      },
vl.c +3 -0
index b3e3676..be122e7 100644
@@ -1596,6 +1596,9 @@ static void monitor_parse(const char *optarg, const char *mode)
              fprintf(stderr, "parse error: %s\n", optarg);
              exit(1);
          }
+        if (!strcmp(mode, "control")) {
+            qemu_opt_set(opts, "cooked", "on");
+        }
      }
 
      opts = qemu_opts_create(&qemu_mon_opts, label, 1);
#2 lore raw
Quoted 10 lines · Anthony Liguori
Quoted 6 lines · Paolo Bonzini

Currently -qmp stdio (or the equivalent -mon/-chardev combination) sets up the terminal attributes even though it does not go through readline to actually do I/O. As a result, echo is disabled and you cannot see anything you type. This patch fixes it by adding a "cooked" option to the stdio chardev backend, that when set will disable switching the tty to raw mode.

cooked doesn't make a whole lot of sense to me (and it's not documented anywhere).

"Cooked mode" is actually pretty common when talking about the Unix TTYs, I can find it for example in curses documentation:

Normally, the tty driver buffers typed characters until a newline or carriage return is typed. The cbreak routine disables line buffering and erase/kill character-processing (interrupt and flow control characters are unaffected), making characters typed by the user immediately available to the program. The nocbreak routine returns the terminal to normal (cooked) mode.

Quoted 1 line

Maybe raw=on|off or even echo=on|off would make more sense?

raw would make sense, echo was my first choice but it has the problem that echo is done anyway when Qemu's readline is involved.

I'll redo the patch with raw.

Paolo