ia64/xen-unstable

changeset 6013:2c0bc4caaa1f

1) Make more functions in io.c static
2) Fix memory leak in domain free
3) Fix error path in read (reported by aq)
4) Move reading of buffer limit to tty reconnect so that changes in
limit take affect more quickly.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed Aug 03 09:32:39 2005 +0000 (2005-08-03)
parents f17987201c08
children 18bb29989371
files tools/consoled/io.c tools/consoled/xc_console.c
line diff
     1.1 --- a/tools/consoled/io.c	Wed Aug 03 09:06:10 2005 +0000
     1.2 +++ b/tools/consoled/io.c	Wed Aug 03 09:32:39 2005 +0000
     1.3 @@ -48,7 +48,7 @@ struct buffer
     1.4  	size_t max_capacity;
     1.5  };
     1.6  
     1.7 -void buffer_append(struct buffer *buffer, const void *data, size_t size)
     1.8 +static void buffer_append(struct buffer *buffer, const void *data, size_t size)
     1.9  {
    1.10  	if ((buffer->capacity - buffer->size) < size) {
    1.11  		buffer->capacity += (size + 1024);
    1.12 @@ -71,12 +71,12 @@ void buffer_append(struct buffer *buffer
    1.13  	}
    1.14  }
    1.15  
    1.16 -bool buffer_empty(struct buffer *buffer)
    1.17 +static bool buffer_empty(struct buffer *buffer)
    1.18  {
    1.19  	return buffer->size == 0;
    1.20  }
    1.21  
    1.22 -void buffer_advance(struct buffer *buffer, size_t size)
    1.23 +static void buffer_advance(struct buffer *buffer, size_t size)
    1.24  {
    1.25  	size = MIN(size, buffer->size);
    1.26  	memmove(buffer->data, buffer + size, buffer->size - size);
    1.27 @@ -93,7 +93,7 @@ struct domain
    1.28  
    1.29  static struct domain *dom_head;
    1.30  
    1.31 -bool domain_is_valid(int domid)
    1.32 +static bool domain_is_valid(int domid)
    1.33  {
    1.34  	bool ret;
    1.35  	xc_dominfo_t info;
    1.36 @@ -104,18 +104,21 @@ bool domain_is_valid(int domid)
    1.37  	return ret;
    1.38  }
    1.39  
    1.40 -int domain_create_tty(int domid)
    1.41 +static int domain_create_tty(struct domain *dom)
    1.42  {
    1.43  	char path[1024];
    1.44  	int master;
    1.45  
    1.46  	if ((master = getpt()) == -1 ||
    1.47  	    grantpt(master) == -1 || unlockpt(master) == -1) {
    1.48 -		dolog(LOG_ERR, "Failed to create tty for domain-%d", domid);
    1.49 +		dolog(LOG_ERR, "Failed to create tty for domain-%d",
    1.50 +		      dom->domid);
    1.51  		master = -1;
    1.52  	} else {
    1.53  		const char *slave = ptsname(master);
    1.54  		struct termios term;
    1.55 +		char *data;
    1.56 +		unsigned int len;
    1.57  
    1.58  		if (tcgetattr(master, &term) != -1) {
    1.59  			cfmakeraw(&term);
    1.60 @@ -123,22 +126,26 @@ int domain_create_tty(int domid)
    1.61  		}
    1.62  
    1.63  		xs_mkdir(xs, "/console");
    1.64 -		snprintf(path, sizeof(path), "/console/%d", domid);
    1.65 +		snprintf(path, sizeof(path), "/console/%d", dom->domid);
    1.66  		xs_mkdir(xs, path);
    1.67  		strcat(path, "/tty");
    1.68  
    1.69  		xs_write(xs, path, slave, strlen(slave), O_CREAT);
    1.70 +
    1.71 +		snprintf(path, sizeof(path), "/console/%d/limit", dom->domid);
    1.72 +		data = xs_read(xs, path, &len);
    1.73 +		if (data) {
    1.74 +			dom->buffer.max_capacity = strtoul(data, 0, 0);
    1.75 +			free(data);
    1.76 +		}
    1.77  	}
    1.78  
    1.79  	return master;
    1.80  }
    1.81  
    1.82 -struct domain *create_domain(int domid)
    1.83 +static struct domain *create_domain(int domid)
    1.84  {
    1.85  	struct domain *dom;
    1.86 -	char *data;
    1.87 -	unsigned int len;
    1.88 -	char path[1024];
    1.89  
    1.90  	dom = (struct domain *)malloc(sizeof(struct domain));
    1.91  	if (dom == NULL) {
    1.92 @@ -148,25 +155,18 @@ struct domain *create_domain(int domid)
    1.93  	}
    1.94  
    1.95  	dom->domid = domid;
    1.96 -	dom->tty_fd = domain_create_tty(domid);
    1.97 +	dom->tty_fd = domain_create_tty(dom);
    1.98  	dom->buffer.data = 0;
    1.99  	dom->buffer.size = 0;
   1.100  	dom->buffer.capacity = 0;
   1.101  	dom->buffer.max_capacity = 0;
   1.102  
   1.103 -	snprintf(path, sizeof(path), "/console/%d/limit", domid);
   1.104 -	data = xs_read(xs, path, &len);
   1.105 -	if (data) {
   1.106 -		dom->buffer.max_capacity = strtoul(data, 0, 0);
   1.107 -		free(data);
   1.108 -	}
   1.109 -
   1.110  	dolog(LOG_DEBUG, "New domain %d", domid);
   1.111  
   1.112  	return dom;
   1.113  }
   1.114  
   1.115 -struct domain *lookup_domain(int domid)
   1.116 +static struct domain *lookup_domain(int domid)
   1.117  {
   1.118  	struct domain **pp;
   1.119  
   1.120 @@ -186,7 +186,7 @@ struct domain *lookup_domain(int domid)
   1.121  	return *pp;
   1.122  }
   1.123  
   1.124 -void remove_domain(struct domain *dom)
   1.125 +static void remove_domain(struct domain *dom)
   1.126  {
   1.127  	struct domain **pp;
   1.128  
   1.129 @@ -197,13 +197,16 @@ void remove_domain(struct domain *dom)
   1.130  
   1.131  		if (dom->domid == d->domid) {
   1.132  			*pp = d->next;
   1.133 +			if (d->buffer.data) {
   1.134 +				free(d->buffer.data);
   1.135 +			}
   1.136  			free(d);
   1.137  			break;
   1.138  		}
   1.139  	}
   1.140  }
   1.141  
   1.142 -void handle_tty_read(struct domain *dom)
   1.143 +static void handle_tty_read(struct domain *dom)
   1.144  {
   1.145  	ssize_t len;
   1.146  	xcs_msg_t msg;
   1.147 @@ -219,7 +222,7 @@ void handle_tty_read(struct domain *dom)
   1.148  		close(dom->tty_fd);
   1.149  
   1.150  		if (domain_is_valid(dom->domid)) {
   1.151 -			dom->tty_fd = domain_create_tty(dom->domid);
   1.152 +			dom->tty_fd = domain_create_tty(dom);
   1.153  		} else {
   1.154  			remove_domain(dom);
   1.155  		}
   1.156 @@ -235,7 +238,7 @@ void handle_tty_read(struct domain *dom)
   1.157  	}
   1.158  }
   1.159  
   1.160 -void handle_tty_write(struct domain *dom)
   1.161 +static void handle_tty_write(struct domain *dom)
   1.162  {
   1.163  	ssize_t len;
   1.164  
   1.165 @@ -244,7 +247,7 @@ void handle_tty_write(struct domain *dom
   1.166  		close(dom->tty_fd);
   1.167  
   1.168  		if (domain_is_valid(dom->domid)) {
   1.169 -			dom->tty_fd = domain_create_tty(dom->domid);
   1.170 +			dom->tty_fd = domain_create_tty(dom);
   1.171  		} else {
   1.172  			remove_domain(dom);
   1.173  		}
   1.174 @@ -253,7 +256,7 @@ void handle_tty_write(struct domain *dom
   1.175  	}
   1.176  }
   1.177  
   1.178 -void handle_xcs_msg(int fd)
   1.179 +static void handle_xcs_msg(int fd)
   1.180  {
   1.181  	xcs_msg_t msg;
   1.182  
     2.1 --- a/tools/consoled/xc_console.c	Wed Aug 03 09:06:10 2005 +0000
     2.2 +++ b/tools/consoled/xc_console.c	Wed Aug 03 09:32:39 2005 +0000
     2.3 @@ -126,7 +126,7 @@ static int console_loop(int xc_handle, d
     2.4  				return 0;
     2.5  			} 
     2.6  
     2.7 -			if (len == 0 && len == -1) {
     2.8 +			if (len == 0 || len == -1) {
     2.9  				if (len == -1 &&
    2.10  				    (errno == EINTR || errno == EAGAIN)) {
    2.11  					continue;