From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Jo6jL-0002S3-U9 for qemu-devel@nongnu.org; Mon, 21 Apr 2008 20:51:31 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Jo6jF-0002Ra-GI for qemu-devel@nongnu.org; Mon, 21 Apr 2008 20:51:31 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jo6jF-0002RX-73 for qemu-devel@nongnu.org; Mon, 21 Apr 2008 20:51:25 -0400 Received: from mx1.redhat.com ([66.187.233.31]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Jo6j5-0000ow-5y for qemu-devel@nongnu.org; Mon, 21 Apr 2008 20:51:23 -0400 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m3M0owpC001339 for ; Mon, 21 Apr 2008 20:50:58 -0400 Received: from file.fab.redhat.com (file.fab.redhat.com [10.33.63.6]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m3M0ovTI009908 for ; Mon, 21 Apr 2008 20:50:58 -0400 Received: (from berrange@localhost) by file.fab.redhat.com (8.13.1/8.13.1/Submit) id m3M0ovHO019939 for qemu-devel@nongnu.org; Tue, 22 Apr 2008 01:50:57 +0100 Date: Tue, 22 Apr 2008 01:50:57 +0100 From: "Daniel P. Berrange" Message-ID: <20080422005057.GD3649@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] PATCH: Put Psuedo-TTY in rawmode for char devices Reply-To: "Daniel P. Berrange" , qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 :|