qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] PATCH: Put Psuedo-TTY in rawmode for char devices
Date: Tue, 22 Apr 2008 01:50:57 +0100	[thread overview]
Message-ID: <20080422005057.GD3649@redhat.com> (raw)

If running a QEMU instance with a serial/parallel device connected to a
Psuedo-TTY, eg  '-serial pty',  every \r\n sequence output by the guest
is getting translated into a \n\n sequence by the TTY layer. So clients
interacting with the serial port via a TTY done get the correct \r\n
sequence and text marches to the right and wraps. This is because the 
TTY is not put into rawmode when QEMU sets it up. 

The following patch is a re-diff of a patch applied to Xen's QEMU code.
It uses cfmakeraw() to ensure the TTY is put into rawmode, thus avoiding
the incorrect \r\n translations. It also switches to tcsetattr() on the
slave_fd instead of master_fd - although this is effectively the same on
Linux, only slave_fd works on Solaris. Finally it stops using the 'name'
arg to openpty() which is a security risk because its buffer size is
undefined. Instead it makes use of the ptsname() function.

Regards,
Daniel.

Index: vl.c
===================================================================
--- vl.c	(revision 4229)
+++ vl.c	(working copy)
@@ -2275,24 +2275,20 @@
 static CharDriverState *qemu_chr_open_pty(void)
 {
     struct termios tty;
-    char slave_name[1024];
     int master_fd, slave_fd;
 
 #if defined(__linux__)
     /* Not satisfying */
-    if (openpty(&master_fd, &slave_fd, slave_name, NULL, NULL) < 0) {
+    if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) < 0) {
         return NULL;
     }
 #endif
 
-    /* Disabling local echo and line-buffered output */
-    tcgetattr (master_fd, &tty);
-    tty.c_lflag &= ~(ECHO|ICANON|ISIG);
-    tty.c_cc[VMIN] = 1;
-    tty.c_cc[VTIME] = 0;
-    tcsetattr (master_fd, TCSAFLUSH, &tty);
+    /* Set raw attributes on the pty. */
+    cfmakeraw(&tty);
+    tcsetattr(slave_fd, TCSAFLUSH, &tty);
 
-    fprintf(stderr, "char device redirected to %s\n", slave_name);
+    fprintf(stderr, "char device redirected to %s\n", ptsname(master_fd));
     return qemu_chr_open_fd(master_fd, master_fd);
 }
 


-- 
|: Red Hat, Engineering, Boston   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

             reply	other threads:[~2008-04-22  0:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-22  0:50 Daniel P. Berrange [this message]
2008-05-01 17:14 ` [Qemu-devel] PATCH: Put Psuedo-TTY in rawmode for char devices Daniel P. Berrange
2008-05-03 23:08   ` Aurelien Jarno
2008-05-03 23:20     ` Samuel Thibault
2008-05-04 18:20     ` Daniel P. Berrange
2008-05-04 18:33       ` Samuel Thibault
2008-05-04 21:10         ` Daniel P. Berrange

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080422005057.GD3649@redhat.com \
    --to=berrange@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).