ia64/xen-unstable

changeset 6566:6d4c0bfc3c1c

Wait a little bit for tty to appear.
There is a race condition that occurs after xend creates a domain.
The console client might be running before the console daemon has
noticed the new domain and setup a pty for it.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Wed Aug 31 10:24:43 2005 +0000 (2005-08-31)
parents f41f8d753b7a
children d6752f193ffa 6fa6c392d258
files tools/console/client/main.c
line diff
     1.1 --- a/tools/console/client/main.c	Wed Aug 31 09:32:52 2005 +0000
     1.2 +++ b/tools/console/client/main.c	Wed Aug 31 10:24:43 2005 +0000
     1.3 @@ -176,6 +176,7 @@ int main(int argc, char **argv)
     1.4  	unsigned int len = 0;
     1.5  	struct xs_handle *xs;
     1.6  	char *end;
     1.7 +	time_t now;
     1.8  
     1.9  	while((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {
    1.10  		switch(ch) {
    1.11 @@ -215,13 +216,37 @@ int main(int argc, char **argv)
    1.12  
    1.13  	snprintf(path, sizeof(path), "/console/%d/tty", domid);
    1.14  	str_pty = xs_read(xs, path, &len);
    1.15 +
    1.16  	/* FIXME consoled currently does not assume domain-0 doesn't have a
    1.17  	   console which is good when we break domain-0 up.  To keep us
    1.18  	   user friendly, we'll bail out here since no data will ever show
    1.19  	   up on domain-0. */
    1.20 -	if (domid == 0 || str_pty == NULL) {
    1.21 +	if (domid == 0) {
    1.22  		err(errno, "Could not read tty from store");
    1.23  	}
    1.24 +
    1.25 +	/* Wait a little bit for tty to appear.  There is a race
    1.26 +	   condition that occurs after xend creates a domain.  This
    1.27 +	   code might be running before consoled has noticed the new
    1.28 +	   domain and setup a pty for it.
    1.29 +
    1.30 +	   A xenstore watch would slightly improve responsiveness but
    1.31 +	   a timeout would still be needed since we don't want to
    1.32 +	   block forever if given an invalid domain or worse yet, a
    1.33 +	   domain that someone else has connected to. */
    1.34 +
    1.35 +	now = time(0);
    1.36 +	while (str_pty == NULL && (now + 5) > time(0)) {
    1.37 +		struct timeval tv = { 0, 500 };
    1.38 +		select(0, NULL, NULL, NULL, &tv); /* pause briefly */
    1.39 +
    1.40 +		str_pty = xs_read(xs, path, &len);
    1.41 +	}
    1.42 +
    1.43 +	if (str_pty == NULL) {
    1.44 +		err(errno, "Could not read tty from store");
    1.45 +	}
    1.46 +
    1.47  	spty = open(str_pty, O_RDWR | O_NOCTTY);
    1.48  	if (spty == -1) {
    1.49  		err(errno, "Could not open tty `%s'", str_pty);