diff options
-rw-r--r-- | tools/misc/xend | 8 | ||||
-rw-r--r-- | tools/python/xen/lowlevel/xu/xu.c | 36 | ||||
-rw-r--r-- | tools/xcs/xcs.c | 69 | ||||
-rw-r--r-- | tools/xcs/xcs_proto.h | 2 | ||||
-rw-r--r-- | tools/xcs/xcsdump.c | 26 |
5 files changed, 66 insertions, 75 deletions
diff --git a/tools/misc/xend b/tools/misc/xend index 5c9757ec23..fe30a13a45 100644 --- a/tools/misc/xend +++ b/tools/misc/xend @@ -24,7 +24,7 @@ import sys import socket import time -XCS_PORT = 1633 +XCS_PATH = "/var/xen/xcs_socket" XCS_EXEC = "/usr/sbin/xcs" XCS_LOGFILE = "/var/log/xcs.log" @@ -100,9 +100,9 @@ def xcs_running(): """ See if the control switch is running. """ ret = 1 - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) try: - s.connect( ("127.0.0.1", XCS_PORT) ) + s.connect( (XCS_PATH) ) except: ret = 0 s.close() @@ -118,7 +118,7 @@ def main(): if (not xcs_running()): if os.fork(): - time.sleep(1) # let xcs start + time.usleep(500) # let xcs start else: try: logfile = os.open(XCS_LOGFILE, diff --git a/tools/python/xen/lowlevel/xu/xu.c b/tools/python/xen/lowlevel/xu/xu.c index 12f27d63db..16768429b2 100644 --- a/tools/python/xen/lowlevel/xu/xu.c +++ b/tools/python/xen/lowlevel/xu/xu.c @@ -13,10 +13,10 @@ #include <sys/wait.h> #include <sys/stat.h> #include <sys/socket.h> +#include <sys/un.h> #include <sys/mman.h> #include <sys/poll.h> #include <sys/sysmacros.h> -#include <netinet/in.h> #include <fcntl.h> #include <unistd.h> #include <errno.h> @@ -87,36 +87,34 @@ static int xcs_ctrl_read(xcs_msg_t *msg); static int xcs_data_send(xcs_msg_t *msg); static int xcs_data_read(xcs_msg_t *msg); -static int xcs_connect(char *ip, short port) +static int xcs_connect(char *path) { - struct sockaddr_in addr; - int ret, flags; + struct sockaddr_un addr; + int ret, len, flags; xcs_msg_t msg; if (xcs_data_fd != -1) /* already connected */ return 0; - xcs_ctrl_fd = socket(AF_INET, SOCK_STREAM, 0); + xcs_ctrl_fd = socket(AF_UNIX, SOCK_STREAM, 0); if (xcs_ctrl_fd < 0) { printf("error creating xcs socket!\n"); goto fail; } - addr.sin_family = AF_INET; - addr.sin_port = htons(port); - addr.sin_addr.s_addr = inet_addr(ip); - memset(&(addr.sin_zero), '\0', 8); + addr.sun_family = AF_UNIX; + strcpy(addr.sun_path, path); + len = sizeof(addr.sun_family) + strlen(addr.sun_path) + 1; - ret = connect(xcs_ctrl_fd, (struct sockaddr *)&addr, - sizeof(struct sockaddr)); + ret = connect(xcs_ctrl_fd, (struct sockaddr *)&addr, len); if (ret < 0) { printf("error connecting to xcs(ctrl)! (%d)\n", errno); goto ctrl_fd_fail; } - //set_cloexec(xcs_ctrl_fd); + /*set_cloexec(xcs_ctrl_fd);*/ msg.type = XCS_CONNECT_CTRL; msg.u.connect.session_id = xcs_session_id; @@ -131,20 +129,18 @@ static int xcs_connect(char *ip, short port) xcs_session_id = msg.u.connect.session_id; /* now the data connection. */ - xcs_data_fd = socket(AF_INET, SOCK_STREAM, 0); + xcs_data_fd = socket(AF_UNIX, SOCK_STREAM, 0); if (xcs_data_fd < 0) { printf("error creating xcs data socket!\n"); goto ctrl_fd_fail; } - addr.sin_family = AF_INET; - addr.sin_port = htons(port); - addr.sin_addr.s_addr = inet_addr(ip); - memset(&(addr.sin_zero), '\0', 8); + addr.sun_family = AF_UNIX; + strcpy(addr.sun_path, path); + len = sizeof(addr.sun_family) + strlen(addr.sun_path) + 1; - ret = connect(xcs_data_fd, (struct sockaddr *)&addr, - sizeof(struct sockaddr)); + ret = connect(xcs_data_fd, (struct sockaddr *)&addr, len); if (ret < 0) { printf("error connecting to xcs(data)! (%d)\n", errno); @@ -447,7 +443,7 @@ static PyObject *xu_notifier_new(PyObject *self, PyObject *args) for (i = 0; i < XCS_RING_SIZE; i++) REQ_RING_ENT(i) = RSP_RING_ENT(i) = NULL; - (void)xcs_connect("127.0.0.1", XCS_TCP_PORT); + (void)xcs_connect(XCS_SUN_PATH); return (PyObject *)xun; diff --git a/tools/xcs/xcs.c b/tools/xcs/xcs.c index f0b1a96a88..f26e3c2f39 100644 --- a/tools/xcs/xcs.c +++ b/tools/xcs/xcs.c @@ -71,8 +71,7 @@ #include <string.h> #include <signal.h> #include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> +#include <sys/un.h> #include <errno.h> #include <malloc.h> #include <fcntl.h> @@ -89,27 +88,28 @@ static int dom_port_map_size = 0; static void map_dom_to_port(u32 dom, int port) { - if (dom >= dom_port_map_size) { - dom_port_map = (int *)realloc(dom_port_map, - (dom + 10) * sizeof(dom_port_map[0])); - - if (dom_port_map == NULL) { - perror("realloc(dom_port_map)"); - exit(1); - } - - for (; dom_port_map_size < dom + 10; dom_port_map_size++) { - dom_port_map[dom_port_map_size] = -1; - } - } + if (dom >= dom_port_map_size) { + dom_port_map = (int *)realloc(dom_port_map, + (dom + 256) * sizeof(dom_port_map[0])); + + if (dom_port_map == NULL) { + perror("realloc(dom_port_map)"); + exit(1); + } + + for (; dom_port_map_size < dom + 10; dom_port_map_size++) { + dom_port_map[dom_port_map_size] = -1; + } + } - dom_port_map[dom] = port; + dom_port_map[dom] = port; } -static int dom_to_port(u32 dom) { - if (dom >= dom_port_map_size) return -1; +static int dom_to_port(u32 dom) +{ + if (dom >= dom_port_map_size) return -1; - return dom_port_map[dom]; + return dom_port_map[dom]; } static void init_interfaces(void) @@ -218,37 +218,34 @@ void put_interface(control_channel_t *cc) /* ------[ Simple helpers ]------------------------------------------------*/ /* listen_socket() is straight from paul sheer's useful select_tut manpage. */ -static int listen_socket (int listen_port) +static int listen_socket (char *listen_path) { - struct sockaddr_in a; + struct sockaddr_un a; int s; int yes; - if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) + if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) { perror ("socket"); return -1; } yes = 1; - if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, - (char *) &yes, sizeof (yes)) < 0) - { - perror ("setsockopt"); - close (s); - return -1; - } memset (&a, 0, sizeof (a)); - a.sin_port = htons (listen_port); - a.sin_family = AF_INET; + a.sun_family = AF_UNIX; + strcpy(a.sun_path, listen_path); + + /* remove an old socket if it exists. */ + unlink(listen_path); + if (bind(s, (struct sockaddr *) &a, sizeof (a)) < 0) { perror ("bind"); close (s); return -1; } - printf ("accepting connections on port %d\n", (int) listen_port); + printf ("accepting connections on path %s\n", listen_path); listen (s, 10); return s; } @@ -626,13 +623,13 @@ void gc_ufd_list( unbound_fd_t **ufd ) } } -int main (int argc, char*argv[]) +int main (int argc, char *argv[]) { int listen_fd, evtchn_fd; unbound_fd_t *unbound_fd_list = NULL, **ufd; struct timeval timeout = { XCS_GC_INTERVAL, 0 }; connection_t **con; - + /* Initialize xc and event connections. */ if (ctrl_chan_init() != 0) { @@ -650,7 +647,7 @@ int main (int argc, char*argv[]) init_interfaces(); init_bindings(); - listen_fd = listen_socket(XCS_TCP_PORT); + listen_fd = listen_socket(XCS_SUN_PATH); /* detach from our controlling tty so that a shell does hang waiting for stopped jobs. */ @@ -742,7 +739,7 @@ int main (int argc, char*argv[]) /* CASE 2: New connection on the listen port. */ if ( FD_ISSET ( listen_fd, &rd )) { - struct sockaddr_in remote_addr; + struct sockaddr_un remote_addr; int size; memset (&remote_addr, 0, sizeof (remote_addr)); size = sizeof remote_addr; diff --git a/tools/xcs/xcs_proto.h b/tools/xcs/xcs_proto.h index ea227c2ff7..10ac7dafed 100644 --- a/tools/xcs/xcs_proto.h +++ b/tools/xcs/xcs_proto.h @@ -9,7 +9,7 @@ #ifndef __XCS_PROTO_H__ #define __XCS_PROTO_H__ -#define XCS_TCP_PORT 1633 +#define XCS_SUN_PATH "/var/xen/xcs_socket" /* xcs message types: */ #define XCS_CONNECT_CTRL 0 /* This is a control connection. */ diff --git a/tools/xcs/xcsdump.c b/tools/xcs/xcsdump.c index dcfd2c9119..35ddcd4e3f 100644 --- a/tools/xcs/xcsdump.c +++ b/tools/xcs/xcsdump.c @@ -11,8 +11,7 @@ #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> +#include <sys/un.h> #include <ctype.h> #include <xc.h> #include <xen/xen.h> @@ -23,24 +22,23 @@ static int xcs_ctrl_fd = -1; /* connection to the xcs server. */ static int xcs_data_fd = -1; /* connection to the xcs server. */ -int tcp_connect(char *ip, short port) +int sock_connect(char *path) { - struct sockaddr_in addr; - int ret, fd; + struct sockaddr_un addr; + int ret, len, fd; - fd = socket(AF_INET, SOCK_STREAM, 0); + fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) { printf("error creating xcs socket!\n"); return -1; } - addr.sin_family = AF_INET; - addr.sin_port = htons(port); - addr.sin_addr.s_addr = inet_addr(ip); - memset(&(addr.sin_zero), '\0', 8); + addr.sun_family = AF_UNIX; + strcpy(addr.sun_path, path); + len = sizeof(addr.sun_family) + strlen(addr.sun_path) + 1; - ret = connect(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr)); + ret = connect(fd, (struct sockaddr *)&addr, len); if (ret < 0) { printf("error connecting to xcs!\n"); @@ -50,7 +48,7 @@ int tcp_connect(char *ip, short port) return fd; } -void tcp_disconnect(int *fd) +void sock_disconnect(int *fd) { close(*fd); *fd = -1; @@ -91,7 +89,7 @@ int main(int argc, char* argv[]) if ((strlen(argv[1]) >=2) && (strncmp(argv[1], "-v", 2) == 0)) verbose = 1; - ret = tcp_connect("127.0.0.1", XCS_TCP_PORT); + ret = sock_connect(XCS_SUN_PATH); if (ret < 0) { printf("connect failed!\n"); @@ -109,7 +107,7 @@ int main(int argc, char* argv[]) exit(-1); } - ret = tcp_connect("127.0.0.1", XCS_TCP_PORT); + ret = sock_connect(XCS_SUN_PATH); if (ret < 0) { printf("connect failed!\n"); |