From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Daniel P. Berrange" Subject: PATCH: Put QEMU Psuedo-TTY in raw mode Date: Mon, 5 May 2008 12:59:42 +0100 Message-ID: <20080505115942.GB19958@redhat.com> Reply-To: "Daniel P. Berrange" Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: kvm-devel@lists.sourceforge.net Return-path: Content-Disposition: inline List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces@lists.sourceforge.net Errors-To: kvm-devel-bounces@lists.sourceforge.net List-Id: kvm.vger.kernel.org I'm forwarding this patch from upstream QEMU because its impotant to get this fixed in KVM to make serial console installs usable now libvirt can talk to KVM serial ports over PTYs. It was reported in this thread: http://lists.gnu.org/archive/html/qemu-devel/2008-05/msg00014.html With the final verson of the patch here: http://lists.gnu.org/archive/html/qemu-devel/2008-05/msg00135.html Recently committed to SVN http://svn.savannah.nongnu.org/viewvc?view=rev&root=qemu&revision=4338 [quote] 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. [/quote] I'm attaching a patch re-diff for KVM. Technically the #iddef _sun__ bit is useless for KVM, but better to keep 100% in sync with QEMU code for easier future merges Signed-off-by: Daniel P. Berrange c_iflag &= + ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); + termios_p->c_oflag &= ~OPOST; + termios_p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); + termios_p->c_cflag &= ~(CSIZE|PARENB); + termios_p->c_cflag |= CS8; + + termios_p->c_cc[VMIN] = 0; + termios_p->c_cc[VTIME] = 0; +} +#endif + #if defined(__linux__) || defined(__sun__) 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 :| ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone