direct-io.hg

changeset 7482:e6591119fda0

Do not create the console tty until domain_create_ring has succeeded. This
means that any reads attempted on that tty will not cause handle_tty_read to
segfault looking for an interface that does not exist.

Move the writing of the tty node so that it happens after console/limit has
been read, as it is cleaner if the writing is the last thing that happens.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Mon Oct 24 14:11:07 2005 +0100 (2005-10-24)
parents 1c62a4149b11
children 98c6c36ac444
files tools/console/daemon/io.c
line diff
     1.1 --- a/tools/console/daemon/io.c	Mon Oct 24 08:04:38 2005 +0100
     1.2 +++ b/tools/console/daemon/io.c	Mon Oct 24 14:11:07 2005 +0100
     1.3 @@ -163,14 +163,6 @@ static int domain_create_tty(struct doma
     1.4  			tcsetattr(master, TCSAFLUSH, &term);
     1.5  		}
     1.6  
     1.7 -		success = asprintf(&path, "%s/tty", dom->conspath) != -1;
     1.8 -		if (!success)
     1.9 -			goto out;
    1.10 -		success = xs_write(xs, NULL, path, slave, strlen(slave));
    1.11 -		free(path);
    1.12 -		if (!success)
    1.13 -			goto out;
    1.14 -
    1.15  		success = asprintf(&path, "%s/limit", dom->conspath) != -1;
    1.16  		if (!success)
    1.17  			goto out;
    1.18 @@ -180,6 +172,14 @@ static int domain_create_tty(struct doma
    1.19  			free(data);
    1.20  		}
    1.21  		free(path);
    1.22 +
    1.23 +		success = asprintf(&path, "%s/tty", dom->conspath) != -1;
    1.24 +		if (!success)
    1.25 +			goto out;
    1.26 +		success = xs_write(xs, NULL, path, slave, strlen(slave));
    1.27 +		free(path);
    1.28 +		if (!success)
    1.29 +			goto out;
    1.30  	}
    1.31  
    1.32  	return master;
    1.33 @@ -269,6 +269,18 @@ static int domain_create_ring(struct dom
    1.34  	}
    1.35  	dom->local_port = rc;
    1.36  
    1.37 +	if (dom->tty_fd == -1) {
    1.38 +		dom->tty_fd = domain_create_tty(dom);
    1.39 +
    1.40 +		if (dom->tty_fd == -1) {
    1.41 +			err = errno;
    1.42 +			close(dom->evtchn_fd);
    1.43 +			dom->evtchn_fd = -1;
    1.44 +			dom->local_port = -1;
    1.45 +			goto out;
    1.46 +		}
    1.47 +	}
    1.48 +
    1.49   out:
    1.50  	return err;
    1.51  }
    1.52 @@ -309,7 +321,7 @@ static struct domain *create_domain(int 
    1.53  	dom->conspath = s;
    1.54  	strcat(dom->conspath, "/console");
    1.55  
    1.56 -	dom->tty_fd = domain_create_tty(dom);
    1.57 +	dom->tty_fd = -1;
    1.58  	dom->is_dead = false;
    1.59  	dom->buffer.data = 0;
    1.60  	dom->buffer.size = 0;