From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JslTv-0005aV-6w for qemu-devel@nongnu.org; Sun, 04 May 2008 17:10:51 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JslTs-0005aG-82 for qemu-devel@nongnu.org; Sun, 04 May 2008 17:10:50 -0400 Received: from [199.232.76.173] (port=58627 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JslTs-0005aD-2D for qemu-devel@nongnu.org; Sun, 04 May 2008 17:10:48 -0400 Received: from mx1.redhat.com ([66.187.233.31]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JslTr-0006Ej-D2 for qemu-devel@nongnu.org; Sun, 04 May 2008 17:10:47 -0400 Date: Sun, 4 May 2008 22:10:30 +0100 From: "Daniel P. Berrange" Subject: Re: [Qemu-devel] PATCH: Put Psuedo-TTY in rawmode for char devices Message-ID: <20080504211030.GA10835@redhat.com> References: <20080422005057.GD3649@redhat.com> <20080501171424.GF21335@redhat.com> <20080503230850.GA6745@volta.aurel32.net> <20080504182017.GA21786@redhat.com> <20080504183338.GL4774@implementation> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <20080504183338.GL4774@implementation> Content-Transfer-Encoding: quoted-printable 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: Samuel Thibault Cc: qemu-devel@nongnu.org, Aurelien Jarno On Sun, May 04, 2008 at 07:33:38PM +0100, Samuel Thibault wrote: > Daniel P. Berrange, le Sun 04 May 2008 19:20:17 +0100, a =E9crit : > > The updated patch also closes the slave_fd file descriptor since only > > the master_fd is needed on the QEMU end. >=20 > That will pose problems. See the corresponding thread on the Xen devel > mailing list `Fix xenconsole's "Could not read tty from store"' from 17 > december 2007: =AB=A0on linux it looks like that makes the master part > stop working: I'm getting EIO on read()s=A0=BB. Opps, thanks for mentioning that - I saw the changeset adding the code to close(slave_fd) but missed the later changeset removing it. Here's same patch with that bogus close() removed. Signed-off-by: Daniel P. Berrange Regards, Daniel Index: vl.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- vl.c (revision 4332) +++ vl.c (working copy) @@ -2269,28 +2269,78 @@ return chr; } =20 +#ifdef __sun__ +/* Once Solaris has openpty(), this is going to be removed. */ +int openpty(int *amaster, int *aslave, char *name, + struct termios *termp, struct winsize *winp) +{ + const char *slave; + int mfd =3D -1, sfd =3D -1; + + *amaster =3D *aslave =3D -1; + + mfd =3D open("/dev/ptmx", O_RDWR | O_NOCTTY); + if (mfd < 0) + goto err; + + if (grantpt(mfd) =3D=3D -1 || unlockpt(mfd) =3D=3D -1) + goto err; + + if ((slave =3D ptsname(mfd)) =3D=3D NULL) + goto err; + + if ((sfd =3D open(slave, O_RDONLY | O_NOCTTY)) =3D=3D -1) + goto err; + + if (ioctl(sfd, I_PUSH, "ptem") =3D=3D -1 || + (termp !=3D NULL && tcgetattr(sfd, termp) < 0)) + goto err; + + if (amaster) + *amaster =3D mfd; + if (aslave) + *aslave =3D sfd; + if (winp) + ioctl(sfd, TIOCSWINSZ, winp); + + return 0; + +err: + if (sfd !=3D -1) + close(sfd); + close(mfd); + return -1; +} + +void cfmakeraw (struct termios *termios_p) +{ + termios_p->c_iflag &=3D + ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); + termios_p->c_oflag &=3D ~OPOST; + termios_p->c_lflag &=3D ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); + termios_p->c_cflag &=3D ~(CSIZE|PARENB); + termios_p->c_cflag |=3D CS8; + + termios_p->c_cc[VMIN] =3D 0; + termios_p->c_cc[VTIME] =3D 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; =20 -#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 =20 - /* Disabling local echo and line-buffered output */ - tcgetattr (master_fd, &tty); - tty.c_lflag &=3D ~(ECHO|ICANON|ISIG); - tty.c_cc[VMIN] =3D 1; - tty.c_cc[VTIME] =3D 0; - tcsetattr (master_fd, TCSAFLUSH, &tty); + /* Set raw attributes on the pty. */ + cfmakeraw(&tty); + tcsetattr(slave_fd, TCSAFLUSH, &tty); =20 - 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); } =20 --=20 |: Red Hat, Engineering, Boston -o- http://people.redhat.com/berrange= / :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.or= g :| |: http://autobuild.org -o- http://search.cpan.org/~danberr= / :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 950= 5 :|