ia64/xen-unstable

changeset 19239:f8187a343ad2

xenconsole: Fix pty handling

I printed the terminal attributes after openpty() and they were
garbage on the first console, valid on the second etc.
openpty() gets garbage in (uninitialized attributes MODIFIED by
cfmakeraw()). It sets the slave to the attributes requested. Using
uninitialized data for cfmakeraw->openpty results in pty attributes
that may even have the receiver disabled. Closing the slave just hides
the bug as these attributes disappear and hope the slave will be
reopened and initialized.

From: Juergen Hannken-Illjes <hannken@netbsd.org>
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Feb 20 17:02:36 2009 +0000 (2009-02-20)
parents b749d0aba17f
children 9cad48ba52b0
files tools/console/daemon/io.c
line diff
     1.1 --- a/tools/console/daemon/io.c	Fri Feb 20 11:13:11 2009 +0000
     1.2 +++ b/tools/console/daemon/io.c	Fri Feb 20 17:02:36 2009 +0000
     1.3 @@ -402,9 +402,7 @@ static int domain_create_tty(struct doma
     1.4  	assert(dom->slave_fd == -1);
     1.5  	assert(dom->master_fd == -1);
     1.6  
     1.7 -	cfmakeraw(&term);
     1.8 -
     1.9 -	if (openpty(&dom->master_fd, &dom->slave_fd, NULL, &term, NULL) < 0) {
    1.10 +	if (openpty(&dom->master_fd, &dom->slave_fd, NULL, NULL, NULL) < 0) {
    1.11  		err = errno;
    1.12  		dolog(LOG_ERR, "Failed to create tty for domain-%d "
    1.13  		      "(errno = %i, %s)",
    1.14 @@ -412,6 +410,22 @@ static int domain_create_tty(struct doma
    1.15  		return 0;
    1.16  	}
    1.17  
    1.18 +	if (tcgetattr(dom->slave_fd, &term) < 0) {
    1.19 +		err = errno;
    1.20 +		dolog(LOG_ERR, "Failed to get tty attributes for domain-%d "
    1.21 +			"(errno = %i, %s)",
    1.22 +			dom->domid, err, strerror(err));
    1.23 +		goto out;
    1.24 +	}
    1.25 +	cfmakeraw(&term);
    1.26 +	if (tcsetattr(dom->slave_fd, TCSANOW, &term) < 0) {
    1.27 +		err = errno;
    1.28 +		dolog(LOG_ERR, "Failed to set tty attributes for domain-%d "
    1.29 +			"(errno = %i, %s)",
    1.30 +			dom->domid, err, strerror(err));
    1.31 +		goto out;
    1.32 +	}
    1.33 +
    1.34  	if ((slave = ptsname(dom->master_fd)) == NULL) {
    1.35  		err = errno;
    1.36  		dolog(LOG_ERR, "Failed to get slave name for domain-%d "
    1.37 @@ -420,14 +434,6 @@ static int domain_create_tty(struct doma
    1.38  		goto out;
    1.39  	}
    1.40  
    1.41 -	/* Close the slave fd or the guest console output disappears,
    1.42 -	 * otherwise.
    1.43 -	 */
    1.44 -	if (dom->slave_fd != -1) {
    1.45 -		close(dom->slave_fd);
    1.46 -		dom->slave_fd = -1;
    1.47 -	}
    1.48 -
    1.49  	if (dom->use_consolepath) {
    1.50  		success = asprintf(&path, "%s/limit", dom->conspath) !=
    1.51  			-1;