ia64/xen-unstable
changeset 6052:ec1878b6956e
Rename console binaries to xenconsole and xenconsoled.
Signed-off-by: Keir Fraser <keir@xensource.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author | kaf24@firebug.cl.cam.ac.uk |
---|---|
date | Sun Aug 07 09:12:55 2005 +0000 (2005-08-07) |
parents | 6721c8cd1a30 |
children | deff07c1b686 |
files | .hgignore tools/Makefile tools/misc/xend tools/python/xen/xm/create.py tools/python/xen/xm/main.py |
line diff
1.1 --- a/.hgignore Sun Aug 07 08:56:57 2005 +0000 1.2 +++ b/.hgignore Sun Aug 07 09:12:55 2005 +0000 1.3 @@ -86,8 +86,8 @@ 1.4 ^tools/check/\..*$ 1.5 ^tools/cmdline/.*$ 1.6 ^tools/cmdline/xen/.*$ 1.7 -^tools/consoled/consoled$ 1.8 -^tools/consoled/xc_console$ 1.9 +^tools/console/xenconsoled$ 1.10 +^tools/console/xenconsole$ 1.11 ^tools/debugger/pdb/pdb$ 1.12 ^tools/debugger/pdb/linux-[0-9.]*-module/.*\.ko$ 1.13 ^tools/debugger/pdb/linux-[0-9.]*-module/.*\.mod.c$
2.1 --- a/tools/Makefile Sun Aug 07 08:56:57 2005 +0000 2.2 +++ b/tools/Makefile Sun Aug 07 09:12:55 2005 +0000 2.3 @@ -13,7 +13,7 @@ SUBDIRS += xcutils 2.4 #SUBDIRS += pygrub 2.5 SUBDIRS += firmware 2.6 SUBDIRS += security 2.7 -SUBDIRS += consoled 2.8 +SUBDIRS += console 2.9 2.10 .PHONY: all install clean check check_clean ioemu eioemuinstall ioemuclean 2.11
3.1 --- a/tools/consoled/Makefile Sun Aug 07 08:56:57 2005 +0000 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,48 +0,0 @@ 3.4 -# Makefile for consoled 3.5 -# based on xcs Makefile 3.6 -# Anthony Liguori 2005 3.7 - 3.8 -XEN_ROOT=../.. 3.9 -include $(XEN_ROOT)/tools/Rules.mk 3.10 - 3.11 -CONSOLED_INSTALL_DIR = /usr/sbin 3.12 -XC_CONSOLE_INSTALL_DIR = /usr/libexec/xen 3.13 - 3.14 -INSTALL = install 3.15 -INSTALL_PROG = $(INSTALL) -m0755 3.16 -INSTALL_DIR = $(INSTALL) -d -m0755 3.17 - 3.18 -CC = gcc 3.19 -CFLAGS = -Wall -Werror -g3 3.20 - 3.21 -CFLAGS += -I $(XEN_XCS) 3.22 -CFLAGS += -I $(XEN_LIBXC) 3.23 -CFLAGS += -I $(XEN_XENSTORE) 3.24 - 3.25 -SRCS := 3.26 -SRCS += main.c utils.c io.c 3.27 - 3.28 -HDRS = $(wildcard *.h) 3.29 -OBJS = $(patsubst %.c,%.o,$(SRCS)) 3.30 -BIN = consoled xc_console 3.31 - 3.32 -all: $(BIN) 3.33 - 3.34 -clean: 3.35 - $(RM) *.a *.so *.o *.rpm $(BIN) 3.36 - 3.37 -consoled: $(OBJS) 3.38 - $(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -L$(XEN_XENSTORE) \ 3.39 - -lxc -lxenstore 3.40 - 3.41 -xc_console: xc_console.o 3.42 - $(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -L$(XEN_XENSTORE) \ 3.43 - -lxc -lxenstore 3.44 - 3.45 -$(OBJS): $(HDRS) 3.46 - 3.47 -install: $(BIN) 3.48 - $(INSTALL_DIR) -p $(DESTDIR)/$(CONSOLED_INSTALL_DIR) 3.49 - $(INSTALL_PROG) consoled $(DESTDIR)/$(CONSOLED_INSTALL_DIR) 3.50 - $(INSTALL_DIR) -p $(DESTDIR)/$(XC_CONSOLE_INSTALL_DIR) 3.51 - $(INSTALL_PROG) xc_console $(DESTDIR)/$(XC_CONSOLE_INSTALL_DIR)
4.1 --- a/tools/consoled/io.c Sun Aug 07 08:56:57 2005 +0000 4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 4.3 @@ -1,343 +0,0 @@ 4.4 -/*\ 4.5 - * Copyright (C) International Business Machines Corp., 2005 4.6 - * Author(s): Anthony Liguori <aliguori@us.ibm.com> 4.7 - * 4.8 - * Xen Console Daemon 4.9 - * 4.10 - * This program is free software; you can redistribute it and/or modify 4.11 - * it under the terms of the GNU General Public License as published by 4.12 - * the Free Software Foundation; under version 2 of the License. 4.13 - * 4.14 - * This program is distributed in the hope that it will be useful, 4.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 4.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4.17 - * GNU General Public License for more details. 4.18 - * 4.19 - * You should have received a copy of the GNU General Public License 4.20 - * along with this program; if not, write to the Free Software 4.21 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 4.22 -\*/ 4.23 - 4.24 -#define _GNU_SOURCE 4.25 - 4.26 -#include "utils.h" 4.27 -#include "io.h" 4.28 - 4.29 -#include "xc.h" 4.30 -#include "xs.h" 4.31 -#include "xen/io/domain_controller.h" 4.32 -#include "xcs_proto.h" 4.33 - 4.34 -#include <malloc.h> 4.35 -#include <stdlib.h> 4.36 -#include <errno.h> 4.37 -#include <string.h> 4.38 -#include <sys/select.h> 4.39 -#include <fcntl.h> 4.40 -#include <unistd.h> 4.41 -#include <termios.h> 4.42 - 4.43 -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) 4.44 -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) 4.45 - 4.46 -struct buffer 4.47 -{ 4.48 - char *data; 4.49 - size_t size; 4.50 - size_t capacity; 4.51 - size_t max_capacity; 4.52 -}; 4.53 - 4.54 -static void buffer_append(struct buffer *buffer, const void *data, size_t size) 4.55 -{ 4.56 - if ((buffer->capacity - buffer->size) < size) { 4.57 - buffer->capacity += (size + 1024); 4.58 - buffer->data = realloc(buffer->data, buffer->capacity); 4.59 - if (buffer->data == NULL) { 4.60 - dolog(LOG_ERR, "Memory allocation failed"); 4.61 - exit(ENOMEM); 4.62 - } 4.63 - } 4.64 - 4.65 - memcpy(buffer->data + buffer->size, data, size); 4.66 - buffer->size += size; 4.67 - 4.68 - if (buffer->max_capacity && 4.69 - buffer->size > buffer->max_capacity) { 4.70 - memmove(buffer->data + (buffer->size - buffer->max_capacity), 4.71 - buffer->data, buffer->max_capacity); 4.72 - buffer->data = realloc(buffer->data, buffer->max_capacity); 4.73 - buffer->capacity = buffer->max_capacity; 4.74 - } 4.75 -} 4.76 - 4.77 -static bool buffer_empty(struct buffer *buffer) 4.78 -{ 4.79 - return buffer->size == 0; 4.80 -} 4.81 - 4.82 -static void buffer_advance(struct buffer *buffer, size_t size) 4.83 -{ 4.84 - size = MIN(size, buffer->size); 4.85 - memmove(buffer->data, buffer + size, buffer->size - size); 4.86 - buffer->size -= size; 4.87 -} 4.88 - 4.89 -struct domain 4.90 -{ 4.91 - int domid; 4.92 - int tty_fd; 4.93 - struct buffer buffer; 4.94 - struct domain *next; 4.95 -}; 4.96 - 4.97 -static struct domain *dom_head; 4.98 - 4.99 -static bool domain_is_valid(int domid) 4.100 -{ 4.101 - bool ret; 4.102 - xc_dominfo_t info; 4.103 - 4.104 - ret = (xc_domain_getinfo(xc, domid, 1, &info) == 1 && 4.105 - info.domid == domid); 4.106 - 4.107 - return ret; 4.108 -} 4.109 - 4.110 -static int domain_create_tty(struct domain *dom) 4.111 -{ 4.112 - char path[1024]; 4.113 - int master; 4.114 - 4.115 - if ((master = getpt()) == -1 || 4.116 - grantpt(master) == -1 || unlockpt(master) == -1) { 4.117 - dolog(LOG_ERR, "Failed to create tty for domain-%d", 4.118 - dom->domid); 4.119 - master = -1; 4.120 - } else { 4.121 - const char *slave = ptsname(master); 4.122 - struct termios term; 4.123 - char *data; 4.124 - unsigned int len; 4.125 - 4.126 - if (tcgetattr(master, &term) != -1) { 4.127 - cfmakeraw(&term); 4.128 - tcsetattr(master, TCSAFLUSH, &term); 4.129 - } 4.130 - 4.131 - xs_mkdir(xs, "/console"); 4.132 - snprintf(path, sizeof(path), "/console/%d", dom->domid); 4.133 - xs_mkdir(xs, path); 4.134 - strcat(path, "/tty"); 4.135 - 4.136 - xs_write(xs, path, slave, strlen(slave), O_CREAT); 4.137 - 4.138 - snprintf(path, sizeof(path), "/console/%d/limit", dom->domid); 4.139 - data = xs_read(xs, path, &len); 4.140 - if (data) { 4.141 - dom->buffer.max_capacity = strtoul(data, 0, 0); 4.142 - free(data); 4.143 - } 4.144 - } 4.145 - 4.146 - return master; 4.147 -} 4.148 - 4.149 -static struct domain *create_domain(int domid) 4.150 -{ 4.151 - struct domain *dom; 4.152 - 4.153 - dom = (struct domain *)malloc(sizeof(struct domain)); 4.154 - if (dom == NULL) { 4.155 - dolog(LOG_ERR, "Out of memory %s:%s():L%d", 4.156 - __FILE__, __FUNCTION__, __LINE__); 4.157 - exit(ENOMEM); 4.158 - } 4.159 - 4.160 - dom->domid = domid; 4.161 - dom->tty_fd = domain_create_tty(dom); 4.162 - dom->buffer.data = 0; 4.163 - dom->buffer.size = 0; 4.164 - dom->buffer.capacity = 0; 4.165 - dom->buffer.max_capacity = 0; 4.166 - 4.167 - dolog(LOG_DEBUG, "New domain %d", domid); 4.168 - 4.169 - return dom; 4.170 -} 4.171 - 4.172 -static struct domain *lookup_domain(int domid) 4.173 -{ 4.174 - struct domain **pp; 4.175 - 4.176 - for (pp = &dom_head; *pp; pp = &(*pp)->next) { 4.177 - struct domain *dom = *pp; 4.178 - 4.179 - if (dom->domid == domid) { 4.180 - return dom; 4.181 - } else if (dom->domid > domid) { 4.182 - *pp = create_domain(domid); 4.183 - (*pp)->next = dom; 4.184 - return *pp; 4.185 - } 4.186 - } 4.187 - 4.188 - *pp = create_domain(domid); 4.189 - return *pp; 4.190 -} 4.191 - 4.192 -static void remove_domain(struct domain *dom) 4.193 -{ 4.194 - struct domain **pp; 4.195 - 4.196 - dolog(LOG_DEBUG, "Removing domain-%d", dom->domid); 4.197 - 4.198 - for (pp = &dom_head; *pp; pp = &(*pp)->next) { 4.199 - struct domain *d = *pp; 4.200 - 4.201 - if (dom->domid == d->domid) { 4.202 - *pp = d->next; 4.203 - if (d->buffer.data) { 4.204 - free(d->buffer.data); 4.205 - } 4.206 - free(d); 4.207 - break; 4.208 - } 4.209 - } 4.210 -} 4.211 - 4.212 -static void handle_tty_read(struct domain *dom) 4.213 -{ 4.214 - ssize_t len; 4.215 - xcs_msg_t msg; 4.216 - 4.217 - msg.type = XCS_REQUEST; 4.218 - msg.u.control.remote_dom = dom->domid; 4.219 - msg.u.control.msg.type = CMSG_CONSOLE; 4.220 - msg.u.control.msg.subtype = CMSG_CONSOLE_DATA; 4.221 - msg.u.control.msg.id = 1; 4.222 - 4.223 - len = read(dom->tty_fd, msg.u.control.msg.msg, 60); 4.224 - if (len < 1) { 4.225 - close(dom->tty_fd); 4.226 - 4.227 - if (domain_is_valid(dom->domid)) { 4.228 - dom->tty_fd = domain_create_tty(dom); 4.229 - } else { 4.230 - remove_domain(dom); 4.231 - } 4.232 - } else if (domain_is_valid(dom->domid)) { 4.233 - msg.u.control.msg.length = len; 4.234 - 4.235 - if (!write_sync(xcs_data_fd, &msg, sizeof(msg))) { 4.236 - dolog(LOG_ERR, "Write to xcs failed: %m"); 4.237 - } 4.238 - } else { 4.239 - close(dom->tty_fd); 4.240 - remove_domain(dom); 4.241 - } 4.242 -} 4.243 - 4.244 -static void handle_tty_write(struct domain *dom) 4.245 -{ 4.246 - ssize_t len; 4.247 - 4.248 - len = write(dom->tty_fd, dom->buffer.data, dom->buffer.size); 4.249 - if (len < 1) { 4.250 - close(dom->tty_fd); 4.251 - 4.252 - if (domain_is_valid(dom->domid)) { 4.253 - dom->tty_fd = domain_create_tty(dom); 4.254 - } else { 4.255 - remove_domain(dom); 4.256 - } 4.257 - } else { 4.258 - buffer_advance(&dom->buffer, len); 4.259 - } 4.260 -} 4.261 - 4.262 -static void handle_xcs_msg(int fd) 4.263 -{ 4.264 - xcs_msg_t msg; 4.265 - 4.266 - if (!read_sync(fd, &msg, sizeof(msg))) { 4.267 - dolog(LOG_ERR, "read from xcs failed! %m"); 4.268 - } else if (msg.type == XCS_REQUEST) { 4.269 - struct domain *dom; 4.270 - 4.271 - dom = lookup_domain(msg.u.control.remote_dom); 4.272 - buffer_append(&dom->buffer, 4.273 - msg.u.control.msg.msg, 4.274 - msg.u.control.msg.length); 4.275 - } 4.276 -} 4.277 - 4.278 -static void enum_domains(void) 4.279 -{ 4.280 - int domid = 0; 4.281 - xc_dominfo_t dominfo; 4.282 - 4.283 - while (xc_domain_getinfo(xc, domid, 1, &dominfo) == 1) { 4.284 - lookup_domain(dominfo.domid); 4.285 - domid = dominfo.domid + 1; 4.286 - } 4.287 -} 4.288 - 4.289 -void handle_io(void) 4.290 -{ 4.291 - fd_set readfds, writefds; 4.292 - int ret; 4.293 - int max_fd = -1; 4.294 - int num_of_writes = 0; 4.295 - 4.296 - do { 4.297 - struct domain *d; 4.298 - struct timeval tv = { 1, 0 }; 4.299 - 4.300 - FD_ZERO(&readfds); 4.301 - FD_ZERO(&writefds); 4.302 - 4.303 - FD_SET(xcs_data_fd, &readfds); 4.304 - max_fd = MAX(xcs_data_fd, max_fd); 4.305 - 4.306 - for (d = dom_head; d; d = d->next) { 4.307 - if (d->tty_fd != -1) { 4.308 - FD_SET(d->tty_fd, &readfds); 4.309 - } 4.310 - 4.311 - if (d->tty_fd != -1 && !buffer_empty(&d->buffer)) { 4.312 - FD_SET(d->tty_fd, &writefds); 4.313 - } 4.314 - 4.315 - max_fd = MAX(d->tty_fd, max_fd); 4.316 - } 4.317 - 4.318 - ret = select(max_fd + 1, &readfds, &writefds, 0, &tv); 4.319 - if (tv.tv_sec == 1 && (++num_of_writes % 100) == 0) { 4.320 - /* FIXME */ 4.321 - /* This is a nasty hack. xcs does not handle the 4.322 - control channels filling up well at all. We'll 4.323 - throttle ourselves here since we do proper 4.324 - queueing to give the domains a shot at pulling out 4.325 - the data. Fixing xcs is not worth it as it's 4.326 - going away */ 4.327 - tv.tv_usec = 1000; 4.328 - select(0, 0, 0, 0, &tv); 4.329 - } 4.330 - enum_domains(); 4.331 - 4.332 - if (FD_ISSET(xcs_data_fd, &readfds)) { 4.333 - handle_xcs_msg(xcs_data_fd); 4.334 - } 4.335 - 4.336 - for (d = dom_head; d; d = d->next) { 4.337 - if (FD_ISSET(d->tty_fd, &readfds)) { 4.338 - handle_tty_read(d); 4.339 - } 4.340 - 4.341 - if (FD_ISSET(d->tty_fd, &writefds)) { 4.342 - handle_tty_write(d); 4.343 - } 4.344 - } 4.345 - } while (ret > -1); 4.346 -}
5.1 --- a/tools/consoled/io.h Sun Aug 07 08:56:57 2005 +0000 5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 5.3 @@ -1,26 +0,0 @@ 5.4 -/*\ 5.5 - * Copyright (C) International Business Machines Corp., 2005 5.6 - * Author(s): Anthony Liguori <aliguori@us.ibm.com> 5.7 - * 5.8 - * Xen Console Daemon 5.9 - * 5.10 - * This program is free software; you can redistribute it and/or modify 5.11 - * it under the terms of the GNU General Public License as published by 5.12 - * the Free Software Foundation; under version 2 of the License. 5.13 - * 5.14 - * This program is distributed in the hope that it will be useful, 5.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 5.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5.17 - * GNU General Public License for more details. 5.18 - * 5.19 - * You should have received a copy of the GNU General Public License 5.20 - * along with this program; if not, write to the Free Software 5.21 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 5.22 -\*/ 5.23 - 5.24 -#ifndef CONSOLED_IO_H 5.25 -#define CONSOLED_IO_H 5.26 - 5.27 -void handle_io(void); 5.28 - 5.29 -#endif
6.1 --- a/tools/consoled/main.c Sun Aug 07 08:56:57 2005 +0000 6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 @@ -1,93 +0,0 @@ 6.4 -/*\ 6.5 - * Copyright (C) International Business Machines Corp., 2005 6.6 - * Author(s): Anthony Liguori <aliguori@us.ibm.com> 6.7 - * 6.8 - * Xen Console Daemon 6.9 - * 6.10 - * This program is free software; you can redistribute it and/or modify 6.11 - * it under the terms of the GNU General Public License as published by 6.12 - * the Free Software Foundation; under version 2 of the License. 6.13 - * 6.14 - * This program is distributed in the hope that it will be useful, 6.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 6.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6.17 - * GNU General Public License for more details. 6.18 - * 6.19 - * You should have received a copy of the GNU General Public License 6.20 - * along with this program; if not, write to the Free Software 6.21 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6.22 -\*/ 6.23 - 6.24 -#include <getopt.h> 6.25 -#include <stdlib.h> 6.26 -#include <stdio.h> 6.27 -#include <errno.h> 6.28 -#include <unistd.h> 6.29 -#include <sys/types.h> 6.30 - 6.31 -#include "xc.h" 6.32 -#include "xen/io/domain_controller.h" 6.33 -#include "xcs_proto.h" 6.34 - 6.35 -#include "utils.h" 6.36 -#include "io.h" 6.37 - 6.38 -int main(int argc, char **argv) 6.39 -{ 6.40 - const char *sopts = "hVvi"; 6.41 - struct option lopts[] = { 6.42 - { "help", 0, 0, 'h' }, 6.43 - { "version", 0, 0, 'V' }, 6.44 - { "verbose", 0, 0, 'v' }, 6.45 - { "interactive", 0, 0, 'i' }, 6.46 - { 0 }, 6.47 - }; 6.48 - bool is_interactive = false; 6.49 - int ch; 6.50 - int syslog_option = LOG_CONS; 6.51 - int syslog_mask = LOG_WARNING; 6.52 - int opt_ind = 0; 6.53 - 6.54 - while ((ch = getopt_long(argc, argv, sopts, lopts, &opt_ind)) != -1) { 6.55 - switch (ch) { 6.56 - case 'h': 6.57 - //usage(argv[0]); 6.58 - exit(0); 6.59 - case 'V': 6.60 - //version(argv[0]); 6.61 - exit(0); 6.62 - case 'v': 6.63 - syslog_option |= LOG_PERROR; 6.64 - syslog_mask = LOG_DEBUG; 6.65 - break; 6.66 - case 'i': 6.67 - is_interactive = true; 6.68 - break; 6.69 - case '?': 6.70 - fprintf(stderr, 6.71 - "Try `%s --help' for more information\n", 6.72 - argv[0]); 6.73 - exit(EINVAL); 6.74 - } 6.75 - } 6.76 - 6.77 - if (geteuid() != 0) { 6.78 - fprintf(stderr, "%s requires root to run.\n", argv[0]); 6.79 - exit(EPERM); 6.80 - } 6.81 - 6.82 - openlog("consoled", syslog_option, LOG_DAEMON); 6.83 - setlogmask(syslog_mask); 6.84 - 6.85 - if (!is_interactive) { 6.86 - daemonize("/var/run/consoled.pid"); 6.87 - } 6.88 - 6.89 - xen_setup(); 6.90 - 6.91 - handle_io(); 6.92 - 6.93 - closelog(); 6.94 - 6.95 - return 0; 6.96 -}
7.1 --- a/tools/consoled/testsuite/Makefile Sun Aug 07 08:56:57 2005 +0000 7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 7.3 @@ -1,11 +0,0 @@ 7.4 -CFLAGS=-g -Wall 7.5 -CC=gcc 7.6 -LDFLAGS=-static 7.7 - 7.8 -all: console-dom0 console-domU procpipe 7.9 - 7.10 -console-dom0: console-dom0.o 7.11 -console-domU: console-domU.o 7.12 -procpipe: procpipe.o 7.13 - 7.14 -clean:; $(RM) *.o console-domU console-dom0 procpipe
8.1 --- a/tools/consoled/testsuite/README Sun Aug 07 08:56:57 2005 +0000 8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 8.3 @@ -1,29 +0,0 @@ 8.4 -ABOUT 8.5 - 8.6 -This tool uses two programs, one that lives in dom0 and one that lives in domU 8.7 -to verify that no data is lost. dom0 and domU share a handshake with each 8.8 -other that they use to exchange a random seed. 8.9 - 8.10 -Both programs then generate a series of random numbers and then writes and 8.11 -reads the numbers via the console. Because each side starts with the same seed 8.12 -they know what data the other side is generating and therefore what should be 8.13 -expected. 8.14 - 8.15 -RUNNNING 8.16 - 8.17 -console-domU should be installed within the guest image. It must be launched 8.18 -from the client automatically. I use a custom initrd image and put it in the 8.19 -/linuxrc. 8.20 - 8.21 -console-dom0 and console-domU will communicate with each other and stress the 8.22 -console code. You can verify it at various levels by invoking it in different 8.23 -ways. procpipe is used to connect the two. I use the following command for 8.24 -testing: 8.25 - 8.26 -./procpipe ./console-dom0 'xm create -c /etc/xen/xmexample1' 8.27 - 8.28 -xmexample1 has no devices and no root set (this is what triggers /linuxrc). 8.29 - 8.30 -If it freezes, it probably means that console-domU is expecting more data from 8.31 -console-dom0 (which means that some data got dropped). I'd like to add 8.32 -timeouts in the future to handle this more gracefully.
9.1 --- a/tools/consoled/testsuite/console-dom0.c Sun Aug 07 08:56:57 2005 +0000 9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 9.3 @@ -1,117 +0,0 @@ 9.4 -/* Written by Anthony Liguori <aliguori@us.ibm.com> */ 9.5 - 9.6 -#include <stdio.h> 9.7 -#include <stdlib.h> 9.8 -#include <time.h> 9.9 -#include <string.h> 9.10 -#include <unistd.h> 9.11 -#include <termios.h> 9.12 - 9.13 -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) 9.14 - 9.15 -static void generate_random_buffer(char *buffer, size_t size) 9.16 -{ 9.17 - int i; 9.18 - 9.19 - for (i = 0; i < size; i++) { 9.20 - buffer[i] = random() & 0xFF; 9.21 - } 9.22 -} 9.23 - 9.24 -static void canonicalize(char *buffer) 9.25 -{ 9.26 - char *reader, *writer; 9.27 - 9.28 - reader = writer = buffer; 9.29 - 9.30 - while (*reader) { 9.31 - *writer = *reader; 9.32 - if (*reader != '\r') writer++; 9.33 - reader++; 9.34 - } 9.35 - *writer = *reader; 9.36 -} 9.37 - 9.38 -int main(int argc, char **argv) 9.39 -{ 9.40 - char buffer[4096]; 9.41 - char *line; 9.42 - unsigned int seed; 9.43 - size_t size; 9.44 - int runs; 9.45 - unsigned long long total_bytes = 0; 9.46 - struct termios term; 9.47 - 9.48 - tcgetattr(STDIN_FILENO, &term); 9.49 - cfmakeraw(&term); 9.50 - tcsetattr(STDIN_FILENO, TCSAFLUSH, &term); 9.51 - 9.52 - tcgetattr(STDOUT_FILENO, &term); 9.53 - cfmakeraw(&term); 9.54 - tcsetattr(STDOUT_FILENO, TCSAFLUSH, &term); 9.55 - 9.56 - while ((line = fgets(buffer, sizeof(buffer), stdin))) { 9.57 - canonicalize(line); 9.58 - 9.59 - if (strcmp(line, "!!!XEN Test Begin!!!\n") == 0) { 9.60 - break; 9.61 - } else { 9.62 - fprintf(stderr, "%s", line); 9.63 - } 9.64 - } 9.65 - 9.66 - if (line == NULL) { 9.67 - fprintf(stderr, "Client never sent start string.\n"); 9.68 - return 1; 9.69 - } 9.70 - 9.71 - seed = time(0); 9.72 - 9.73 - printf("%u\n", seed); fflush(stdout); 9.74 - 9.75 - fprintf(stderr, "Waiting for seed acknowledgement\n"); 9.76 - line = fgets(buffer, sizeof(buffer), stdin); 9.77 - if (line == NULL) { 9.78 - fprintf(stderr, "Client never acknowledge seed.\n"); 9.79 - return 1; 9.80 - } 9.81 - 9.82 - canonicalize(line); 9.83 - if (strcmp(line, "Seed Okay.\n") != 0) { 9.84 - fprintf(stderr, "Incorrect seed acknowledgement.\n"); 9.85 - fprintf(stderr, "[%s]", line); 9.86 - return 1; 9.87 - } else { 9.88 - fprintf(stderr, "Processed seed.\n"); 9.89 - } 9.90 - 9.91 - srandom(seed); 9.92 - 9.93 - for (runs = (random() % 100000) + 4096; runs > 0; runs--) { 9.94 - 9.95 - size = random() % 4096; 9.96 - 9.97 - fprintf(stderr, "Writing %d bytes.\n", size); 9.98 - 9.99 - generate_random_buffer(buffer, size); 9.100 - fwrite(buffer, size, 1, stdout); 9.101 - fflush(stdout); 9.102 - 9.103 - do { 9.104 - line = fgets(buffer, sizeof(buffer), stdin); 9.105 - if (line == NULL) { 9.106 - fprintf(stderr, "Premature EOF from client.\n"); 9.107 - return 1; 9.108 - } 9.109 - 9.110 - canonicalize(line); 9.111 - fprintf(stderr, "%s", line); 9.112 - } while (strcmp(line, "Okay.\n") != 0); 9.113 - 9.114 - total_bytes += size; 9.115 - } 9.116 - 9.117 - fprintf(stderr, "PASS: processed %llu byte(s).\n", total_bytes); 9.118 - 9.119 - return 0; 9.120 -}
10.1 --- a/tools/consoled/testsuite/console-domU.c Sun Aug 07 08:56:57 2005 +0000 10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 10.3 @@ -1,76 +0,0 @@ 10.4 -/* Written by Anthony Liguori <aliguori@us.ibm.com> */ 10.5 - 10.6 -#include <stdio.h> 10.7 -#include <stdlib.h> 10.8 -#include <time.h> 10.9 -#include <termios.h> 10.10 -#include <unistd.h> 10.11 - 10.12 -static void canonicalize(char *buffer) 10.13 -{ 10.14 - char *reader, *writer; 10.15 - 10.16 - reader = writer = buffer; 10.17 - 10.18 - while (*reader) { 10.19 - *writer = *reader; 10.20 - if (*reader != '\r') writer++; 10.21 - reader++; 10.22 - } 10.23 - *writer = *reader; 10.24 -} 10.25 - 10.26 -int main(int argc, char **argv) 10.27 -{ 10.28 - char buffer[4096]; 10.29 - char *line; 10.30 - unsigned int seed; 10.31 - size_t size; 10.32 - int i; 10.33 - int runs; 10.34 - struct termios term; 10.35 - 10.36 - tcgetattr(STDIN_FILENO, &term); 10.37 - cfmakeraw(&term); 10.38 - tcsetattr(STDIN_FILENO, TCSAFLUSH, &term); 10.39 - 10.40 - tcgetattr(STDOUT_FILENO, &term); 10.41 - cfmakeraw(&term); 10.42 - tcsetattr(STDOUT_FILENO, TCSAFLUSH, &term); 10.43 - 10.44 - printf("!!!XEN Test Begin!!!\n"); fflush(stdout); 10.45 - line = fgets(buffer, sizeof(buffer), stdin); 10.46 - if (line == NULL) { 10.47 - printf("Failure\n"); fflush(stdout); 10.48 - return 1; 10.49 - } 10.50 - 10.51 - canonicalize(line); 10.52 - seed = strtoul(line, 0, 0); 10.53 - 10.54 - printf("Seed Okay.\n"); fflush(stdout); 10.55 - 10.56 - srandom(seed); 10.57 - 10.58 - for (runs = (random() % 100000) + 4096; runs > 0; runs--) { 10.59 - size = random() % 4096; 10.60 - 10.61 - for (i = 0; i < size; i++) { 10.62 - int ch; 10.63 - int exp; 10.64 - 10.65 - ch = fgetc(stdin); 10.66 - exp = random() & 0xFF; 10.67 - if (ch != exp) { 10.68 - printf("Expected %d got %d\n", 10.69 - exp, ch); 10.70 - fflush(stdout); 10.71 - } 10.72 - printf("Got %d/%d good bytes\n", i, size); 10.73 - } 10.74 - 10.75 - printf("Okay.\n"); fflush(stdout); 10.76 - } 10.77 - 10.78 - return 0; 10.79 -}
11.1 --- a/tools/consoled/testsuite/procpipe.c Sun Aug 07 08:56:57 2005 +0000 11.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 11.3 @@ -1,133 +0,0 @@ 11.4 -/* Written by Anthony Liguori <aliguori@us.ibm.com> */ 11.5 - 11.6 -#include <stdio.h> 11.7 -#include <getopt.h> 11.8 -#include <errno.h> 11.9 -#include <stdlib.h> 11.10 -#include <err.h> 11.11 - 11.12 -#include <sys/types.h> 11.13 -#include <sys/wait.h> 11.14 -#include <unistd.h> 11.15 - 11.16 -#define PACKAGE_NAME "procpipe" 11.17 -#define PACKAGE_VERSION "0.0.1" 11.18 - 11.19 -#define GPL_SHORT \ 11.20 -"This is free software; see the source for copying conditions. There is NO\n"\ 11.21 -"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." 11.22 - 11.23 -#define PACKAGE_BUGS "aliguori@us.ibm.com" 11.24 -#define PACKAGE_AUTHOR "Anthony Liguori" 11.25 -#define PACKAGE_OWNER "IBM, Corp." 11.26 -#define PACKAGE_LICENSE GPL_SHORT 11.27 - 11.28 -static void usage(const char *name) 11.29 -{ 11.30 - printf("Usage: %s [OPTIONS]\n" 11.31 - "\n" 11.32 - " -h, --help display this help and exit\n" 11.33 - " -V, --version output version information and exit\n" 11.34 - "\n" 11.35 - "Report bugs to <%s>.\n" 11.36 - , name, PACKAGE_BUGS); 11.37 -} 11.38 - 11.39 -static void version(const char *name) 11.40 -{ 11.41 - printf("%s (%s) %s\n" 11.42 - "Written by %s.\n" 11.43 - "\n" 11.44 - "Copyright (C) 2005 %s.\n" 11.45 - "%s\n" 11.46 - , name, PACKAGE_NAME, PACKAGE_VERSION, 11.47 - PACKAGE_AUTHOR, PACKAGE_OWNER, PACKAGE_LICENSE); 11.48 -} 11.49 - 11.50 -static pid_t exec(int stdout, int stdin, const char *cmd) 11.51 -{ 11.52 - pid_t pid; 11.53 - 11.54 - pid = fork(); 11.55 - if (pid == 0) { 11.56 - close(STDOUT_FILENO); 11.57 - dup2(stdout, STDOUT_FILENO); 11.58 - close(STDIN_FILENO); 11.59 - dup2(stdin, STDIN_FILENO); 11.60 - 11.61 - execlp("/bin/sh", "sh", "-c", cmd, NULL); 11.62 - } 11.63 - 11.64 - return pid; 11.65 -} 11.66 - 11.67 -int main(int argc, char **argv) 11.68 -{ 11.69 - int ch, opt_ind = 0; 11.70 - const char *sopt = "hV"; 11.71 - struct option lopt[] = { 11.72 - { "help", 0, 0, 'h' }, 11.73 - { "version", 0, 0, 'V' }, 11.74 - { 0 } 11.75 - }; 11.76 - int host_stdout[2]; 11.77 - int host_stdin[2]; 11.78 - int res; 11.79 - pid_t pid1, pid2; 11.80 - int status; 11.81 - 11.82 - while ((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) { 11.83 - switch (ch) { 11.84 - case 'h': 11.85 - usage(argv[0]); 11.86 - exit(0); 11.87 - case 'V': 11.88 - version(argv[0]); 11.89 - exit(0); 11.90 - case '?': 11.91 - errx(EINVAL, "Try `%s --help' for more information.", 11.92 - argv[0]); 11.93 - } 11.94 - } 11.95 - 11.96 - if ((argc - optind) != 2) { 11.97 - errx(EINVAL, "Two commands are required.\n" 11.98 - "Try `%s --help' for more information.", argv[0]); 11.99 - } 11.100 - 11.101 - res = pipe(host_stdout); 11.102 - if (res == -1) { 11.103 - err(errno, "pipe() failed"); 11.104 - } 11.105 - 11.106 - res = pipe(host_stdin); 11.107 - if (res == -1) { 11.108 - err(errno, "pipe() failed"); 11.109 - } 11.110 - 11.111 - pid1 = exec(host_stdout[1], host_stdin[0], argv[optind]); 11.112 - if (pid1 == -1) { 11.113 - err(errno, "exec(%s)", argv[optind]); 11.114 - } 11.115 - 11.116 - pid2 = exec(host_stdin[1], host_stdout[0], argv[optind + 1]); 11.117 - if (pid2 == -1) { 11.118 - err(errno, "exec(%s)", argv[optind + 1]); 11.119 - } 11.120 - 11.121 - waitpid(pid1, &status, 0); 11.122 - if (WIFEXITED(status)) status = WEXITSTATUS(status); 11.123 - 11.124 - if (status != 0) { 11.125 - printf("Child exited with status %d\n", status); 11.126 - } 11.127 - 11.128 - waitpid(pid2, &status, 0); 11.129 - if (WIFEXITED(status)) status = WEXITSTATUS(status); 11.130 - 11.131 - if (status != 0) { 11.132 - printf("Child2 exited with status %d\n", status); 11.133 - } 11.134 - 11.135 - return 0; 11.136 -}
12.1 --- a/tools/consoled/utils.c Sun Aug 07 08:56:57 2005 +0000 12.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 12.3 @@ -1,251 +0,0 @@ 12.4 -/*\ 12.5 - * Copyright (C) International Business Machines Corp., 2005 12.6 - * Author(s): Anthony Liguori <aliguori@us.ibm.com> 12.7 - * 12.8 - * Xen Console Daemon 12.9 - * 12.10 - * This program is free software; you can redistribute it and/or modify 12.11 - * it under the terms of the GNU General Public License as published by 12.12 - * the Free Software Foundation; under version 2 of the License. 12.13 - * 12.14 - * This program is distributed in the hope that it will be useful, 12.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 12.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12.17 - * GNU General Public License for more details. 12.18 - * 12.19 - * You should have received a copy of the GNU General Public License 12.20 - * along with this program; if not, write to the Free Software 12.21 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 12.22 -\*/ 12.23 - 12.24 -#include <sys/types.h> 12.25 -#include <sys/stat.h> 12.26 -#include <sys/wait.h> 12.27 -#include <unistd.h> 12.28 -#include <stdlib.h> 12.29 -#include <fcntl.h> 12.30 -#include <err.h> 12.31 -#include <errno.h> 12.32 -#include <stdio.h> 12.33 -#include <getopt.h> 12.34 -#include <stdbool.h> 12.35 -#include <sys/socket.h> 12.36 -#include <sys/un.h> 12.37 -#include <string.h> 12.38 - 12.39 -#include "xc.h" 12.40 -#include "xen/io/domain_controller.h" 12.41 -#include "xcs_proto.h" 12.42 - 12.43 -#include "utils.h" 12.44 - 12.45 -struct xs_handle *xs; 12.46 -int xc; 12.47 - 12.48 -int xcs_ctrl_fd = -1; 12.49 -int xcs_data_fd = -1; 12.50 - 12.51 -bool _read_write_sync(int fd, void *data, size_t size, bool do_read) 12.52 -{ 12.53 - size_t offset = 0; 12.54 - ssize_t len; 12.55 - 12.56 - while (offset < size) { 12.57 - if (do_read) { 12.58 - len = read(fd, data + offset, size - offset); 12.59 - } else { 12.60 - len = write(fd, data + offset, size - offset); 12.61 - } 12.62 - 12.63 - if (len < 1) { 12.64 - if (len == -1 && (errno == EAGAIN || errno == EINTR)) { 12.65 - return false; 12.66 - } 12.67 - } else { 12.68 - offset += len; 12.69 - } 12.70 - } 12.71 - 12.72 - return true; 12.73 -} 12.74 - 12.75 -static int open_domain_socket(const char *path) 12.76 -{ 12.77 - struct sockaddr_un addr; 12.78 - int sock; 12.79 - size_t addr_len; 12.80 - 12.81 - if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) { 12.82 - goto out; 12.83 - } 12.84 - 12.85 - addr.sun_family = AF_UNIX; 12.86 - strcpy(addr.sun_path, path); 12.87 - addr_len = sizeof(addr.sun_family) + strlen(XCS_SUN_PATH) + 1; 12.88 - 12.89 - if (connect(sock, (struct sockaddr *)&addr, addr_len) == -1) { 12.90 - goto out_close_sock; 12.91 - } 12.92 - 12.93 - return sock; 12.94 - 12.95 - out_close_sock: 12.96 - close(sock); 12.97 - out: 12.98 - return -1; 12.99 -} 12.100 - 12.101 -static void child_exit(int sig) 12.102 -{ 12.103 - while (waitpid(-1, NULL, WNOHANG) > 0); 12.104 -} 12.105 - 12.106 -void daemonize(const char *pidfile) 12.107 -{ 12.108 - pid_t pid; 12.109 - int fd; 12.110 - int len; 12.111 - int i; 12.112 - char buf[100]; 12.113 - 12.114 - if (getppid() == 1) { 12.115 - return; 12.116 - } 12.117 - 12.118 - if ((pid = fork()) > 0) { 12.119 - exit(0); 12.120 - } else if (pid == -1) { 12.121 - err(errno, "fork() failed"); 12.122 - } 12.123 - 12.124 - setsid(); 12.125 - 12.126 - /* redirect fd 0,1,2 to /dev/null */ 12.127 - if ((fd = open("/dev/null",O_RDWR)) == -1) { 12.128 - exit(1); 12.129 - } 12.130 - 12.131 - for (i = 0; i <= 2; i++) { 12.132 - close(i); 12.133 - dup2(fd, i); 12.134 - } 12.135 - 12.136 - close(fd); 12.137 - 12.138 - umask(027); 12.139 - chdir("/"); 12.140 - 12.141 - fd = open(pidfile, O_RDWR | O_CREAT); 12.142 - if (fd == -1) { 12.143 - exit(1); 12.144 - } 12.145 - 12.146 - if (lockf(fd, F_TLOCK, 0) == -1) { 12.147 - exit(1); 12.148 - } 12.149 - 12.150 - len = sprintf(buf, "%d\n", getpid()); 12.151 - write(fd, buf, len); 12.152 - 12.153 - signal(SIGCHLD, child_exit); 12.154 - signal(SIGTSTP, SIG_IGN); 12.155 - signal(SIGTTOU, SIG_IGN); 12.156 - signal(SIGTTIN, SIG_IGN); 12.157 -} 12.158 - 12.159 -/* synchronized send/recv strictly for setting up xcs */ 12.160 -/* always use asychronize callbacks any other time */ 12.161 -static bool xcs_send_recv(int fd, xcs_msg_t *msg) 12.162 -{ 12.163 - bool ret = false; 12.164 - 12.165 - if (!write_sync(fd, msg, sizeof(*msg))) { 12.166 - dolog(LOG_ERR, "Write failed at %s:%s():L%d? Possible bug.", 12.167 - __FILE__, __FUNCTION__, __LINE__); 12.168 - goto out; 12.169 - } 12.170 - 12.171 - if (!read_sync(fd, msg, sizeof(*msg))) { 12.172 - dolog(LOG_ERR, "Read failed at %s:%s():L%d? Possible bug.", 12.173 - __FILE__, __FUNCTION__, __LINE__); 12.174 - goto out; 12.175 - } 12.176 - 12.177 - ret = true; 12.178 - 12.179 - out: 12.180 - return ret; 12.181 -} 12.182 - 12.183 -bool xen_setup(void) 12.184 -{ 12.185 - int sock; 12.186 - xcs_msg_t msg; 12.187 - 12.188 - xs = xs_daemon_open(); 12.189 - if (xs == NULL) { 12.190 - dolog(LOG_ERR, 12.191 - "Failed to contact xenstore (%m). Is it running?"); 12.192 - goto out; 12.193 - } 12.194 - 12.195 - xc = xc_interface_open(); 12.196 - if (xc == -1) { 12.197 - dolog(LOG_ERR, "Failed to contact hypervisor (%m)"); 12.198 - goto out; 12.199 - } 12.200 - 12.201 - sock = open_domain_socket(XCS_SUN_PATH); 12.202 - if (sock == -1) { 12.203 - dolog(LOG_ERR, "Failed to contact xcs (%m). Is it running?"); 12.204 - goto out_close_store; 12.205 - } 12.206 - 12.207 - xcs_ctrl_fd = sock; 12.208 - 12.209 - sock = open_domain_socket(XCS_SUN_PATH); 12.210 - if (sock == -1) { 12.211 - dolog(LOG_ERR, "Failed to contact xcs (%m). Is it running?"); 12.212 - goto out_close_ctrl; 12.213 - } 12.214 - 12.215 - xcs_data_fd = sock; 12.216 - 12.217 - memset(&msg, 0, sizeof(msg)); 12.218 - msg.type = XCS_CONNECT_CTRL; 12.219 - if (!xcs_send_recv(xcs_ctrl_fd, &msg) || msg.result != XCS_RSLT_OK) { 12.220 - dolog(LOG_ERR, "xcs control connect failed. Possible bug."); 12.221 - goto out_close_data; 12.222 - } 12.223 - 12.224 - msg.type = XCS_CONNECT_DATA; 12.225 - if (!xcs_send_recv(xcs_data_fd, &msg) || msg.result != XCS_RSLT_OK) { 12.226 - dolog(LOG_ERR, "xcs data connect failed. Possible bug."); 12.227 - goto out_close_data; 12.228 - } 12.229 - 12.230 - /* Since the vast majority of control messages are console messages 12.231 - it's just easier to ignore other messages that try to bind to 12.232 - a specific type. */ 12.233 - msg.type = XCS_MSG_BIND; 12.234 - msg.u.bind.port = PORT_WILDCARD; 12.235 - msg.u.bind.type = TYPE_WILDCARD; 12.236 - if (!xcs_send_recv(xcs_ctrl_fd, &msg) || msg.result != XCS_RSLT_OK) { 12.237 - dolog(LOG_ERR, "xcs vind failed. Possible bug."); 12.238 - goto out_close_data; 12.239 - } 12.240 - 12.241 - return true; 12.242 - 12.243 - out_close_data: 12.244 - close(xcs_ctrl_fd); 12.245 - xcs_data_fd = -1; 12.246 - out_close_ctrl: 12.247 - close(xcs_ctrl_fd); 12.248 - xcs_ctrl_fd = -1; 12.249 - out_close_store: 12.250 - xs_daemon_close(xs); 12.251 - out: 12.252 - return false; 12.253 -} 12.254 -
13.1 --- a/tools/consoled/utils.h Sun Aug 07 08:56:57 2005 +0000 13.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 13.3 @@ -1,47 +0,0 @@ 13.4 -/*\ 13.5 - * Copyright (C) International Business Machines Corp., 2005 13.6 - * Author(s): Anthony Liguori <aliguori@us.ibm.com> 13.7 - * 13.8 - * Xen Console Daemon 13.9 - * 13.10 - * This program is free software; you can redistribute it and/or modify 13.11 - * it under the terms of the GNU General Public License as published by 13.12 - * the Free Software Foundation; under version 2 of the License. 13.13 - * 13.14 - * This program is distributed in the hope that it will be useful, 13.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13.17 - * GNU General Public License for more details. 13.18 - * 13.19 - * You should have received a copy of the GNU General Public License 13.20 - * along with this program; if not, write to the Free Software 13.21 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 13.22 -\*/ 13.23 - 13.24 -#ifndef CONSOLED_UTILS_H 13.25 -#define CONSOLED_UTILS_H 13.26 - 13.27 -#include <stdbool.h> 13.28 -#include <syslog.h> 13.29 -#include <stdio.h> 13.30 - 13.31 -#include "xs.h" 13.32 - 13.33 -void daemonize(const char *pidfile); 13.34 -bool xen_setup(void); 13.35 -#define read_sync(fd, buffer, size) _read_write_sync(fd, buffer, size, true) 13.36 -#define write_sync(fd, buffer, size) _read_write_sync(fd, buffer, size, false) 13.37 -bool _read_write_sync(int fd, void *data, size_t size, bool do_read); 13.38 - 13.39 -extern int xcs_ctrl_fd; 13.40 -extern int xcs_data_fd; 13.41 -extern struct xs_handle *xs; 13.42 -extern int xc; 13.43 - 13.44 -#if 1 13.45 -#define dolog(val, fmt, ...) syslog(val, fmt, ## __VA_ARGS__) 13.46 -#else 13.47 -#define dolog(val, fmt, ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__) 13.48 -#endif 13.49 - 13.50 -#endif
14.1 --- a/tools/consoled/xc_console.c Sun Aug 07 08:56:57 2005 +0000 14.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 14.3 @@ -1,228 +0,0 @@ 14.4 -/*\ 14.5 - * Copyright (C) International Business Machines Corp., 2005 14.6 - * Author(s): Anthony Liguori <aliguori@us.ibm.com> 14.7 - * 14.8 - * Xen Console Daemon 14.9 - * 14.10 - * This program is free software; you can redistribute it and/or modify 14.11 - * it under the terms of the GNU General Public License as published by 14.12 - * the Free Software Foundation; under version 2 of the License. 14.13 - * 14.14 - * This program is distributed in the hope that it will be useful, 14.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 14.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14.17 - * GNU General Public License for more details. 14.18 - * 14.19 - * You should have received a copy of the GNU General Public License 14.20 - * along with this program; if not, write to the Free Software 14.21 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14.22 -\*/ 14.23 - 14.24 -#include <sys/types.h> 14.25 -#include <sys/socket.h> 14.26 -#include <sys/un.h> 14.27 -#include <stdio.h> 14.28 -#include <unistd.h> 14.29 -#include <errno.h> 14.30 -#include <stdlib.h> 14.31 -#include <time.h> 14.32 -#include <fcntl.h> 14.33 -#include <sys/wait.h> 14.34 -#include <termios.h> 14.35 -#include <signal.h> 14.36 -#include <getopt.h> 14.37 -#include <sys/select.h> 14.38 -#include <err.h> 14.39 -#include <errno.h> 14.40 -#include <pty.h> 14.41 - 14.42 -#include "xc.h" 14.43 -#include "xs.h" 14.44 - 14.45 -#define ESCAPE_CHARACTER 0x1d 14.46 - 14.47 -static volatile sig_atomic_t received_signal = 0; 14.48 - 14.49 -static void sighandler(int signum) 14.50 -{ 14.51 - received_signal = 1; 14.52 -} 14.53 - 14.54 -static bool write_sync(int fd, const void *data, size_t size) 14.55 -{ 14.56 - size_t offset = 0; 14.57 - ssize_t len; 14.58 - 14.59 - while (offset < size) { 14.60 - len = write(fd, data + offset, size - offset); 14.61 - if (len < 1) { 14.62 - return false; 14.63 - } 14.64 - offset += len; 14.65 - } 14.66 - 14.67 - return true; 14.68 -} 14.69 - 14.70 -static void usage(const char *program) { 14.71 - printf("Usage: %s [OPTION] DOMID\n" 14.72 - "Attaches to a virtual domain console\n" 14.73 - "\n" 14.74 - " -h, --help display this help and exit\n" 14.75 - , program); 14.76 -} 14.77 - 14.78 -/* don't worry too much if setting terminal attributes fail */ 14.79 -static void init_term(int fd, struct termios *old) 14.80 -{ 14.81 - struct termios new_term; 14.82 - 14.83 - if (tcgetattr(fd, old) == -1) { 14.84 - return; 14.85 - } 14.86 - 14.87 - new_term = *old; 14.88 - cfmakeraw(&new_term); 14.89 - 14.90 - tcsetattr(fd, TCSAFLUSH, &new_term); 14.91 -} 14.92 - 14.93 -static void restore_term(int fd, struct termios *old) 14.94 -{ 14.95 - tcsetattr(fd, TCSAFLUSH, old); 14.96 -} 14.97 - 14.98 -static int console_loop(int xc_handle, domid_t domid, int fd) 14.99 -{ 14.100 - int ret; 14.101 - 14.102 - do { 14.103 - fd_set fds; 14.104 - 14.105 - FD_ZERO(&fds); 14.106 - FD_SET(STDIN_FILENO, &fds); 14.107 - FD_SET(fd, &fds); 14.108 - 14.109 - ret = select(fd + 1, &fds, NULL, NULL, NULL); 14.110 - if (ret == -1) { 14.111 - if (errno == EINTR || errno == EAGAIN) { 14.112 - continue; 14.113 - } 14.114 - return -1; 14.115 - } 14.116 - 14.117 - if (FD_ISSET(STDIN_FILENO, &fds)) { 14.118 - ssize_t len; 14.119 - char msg[60]; 14.120 - 14.121 - len = read(STDIN_FILENO, msg, sizeof(msg)); 14.122 - if (len == 1 && msg[0] == ESCAPE_CHARACTER) { 14.123 - return 0; 14.124 - } 14.125 - 14.126 - if (len == 0 || len == -1) { 14.127 - if (len == -1 && 14.128 - (errno == EINTR || errno == EAGAIN)) { 14.129 - continue; 14.130 - } 14.131 - return -1; 14.132 - } 14.133 - 14.134 - if (!write_sync(fd, msg, len)) { 14.135 - perror("write() failed"); 14.136 - return -1; 14.137 - } 14.138 - } 14.139 - 14.140 - if (FD_ISSET(fd, &fds)) { 14.141 - ssize_t len; 14.142 - char msg[512]; 14.143 - 14.144 - len = read(fd, msg, sizeof(msg)); 14.145 - if (len == 0 || len == -1) { 14.146 - if (len == -1 && 14.147 - (errno == EINTR || errno == EAGAIN)) { 14.148 - continue; 14.149 - } 14.150 - return -1; 14.151 - } 14.152 - 14.153 - if (!write_sync(STDOUT_FILENO, msg, len)) { 14.154 - perror("write() failed"); 14.155 - return -1; 14.156 - } 14.157 - } 14.158 - } while (received_signal == 0); 14.159 - 14.160 - return 0; 14.161 -} 14.162 - 14.163 -int main(int argc, char **argv) 14.164 -{ 14.165 - struct termios attr; 14.166 - int domid; 14.167 - int xc_handle; 14.168 - char *sopt = "hf:pc"; 14.169 - int ch; 14.170 - int opt_ind=0; 14.171 - struct option lopt[] = { 14.172 - { "help", 0, 0, 'h' }, 14.173 - { "file", 1, 0, 'f' }, 14.174 - { "pty", 0, 0, 'p' }, 14.175 - { "ctty", 0, 0, 'c' }, 14.176 - { 0 }, 14.177 - 14.178 - }; 14.179 - char *str_pty; 14.180 - char path[1024]; 14.181 - int spty; 14.182 - unsigned int len = 0; 14.183 - struct xs_handle *xs; 14.184 - 14.185 - while((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) { 14.186 - switch(ch) { 14.187 - case 'h': 14.188 - usage(argv[0]); 14.189 - exit(0); 14.190 - break; 14.191 - } 14.192 - } 14.193 - 14.194 - if ((argc - optind) != 1) { 14.195 - fprintf(stderr, "Invalid number of arguments\n"); 14.196 - fprintf(stderr, "Try `%s --help' for more information.\n", 14.197 - argv[0]); 14.198 - exit(EINVAL); 14.199 - } 14.200 - 14.201 - domid = atoi(argv[optind]); 14.202 - 14.203 - xs = xs_daemon_open(); 14.204 - if (xs == NULL) { 14.205 - err(errno, "Could not contact XenStore"); 14.206 - } 14.207 - 14.208 - xc_handle = xc_interface_open(); 14.209 - if (xc_handle == -1) { 14.210 - err(errno, "xc_interface_open()"); 14.211 - } 14.212 - 14.213 - signal(SIGTERM, sighandler); 14.214 - 14.215 - snprintf(path, sizeof(path), "/console/%d/tty", domid); 14.216 - str_pty = xs_read(xs, path, &len); 14.217 - if (str_pty == NULL) { 14.218 - err(errno, "Could not read tty from store"); 14.219 - } 14.220 - spty = open(str_pty, O_RDWR | O_NOCTTY); 14.221 - if (spty == -1) { 14.222 - err(errno, "Could not open tty `%s'", str_pty); 14.223 - } 14.224 - free(str_pty); 14.225 - 14.226 - init_term(STDIN_FILENO, &attr); 14.227 - console_loop(xc_handle, domid, spty); 14.228 - restore_term(STDIN_FILENO, &attr); 14.229 - 14.230 - return 0; 14.231 - }
15.1 --- a/tools/misc/xend Sun Aug 07 08:56:57 2005 +0000 15.2 +++ b/tools/misc/xend Sun Aug 07 09:12:55 2005 +0000 15.3 @@ -121,7 +121,7 @@ def start_xenstored(): 15.4 15.5 def start_consoled(): 15.6 if os.fork() == 0: 15.7 - os.execvp('/usr/sbin/consoled', ['/usr/sbin/consoled']); 15.8 + os.execvp('/usr/sbin/xenconsoled', ['/usr/sbin/xenconsoled']); 15.9 15.10 def main(): 15.11 try:
16.1 --- a/tools/python/xen/xm/create.py Sun Aug 07 08:56:57 2005 +0000 16.2 +++ b/tools/python/xen/xm/create.py Sun Aug 07 09:12:55 2005 +0000 16.3 @@ -698,8 +698,8 @@ def main(argv): 16.4 16.5 dom = make_domain(opts, config) 16.6 if opts.vals.console_autoconnect: 16.7 - cmd = "/usr/libexec/xen/xc_console %d" % dom 16.8 - os.execvp('/usr/libexec/xen/xc_console', cmd.split()) 16.9 + cmd = "/usr/libexec/xen/xenconsole %d" % dom 16.10 + os.execvp('/usr/libexec/xen/xenconsole', cmd.split()) 16.11 16.12 if __name__ == '__main__': 16.13 main(sys.argv)
17.1 --- a/tools/python/xen/xm/main.py Sun Aug 07 08:56:57 2005 +0000 17.2 +++ b/tools/python/xen/xm/main.py Sun Aug 07 09:12:55 2005 +0000 17.3 @@ -709,8 +709,8 @@ class ProgConsole(Prog): 17.4 dom = args[1] 17.5 info = server.xend_domain(dom) 17.6 domid = int(sxp.child_value(info, 'id', '-1')) 17.7 - cmd = "/usr/libexec/xen/xc_console %d" % domid 17.8 - os.execvp('/usr/libexec/xen/xc_console', cmd.split()) 17.9 + cmd = "/usr/libexec/xen/xenconsole %d" % domid 17.10 + os.execvp('/usr/libexec/xen/xenconsole', cmd.split()) 17.11 17.12 xm.prog(ProgConsole) 17.13