2006-06-29 02:19:13 +08:00
|
|
|
/*
|
|
|
|
* proxy_svr.c: root suid proxy server for Xen access to APIs with no
|
|
|
|
* side effects from unauthenticated clients.
|
|
|
|
*
|
2009-01-28 22:08:33 +08:00
|
|
|
* Copyright (C) 2006, 2007, 2008, 2009 Red Hat, Inc.
|
2006-06-29 02:19:13 +08:00
|
|
|
*
|
|
|
|
* See COPYING.LIB for the License of this software
|
|
|
|
*
|
|
|
|
* Daniel Veillard <veillard@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2008-01-30 02:15:54 +08:00
|
|
|
#include <config.h>
|
2008-07-07 18:00:30 +08:00
|
|
|
#include <stdio.h>
|
2007-12-07 18:08:06 +08:00
|
|
|
|
2007-12-07 22:45:39 +08:00
|
|
|
#ifdef WITH_XEN
|
|
|
|
|
2006-06-29 02:19:13 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/poll.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
2007-03-02 00:01:39 +08:00
|
|
|
#include <locale.h>
|
2007-12-07 22:45:39 +08:00
|
|
|
|
2006-06-29 02:19:13 +08:00
|
|
|
#include "internal.h"
|
2008-11-05 07:22:06 +08:00
|
|
|
#include "datatypes.h"
|
2006-06-30 06:12:47 +08:00
|
|
|
#include "proxy_internal.h"
|
Move safewrite and saferead to a separate file.
We currently use safewrite from inside libvirt and don't want to publish
any such function name. However, we do want to use it in applications
like virsh, libvirtd and libvirt_proxy that link with libvirt. To that
end, this change moves that function definition (along with the nearly
identical saferead) into a new file, util-lib.c. To avoid maintaining
separate copies of even such small functions, we simply include that new
file from util.c. Then, the separate applications that need to use
safewrite simply compile and link with util-lib.c.
Of course, this does mean that each of those applications will
containing two copies of these functions. However, the functions
are so small that it's not worth worrying about that.
* src/util.c (saferead, safewrite): Move function definitions to
util-lib.c and include that .c file.
* src/util-lib.c (saferead, safewrite): New file. Functions from src/util.c
with slight change (s/int r =/ssize_t r =/) to reflect read/write return type.
* src/util-lib.h: Declare the two moved functions.
* src/util.h: Remove declarations. Include src/util-lib.h.
* proxy/Makefile.am (libvirt_proxy_SOURCES): Add src/util-lib.c.
* qemud/Makefile.am (libvirtd_SOURCES): Likewise.
* src/Makefile.am (virsh_SOURCES): Add util-lib.c. Remove some SP-before-TAB.
2008-02-22 23:53:13 +08:00
|
|
|
#include "util.h"
|
2006-06-29 02:19:13 +08:00
|
|
|
#include "xen_internal.h"
|
2006-06-29 22:44:37 +08:00
|
|
|
#include "xend_internal.h"
|
2006-08-09 23:21:16 +08:00
|
|
|
#include "xs_internal.h"
|
2007-04-04 22:19:49 +08:00
|
|
|
#include "xen_unified.h"
|
2006-06-29 02:19:13 +08:00
|
|
|
|
|
|
|
static int fdServer = -1;
|
|
|
|
static int debug = 0;
|
2006-06-29 22:44:37 +08:00
|
|
|
static int persist = 0;
|
2006-06-29 02:19:13 +08:00
|
|
|
static int done = 0;
|
|
|
|
|
|
|
|
#define MAX_CLIENT 64
|
|
|
|
|
|
|
|
static int nbClients = 0; /* client 0 is the unix listen socket */
|
|
|
|
static struct pollfd pollInfos[MAX_CLIENT + 1];
|
|
|
|
|
|
|
|
static virConnect conninfos;
|
|
|
|
static virConnectPtr conn = &conninfos;
|
|
|
|
|
2006-06-29 22:44:37 +08:00
|
|
|
static unsigned long xenVersion = 0;
|
|
|
|
|
2006-06-29 02:19:13 +08:00
|
|
|
/************************************************************************
|
|
|
|
* *
|
|
|
|
* Interfaces with the Xen hypervisor *
|
|
|
|
* *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* proxyInitXen:
|
|
|
|
*
|
|
|
|
* Initialize the communication layer with Xen
|
|
|
|
*
|
|
|
|
* Returns 0 or -1 in case of error
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
proxyInitXen(void) {
|
|
|
|
int ret;
|
2006-06-29 22:44:37 +08:00
|
|
|
unsigned long xenVersion2;
|
2007-04-04 22:19:49 +08:00
|
|
|
xenUnifiedPrivatePtr priv;
|
|
|
|
|
|
|
|
/* Allocate per-connection private data. */
|
|
|
|
priv = malloc (sizeof *priv);
|
|
|
|
if (!priv) {
|
|
|
|
fprintf(stderr, "Failed to allocate private data\n");
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
conn->privateData = priv;
|
|
|
|
|
|
|
|
priv->handle = -1;
|
|
|
|
priv->xendConfigVersion = -1;
|
|
|
|
priv->xshandle = NULL;
|
|
|
|
priv->proxy = -1;
|
2006-06-29 02:19:13 +08:00
|
|
|
|
2008-11-17 19:44:51 +08:00
|
|
|
ret = xenHypervisorOpen(conn, NULL, 0);
|
2006-06-29 02:19:13 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
fprintf(stderr, "Failed to open Xen hypervisor\n");
|
|
|
|
return(-1);
|
2006-06-29 22:44:37 +08:00
|
|
|
} else {
|
|
|
|
ret = xenHypervisorGetVersion(conn, &xenVersion);
|
2008-04-11 00:54:54 +08:00
|
|
|
if (ret != 0) {
|
|
|
|
fprintf(stderr, "Failed to get Xen hypervisor version\n");
|
|
|
|
return(-1);
|
|
|
|
}
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
ret = xenDaemonOpen_unix(conn, "/var/lib/xend/xend-socket");
|
|
|
|
if (ret < 0) {
|
|
|
|
fprintf(stderr, "Failed to connect to Xen daemon\n");
|
|
|
|
return(-1);
|
|
|
|
}
|
2008-11-17 19:44:51 +08:00
|
|
|
ret = xenStoreOpen(conn, NULL, VIR_CONNECT_RO);
|
2006-08-09 23:21:16 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
fprintf(stderr, "Failed to open XenStore connection");
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-06-29 22:44:37 +08:00
|
|
|
ret = xenDaemonGetVersion(conn, &xenVersion2);
|
|
|
|
if (ret != 0) {
|
2008-04-11 00:54:54 +08:00
|
|
|
fprintf(stderr, "Failed to get Xen daemon version\n");
|
|
|
|
return(-1);
|
2006-06-29 22:44:37 +08:00
|
|
|
}
|
|
|
|
if (debug)
|
|
|
|
fprintf(stderr, "Connected to hypervisor %lu and daemon %lu\n",
|
2008-04-11 00:54:54 +08:00
|
|
|
xenVersion, xenVersion2);
|
2006-06-29 22:44:37 +08:00
|
|
|
if (xenVersion2 > xenVersion)
|
|
|
|
xenVersion = xenVersion2;
|
2006-06-29 02:19:13 +08:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* *
|
|
|
|
* Processing of the unix socket to listen for clients *
|
|
|
|
* *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* proxyCloseUnixSocket:
|
|
|
|
*
|
|
|
|
* close the unix socket
|
|
|
|
*
|
|
|
|
* Returns 0 or -1 in case of error
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
proxyCloseUnixSocket(void) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (fdServer < 0)
|
|
|
|
return(0);
|
2008-02-06 03:27:37 +08:00
|
|
|
|
2006-06-29 02:19:13 +08:00
|
|
|
ret = close(fdServer);
|
|
|
|
if (debug > 0)
|
|
|
|
fprintf(stderr, "closing unix socket %d: %d\n", fdServer, ret);
|
|
|
|
fdServer = -1;
|
|
|
|
pollInfos[0].fd = -1;
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* proxyListenUnixSocket:
|
2008-04-24 17:17:29 +08:00
|
|
|
* @path: the filename for the socket
|
2006-06-29 02:19:13 +08:00
|
|
|
*
|
|
|
|
* create a new abstract socket based on that path and listen on it
|
|
|
|
*
|
|
|
|
* Returns the associated file descriptor or -1 in case of failure
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
proxyListenUnixSocket(const char *path) {
|
|
|
|
int fd;
|
|
|
|
struct sockaddr_un addr;
|
|
|
|
|
|
|
|
if (fdServer >= 0)
|
|
|
|
return(fdServer);
|
|
|
|
|
|
|
|
fd = socket(PF_UNIX, SOCK_STREAM, 0);
|
|
|
|
if (fd < 0) {
|
|
|
|
fprintf(stderr, "Failed to create unix socket");
|
2008-04-11 00:54:54 +08:00
|
|
|
return(-1);
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-02-06 03:27:37 +08:00
|
|
|
* Abstract socket do not hit the filesystem, way more secure and
|
2008-04-04 15:58:29 +08:00
|
|
|
* guaranteed to be atomic
|
2006-06-29 02:19:13 +08:00
|
|
|
*/
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
addr.sun_family = AF_UNIX;
|
|
|
|
addr.sun_path[0] = '\0';
|
|
|
|
strncpy(&addr.sun_path[1], path, (sizeof(addr) - 4) - 2);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* now bind the socket to that address and listen on it
|
|
|
|
*/
|
|
|
|
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
|
|
|
fprintf(stderr, "Failed to bind to socket %s\n", path);
|
2008-04-11 00:54:54 +08:00
|
|
|
close(fd);
|
|
|
|
return (-1);
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
if (listen(fd, 30 /* backlog */ ) < 0) {
|
|
|
|
fprintf(stderr, "Failed to listen to socket %s\n", path);
|
2008-04-11 00:54:54 +08:00
|
|
|
close(fd);
|
|
|
|
return (-1);
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (debug > 0)
|
|
|
|
fprintf(stderr, "opened and bound unix socket %d\n", fd);
|
|
|
|
|
|
|
|
fdServer = fd;
|
|
|
|
pollInfos[0].fd = fd;
|
|
|
|
pollInfos[0].events = POLLIN | POLLERR | POLLHUP | POLLNVAL;
|
|
|
|
return (fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* proxyAcceptClientSocket:
|
|
|
|
*
|
|
|
|
* Process a request to the unix socket
|
|
|
|
*
|
|
|
|
* Returns the filedescriptor of the new client or -1 in case of error
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
proxyAcceptClientSocket(void) {
|
|
|
|
int client;
|
|
|
|
socklen_t client_addrlen;
|
|
|
|
struct sockaddr client_addr;
|
|
|
|
|
|
|
|
retry:
|
|
|
|
client_addrlen = sizeof(client_addr);
|
|
|
|
client = accept(pollInfos[0].fd, &client_addr, &client_addrlen);
|
|
|
|
if (client < 0) {
|
|
|
|
if (errno == EINTR) {
|
2008-04-11 00:54:54 +08:00
|
|
|
if (debug > 0)
|
|
|
|
fprintf(stderr, "accept connection on socket %d interrupted\n",
|
|
|
|
pollInfos[0].fd);
|
|
|
|
goto retry;
|
|
|
|
}
|
2006-06-29 02:19:13 +08:00
|
|
|
fprintf(stderr, "Failed to accept incoming connection on socket %d\n",
|
2008-04-11 00:54:54 +08:00
|
|
|
pollInfos[0].fd);
|
|
|
|
done = 1;
|
|
|
|
return(-1);
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nbClients >= MAX_CLIENT) {
|
|
|
|
fprintf(stderr, "Too many client registered\n");
|
2008-04-11 00:54:54 +08:00
|
|
|
close(client);
|
|
|
|
return(-1);
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
nbClients++;
|
|
|
|
pollInfos[nbClients].fd = client;
|
|
|
|
pollInfos[nbClients].events = POLLIN | POLLERR | POLLHUP | POLLNVAL;
|
|
|
|
if (debug > 0)
|
2008-04-11 00:54:54 +08:00
|
|
|
fprintf(stderr, "accept connection on socket %d for client %d\n",
|
|
|
|
client, nbClients);
|
2006-06-29 02:19:13 +08:00
|
|
|
return(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* *
|
|
|
|
* Processing of client sockets *
|
|
|
|
* *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* proxyCloseClientSocket:
|
|
|
|
* @nr: client number
|
|
|
|
*
|
|
|
|
* Close the socket from that client, and recompact the pollInfo array
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of error
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
proxyCloseClientSocket(int nr) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = close(pollInfos[nr].fd);
|
|
|
|
if (ret != 0)
|
2008-04-11 00:54:54 +08:00
|
|
|
fprintf(stderr, "Failed to close socket %d from client %d\n",
|
|
|
|
pollInfos[nr].fd, nr);
|
2006-06-29 02:19:13 +08:00
|
|
|
else if (debug > 0)
|
2008-04-11 00:54:54 +08:00
|
|
|
fprintf(stderr, "Closed socket %d from client %d\n",
|
|
|
|
pollInfos[nr].fd, nr);
|
2006-06-29 02:19:13 +08:00
|
|
|
if (nr < nbClients) {
|
|
|
|
memmove(&pollInfos[nr], &pollInfos[nr + 1],
|
2008-04-11 00:54:54 +08:00
|
|
|
(nbClients - nr) * sizeof(pollInfos[0]));
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
nbClients--;
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* proxyCloseClientSockets:
|
|
|
|
*
|
|
|
|
* Close all the sockets from the clients
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
proxyCloseClientSockets(void) {
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
for (i = 1;i <= nbClients;i++) {
|
|
|
|
ret = close(pollInfos[i].fd);
|
2008-04-11 00:54:54 +08:00
|
|
|
if (ret != 0)
|
|
|
|
fprintf(stderr, "Failed to close socket %d from client %d\n",
|
|
|
|
pollInfos[i].fd, i);
|
|
|
|
else if (debug > 0)
|
|
|
|
fprintf(stderr, "Closed socket %d from client %d\n",
|
|
|
|
pollInfos[i].fd, i);
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
nbClients = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* proxyWriteClientSocket:
|
|
|
|
* @nr: the client number
|
|
|
|
* @req: pointer to the packet
|
|
|
|
*
|
|
|
|
* Send back a packet to the client. If it seems write would be blocking
|
|
|
|
* then try to disconnect from it.
|
|
|
|
*
|
|
|
|
* Return 0 in case of success and -1 in case of error.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
proxyWriteClientSocket(int nr, virProxyPacketPtr req) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if ((nr <= 0) || (nr > nbClients) || (req == NULL) ||
|
2006-06-30 06:12:47 +08:00
|
|
|
(req->len < sizeof(virProxyPacket)) ||
|
2008-04-11 00:54:54 +08:00
|
|
|
(req->len > sizeof(virProxyFullPacket)) ||
|
|
|
|
(pollInfos[nr].fd < 0)) {
|
|
|
|
fprintf(stderr, "write to client %d in error", nr);
|
|
|
|
proxyCloseClientSocket(nr);
|
|
|
|
return(-1);
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
|
Move safewrite and saferead to a separate file.
We currently use safewrite from inside libvirt and don't want to publish
any such function name. However, we do want to use it in applications
like virsh, libvirtd and libvirt_proxy that link with libvirt. To that
end, this change moves that function definition (along with the nearly
identical saferead) into a new file, util-lib.c. To avoid maintaining
separate copies of even such small functions, we simply include that new
file from util.c. Then, the separate applications that need to use
safewrite simply compile and link with util-lib.c.
Of course, this does mean that each of those applications will
containing two copies of these functions. However, the functions
are so small that it's not worth worrying about that.
* src/util.c (saferead, safewrite): Move function definitions to
util-lib.c and include that .c file.
* src/util-lib.c (saferead, safewrite): New file. Functions from src/util.c
with slight change (s/int r =/ssize_t r =/) to reflect read/write return type.
* src/util-lib.h: Declare the two moved functions.
* src/util.h: Remove declarations. Include src/util-lib.h.
* proxy/Makefile.am (libvirt_proxy_SOURCES): Add src/util-lib.c.
* qemud/Makefile.am (libvirtd_SOURCES): Likewise.
* src/Makefile.am (virsh_SOURCES): Add util-lib.c. Remove some SP-before-TAB.
2008-02-22 23:53:13 +08:00
|
|
|
ret = safewrite(pollInfos[nr].fd, (char *) req, req->len);
|
2006-06-29 02:19:13 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
fprintf(stderr, "write %d bytes to socket %d from client %d failed\n",
|
2008-04-11 00:54:54 +08:00
|
|
|
req->len, pollInfos[nr].fd, nr);
|
Move safewrite and saferead to a separate file.
We currently use safewrite from inside libvirt and don't want to publish
any such function name. However, we do want to use it in applications
like virsh, libvirtd and libvirt_proxy that link with libvirt. To that
end, this change moves that function definition (along with the nearly
identical saferead) into a new file, util-lib.c. To avoid maintaining
separate copies of even such small functions, we simply include that new
file from util.c. Then, the separate applications that need to use
safewrite simply compile and link with util-lib.c.
Of course, this does mean that each of those applications will
containing two copies of these functions. However, the functions
are so small that it's not worth worrying about that.
* src/util.c (saferead, safewrite): Move function definitions to
util-lib.c and include that .c file.
* src/util-lib.c (saferead, safewrite): New file. Functions from src/util.c
with slight change (s/int r =/ssize_t r =/) to reflect read/write return type.
* src/util-lib.h: Declare the two moved functions.
* src/util.h: Remove declarations. Include src/util-lib.h.
* proxy/Makefile.am (libvirt_proxy_SOURCES): Add src/util-lib.c.
* qemud/Makefile.am (libvirtd_SOURCES): Likewise.
* src/Makefile.am (virsh_SOURCES): Add util-lib.c. Remove some SP-before-TAB.
2008-02-22 23:53:13 +08:00
|
|
|
proxyCloseClientSocket(nr);
|
|
|
|
return(-1);
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
if (ret == 0) {
|
2008-04-11 00:54:54 +08:00
|
|
|
if (debug)
|
|
|
|
fprintf(stderr, "end of stream from client %d on socket %d\n",
|
|
|
|
nr, pollInfos[nr].fd);
|
|
|
|
proxyCloseClientSocket(nr);
|
|
|
|
return(-1);
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret != req->len) {
|
|
|
|
fprintf(stderr, "write %d of %d bytes to socket %d from client %d\n",
|
2008-04-11 00:54:54 +08:00
|
|
|
ret, req->len, pollInfos[nr].fd, nr);
|
|
|
|
proxyCloseClientSocket(nr);
|
|
|
|
return(-1);
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
if (debug)
|
|
|
|
fprintf(stderr, "wrote %d bytes to client %d on socket %d\n",
|
2008-04-11 00:54:54 +08:00
|
|
|
ret, nr, pollInfos[nr].fd);
|
2008-02-06 03:27:37 +08:00
|
|
|
|
2006-06-29 02:19:13 +08:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* proxyReadClientSocket:
|
|
|
|
* @nr: the client number
|
|
|
|
*
|
|
|
|
* Process a read from a client socket
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
proxyReadClientSocket(int nr) {
|
2008-07-25 21:17:27 +08:00
|
|
|
virDomainDefPtr def;
|
2009-02-14 03:11:37 +08:00
|
|
|
union {
|
|
|
|
virProxyFullPacket full_request;
|
|
|
|
virProxyPacket request;
|
|
|
|
} r;
|
|
|
|
virProxyPacketPtr req = &r.request;
|
2006-06-29 02:19:13 +08:00
|
|
|
int ret;
|
2006-11-08 00:28:16 +08:00
|
|
|
char *xml, *ostype;
|
2006-06-29 02:19:13 +08:00
|
|
|
|
|
|
|
retry:
|
2006-06-30 06:12:47 +08:00
|
|
|
ret = read(pollInfos[nr].fd, req, sizeof(virProxyPacket));
|
2006-06-29 02:19:13 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
if (errno == EINTR) {
|
2008-04-11 00:54:54 +08:00
|
|
|
if (debug > 0)
|
|
|
|
fprintf(stderr, "read socket %d from client %d interrupted\n",
|
|
|
|
pollInfos[nr].fd, nr);
|
|
|
|
goto retry;
|
|
|
|
}
|
2006-06-29 02:19:13 +08:00
|
|
|
fprintf(stderr, "Failed to read socket %d from client %d\n",
|
2008-04-11 00:54:54 +08:00
|
|
|
pollInfos[nr].fd, nr);
|
|
|
|
proxyCloseClientSocket(nr);
|
|
|
|
return(-1);
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
if (ret == 0) {
|
2008-04-11 00:54:54 +08:00
|
|
|
if (debug)
|
|
|
|
fprintf(stderr, "end of stream from client %d on socket %d\n",
|
|
|
|
nr, pollInfos[nr].fd);
|
|
|
|
proxyCloseClientSocket(nr);
|
|
|
|
return(-1);
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
fprintf(stderr, "read %d bytes from client %d on socket %d\n",
|
2008-04-11 00:54:54 +08:00
|
|
|
ret, nr, pollInfos[nr].fd);
|
2008-02-06 03:27:37 +08:00
|
|
|
|
2009-01-28 22:08:33 +08:00
|
|
|
if ((ret != sizeof(virProxyPacket)) ||
|
|
|
|
(req->version != PROXY_PROTO_VERSION) ||
|
2006-07-01 00:23:16 +08:00
|
|
|
(req->len < sizeof(virProxyPacket)) ||
|
2008-04-11 00:54:54 +08:00
|
|
|
(req->len > sizeof(virProxyFullPacket)))
|
|
|
|
goto comm_error;
|
2006-07-01 00:23:16 +08:00
|
|
|
|
2008-02-06 03:27:37 +08:00
|
|
|
|
2006-06-29 02:19:13 +08:00
|
|
|
if (debug)
|
2006-06-29 22:44:37 +08:00
|
|
|
fprintf(stderr, "Got command %d from client %d\n", req->command, nr);
|
2006-06-29 02:19:13 +08:00
|
|
|
|
2006-07-01 00:23:16 +08:00
|
|
|
/*
|
|
|
|
* complete reading the packet.
|
|
|
|
* TODO: we should detect when blocking and abort connection if this happen
|
|
|
|
*/
|
|
|
|
if (req->len > ret) {
|
|
|
|
int total, extra;
|
2009-02-14 03:11:37 +08:00
|
|
|
char *base = (char *) &r;
|
2006-07-01 00:23:16 +08:00
|
|
|
|
|
|
|
total = ret;
|
2008-04-11 00:54:54 +08:00
|
|
|
while (total < req->len) {
|
|
|
|
extra = req->len - total;
|
2006-07-01 00:23:16 +08:00
|
|
|
retry2:
|
2008-04-11 00:54:54 +08:00
|
|
|
ret = read(pollInfos[nr].fd, base + total, extra);
|
|
|
|
if (ret < 0) {
|
|
|
|
if (errno == EINTR) {
|
|
|
|
if (debug > 0)
|
|
|
|
fprintf(stderr,
|
|
|
|
"read socket %d from client %d interrupted\n",
|
|
|
|
pollInfos[nr].fd, nr);
|
|
|
|
goto retry2;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "Failed to read socket %d from client %d\n",
|
|
|
|
pollInfos[nr].fd, nr);
|
|
|
|
proxyCloseClientSocket(nr);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
if (ret == 0) {
|
|
|
|
if (debug)
|
|
|
|
fprintf(stderr,
|
|
|
|
"end of stream from client %d on socket %d\n",
|
|
|
|
nr, pollInfos[nr].fd);
|
|
|
|
proxyCloseClientSocket(nr);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
total += ret;
|
|
|
|
}
|
2006-07-01 00:23:16 +08:00
|
|
|
}
|
2006-06-29 02:19:13 +08:00
|
|
|
switch (req->command) {
|
2008-04-11 00:54:54 +08:00
|
|
|
case VIR_PROXY_NONE:
|
|
|
|
if (req->len != sizeof(virProxyPacket))
|
|
|
|
goto comm_error;
|
|
|
|
break;
|
|
|
|
case VIR_PROXY_VERSION:
|
|
|
|
if (req->len != sizeof(virProxyPacket))
|
|
|
|
goto comm_error;
|
|
|
|
req->data.larg = xenVersion;
|
|
|
|
break;
|
|
|
|
case VIR_PROXY_LIST: {
|
|
|
|
int maxids;
|
|
|
|
|
|
|
|
if (req->len != sizeof(virProxyPacket))
|
|
|
|
goto comm_error;
|
2009-02-14 03:11:37 +08:00
|
|
|
maxids = sizeof(r.full_request.extra.arg) / sizeof(int);
|
|
|
|
ret = xenHypervisorListDomains(conn, &r.full_request.extra.arg[0],
|
2008-04-11 00:54:54 +08:00
|
|
|
maxids);
|
|
|
|
if (ret < 0) {
|
|
|
|
req->len = sizeof(virProxyPacket);
|
|
|
|
req->data.arg = 0;
|
|
|
|
} else {
|
|
|
|
req->len = sizeof(virProxyPacket) + ret * sizeof(int);
|
|
|
|
req->data.arg = ret;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VIR_PROXY_NUM_DOMAIN:
|
|
|
|
if (req->len != sizeof(virProxyPacket))
|
|
|
|
goto comm_error;
|
|
|
|
req->data.arg = xenHypervisorNumOfDomains(conn);
|
|
|
|
break;
|
|
|
|
case VIR_PROXY_MAX_MEMORY:
|
|
|
|
if (req->len != sizeof(virProxyPacket))
|
|
|
|
goto comm_error;
|
|
|
|
req->data.larg = xenHypervisorGetDomMaxMemory(conn, req->data.arg);
|
|
|
|
break;
|
|
|
|
case VIR_PROXY_DOMAIN_INFO:
|
|
|
|
if (req->len != sizeof(virProxyPacket))
|
|
|
|
goto comm_error;
|
2009-02-14 03:11:37 +08:00
|
|
|
memset(&r.full_request.extra.dinfo, 0, sizeof(virDomainInfo));
|
2008-04-11 00:54:54 +08:00
|
|
|
ret = xenHypervisorGetDomInfo(conn, req->data.arg,
|
2009-02-14 03:11:37 +08:00
|
|
|
&r.full_request.extra.dinfo);
|
2008-04-11 00:54:54 +08:00
|
|
|
if (ret < 0) {
|
2006-06-30 07:53:31 +08:00
|
|
|
req->data.arg = -1;
|
|
|
|
} else {
|
2008-04-11 00:54:54 +08:00
|
|
|
req->len += sizeof(virDomainInfo);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VIR_PROXY_LOOKUP_ID: {
|
|
|
|
char *name = NULL;
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (req->len != sizeof(virProxyPacket))
|
|
|
|
goto comm_error;
|
|
|
|
|
|
|
|
if (xenDaemonDomainLookupByID(conn, req->data.arg, &name, uuid) < 0) {
|
|
|
|
req->data.arg = -1;
|
|
|
|
} else {
|
|
|
|
len = strlen(name);
|
|
|
|
if (len > 1000) {
|
|
|
|
len = 1000;
|
|
|
|
name[1000] = 0;
|
|
|
|
}
|
|
|
|
req->len += VIR_UUID_BUFLEN + len + 1;
|
2009-02-14 03:11:37 +08:00
|
|
|
memcpy(&r.full_request.extra.str[0], uuid, VIR_UUID_BUFLEN);
|
|
|
|
strcpy(&r.full_request.extra.str[VIR_UUID_BUFLEN], name);
|
2008-04-11 00:54:54 +08:00
|
|
|
}
|
2008-01-30 01:41:07 +08:00
|
|
|
free(name);
|
2008-04-11 00:54:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VIR_PROXY_LOOKUP_UUID: {
|
|
|
|
char **names;
|
|
|
|
char **tmp;
|
|
|
|
int ident, len;
|
|
|
|
char *name = NULL;
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
|
|
|
|
|
|
if (req->len != sizeof(virProxyPacket) + VIR_UUID_BUFLEN)
|
|
|
|
goto comm_error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Xend API forces to collect the full domain list by names, and
|
2006-07-01 00:23:16 +08:00
|
|
|
* then query each of them until the id is found
|
2008-04-11 00:54:54 +08:00
|
|
|
*/
|
|
|
|
names = xenDaemonListDomainsOld(conn);
|
|
|
|
tmp = names;
|
|
|
|
|
|
|
|
if (names != NULL) {
|
|
|
|
while (*tmp != NULL) {
|
|
|
|
ident = xenDaemonDomainLookupByName_ids(conn, *tmp, &uuid[0]);
|
2009-02-14 03:11:37 +08:00
|
|
|
if (!memcmp(uuid, &r.full_request.extra.str[0], VIR_UUID_BUFLEN)) {
|
2008-04-11 00:54:54 +08:00
|
|
|
name = *tmp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tmp++;
|
|
|
|
}
|
|
|
|
}
|
2006-07-01 00:23:16 +08:00
|
|
|
if (name == NULL) {
|
2008-04-11 00:54:54 +08:00
|
|
|
/* not found */
|
2006-07-01 00:23:16 +08:00
|
|
|
req->data.arg = -1;
|
2008-04-11 00:54:54 +08:00
|
|
|
req->len = sizeof(virProxyPacket);
|
2006-07-01 00:23:16 +08:00
|
|
|
} else {
|
2008-04-11 00:54:54 +08:00
|
|
|
len = strlen(name);
|
|
|
|
if (len > 1000) {
|
|
|
|
len = 1000;
|
|
|
|
name[1000] = 0;
|
|
|
|
}
|
|
|
|
req->len = sizeof(virProxyPacket) + len + 1;
|
2009-02-14 03:11:37 +08:00
|
|
|
strcpy(&r.full_request.extra.str[0], name);
|
2006-07-01 00:23:16 +08:00
|
|
|
req->data.arg = ident;
|
2008-04-11 00:54:54 +08:00
|
|
|
}
|
|
|
|
free(names);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VIR_PROXY_LOOKUP_NAME: {
|
|
|
|
int ident;
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
|
|
|
|
|
|
if (req->len > sizeof(virProxyPacket) + 1000)
|
|
|
|
goto comm_error;
|
|
|
|
|
|
|
|
ident = xenDaemonDomainLookupByName_ids(conn,
|
2009-02-14 03:11:37 +08:00
|
|
|
&r.full_request.extra.str[0], &uuid[0]);
|
2008-04-11 00:54:54 +08:00
|
|
|
if (ident < 0) {
|
|
|
|
/* not found */
|
2006-07-01 00:23:16 +08:00
|
|
|
req->data.arg = -1;
|
2008-04-11 00:54:54 +08:00
|
|
|
req->len = sizeof(virProxyPacket);
|
|
|
|
} else {
|
|
|
|
req->len = sizeof(virProxyPacket) + VIR_UUID_BUFLEN;
|
2009-02-14 03:11:37 +08:00
|
|
|
memcpy(&r.full_request.extra.str[0], uuid, VIR_UUID_BUFLEN);
|
2008-04-11 00:54:54 +08:00
|
|
|
req->data.arg = ident;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VIR_PROXY_NODE_INFO:
|
|
|
|
if (req->len != sizeof(virProxyPacket))
|
|
|
|
goto comm_error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hum, could we expect those information to be unmutable and
|
|
|
|
* cache them ? Since it's probably an unfrequent call better
|
|
|
|
* not make assumption and do the xend RPC each call.
|
|
|
|
*/
|
2009-02-14 03:11:37 +08:00
|
|
|
ret = xenDaemonNodeGetInfo(conn, &r.full_request.extra.ninfo);
|
2008-04-11 00:54:54 +08:00
|
|
|
if (ret < 0) {
|
2006-07-03 19:12:12 +08:00
|
|
|
req->data.arg = -1;
|
2008-04-11 00:54:54 +08:00
|
|
|
req->len = sizeof(virProxyPacket);
|
|
|
|
} else {
|
2006-07-03 19:12:12 +08:00
|
|
|
req->data.arg = 0;
|
2008-04-11 00:54:54 +08:00
|
|
|
req->len = sizeof(virProxyPacket) + sizeof(virNodeInfo);
|
|
|
|
}
|
|
|
|
break;
|
2007-05-01 00:58:26 +08:00
|
|
|
|
2008-04-11 00:54:54 +08:00
|
|
|
case VIR_PROXY_GET_CAPABILITIES:
|
|
|
|
if (req->len != sizeof(virProxyPacket))
|
|
|
|
goto comm_error;
|
2007-05-01 00:58:26 +08:00
|
|
|
|
|
|
|
xml = xenHypervisorGetCapabilities (conn);
|
|
|
|
if (!xml) {
|
|
|
|
req->data.arg = -1;
|
|
|
|
req->len = sizeof (virProxyPacket);
|
|
|
|
} else {
|
|
|
|
int xmllen = strlen (xml);
|
2009-02-14 03:11:37 +08:00
|
|
|
if (xmllen > (int) sizeof (r.full_request.extra.str)) {
|
2007-05-01 00:58:26 +08:00
|
|
|
req->data.arg = -2;
|
|
|
|
req->len = sizeof (virProxyPacket);
|
|
|
|
} else {
|
|
|
|
req->data.arg = 0;
|
2009-02-14 03:11:37 +08:00
|
|
|
memmove (r.full_request.extra.str, xml, xmllen);
|
2007-05-01 00:58:26 +08:00
|
|
|
req->len = sizeof (virProxyPacket) + xmllen;
|
|
|
|
}
|
|
|
|
free (xml);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-04-11 00:54:54 +08:00
|
|
|
case VIR_PROXY_DOMAIN_XML:
|
|
|
|
if (req->len != sizeof(virProxyPacket))
|
|
|
|
goto comm_error;
|
2006-08-09 23:21:16 +08:00
|
|
|
|
2007-10-31 17:39:13 +08:00
|
|
|
/*
|
2008-04-11 00:54:54 +08:00
|
|
|
* Ideally we should get the CPUs used by the domain
|
|
|
|
* but that information is really node specific and it
|
|
|
|
* rather hard to get from that code path. So proxy
|
|
|
|
* users won't see CPU pinning (last NULL arg)
|
|
|
|
*/
|
2009-02-14 03:11:37 +08:00
|
|
|
def = xenDaemonDomainFetch(conn, r.full_request.data.arg, NULL, NULL);
|
2008-07-25 21:17:27 +08:00
|
|
|
if (!def) {
|
2006-08-09 23:21:16 +08:00
|
|
|
req->data.arg = -1;
|
|
|
|
req->len = sizeof(virProxyPacket);
|
2008-04-11 00:54:54 +08:00
|
|
|
} else {
|
2008-07-25 21:17:27 +08:00
|
|
|
xml = virDomainDefFormat(conn, def, 0);
|
|
|
|
if (!xml) {
|
|
|
|
req->data.arg = -1;
|
2006-08-09 23:21:16 +08:00
|
|
|
req->len = sizeof(virProxyPacket);
|
|
|
|
} else {
|
2008-07-25 21:17:27 +08:00
|
|
|
int xmllen = strlen(xml);
|
2009-02-14 03:11:37 +08:00
|
|
|
if (xmllen > (int) sizeof(r.full_request.extra.str)) {
|
2008-07-25 21:17:27 +08:00
|
|
|
req->data.arg = -2;
|
|
|
|
req->len = sizeof(virProxyPacket);
|
|
|
|
} else {
|
|
|
|
req->data.arg = 0;
|
2009-02-14 03:11:37 +08:00
|
|
|
memmove(&r.full_request.extra.str[0], xml, xmllen);
|
2008-07-25 21:17:27 +08:00
|
|
|
req->len = sizeof(virProxyPacket) + xmllen;
|
|
|
|
}
|
|
|
|
free(xml);
|
2006-08-09 23:21:16 +08:00
|
|
|
}
|
2008-04-11 00:54:54 +08:00
|
|
|
}
|
2008-07-25 21:17:27 +08:00
|
|
|
virDomainDefFree(def);
|
2008-04-11 00:54:54 +08:00
|
|
|
break;
|
|
|
|
case VIR_PROXY_DOMAIN_OSTYPE:
|
|
|
|
if (req->len != sizeof(virProxyPacket))
|
|
|
|
goto comm_error;
|
2006-11-08 00:28:16 +08:00
|
|
|
|
2009-02-14 03:11:37 +08:00
|
|
|
ostype = xenStoreDomainGetOSTypeID(conn, r.full_request.data.arg);
|
2006-11-08 00:28:16 +08:00
|
|
|
if (!ostype) {
|
|
|
|
req->data.arg = -1;
|
|
|
|
req->len = sizeof(virProxyPacket);
|
2008-04-11 00:54:54 +08:00
|
|
|
} else {
|
2006-11-08 00:28:16 +08:00
|
|
|
int ostypelen = strlen(ostype);
|
2009-02-14 03:11:37 +08:00
|
|
|
if (ostypelen > (int) sizeof(r.full_request.extra.str)) {
|
2006-11-08 00:28:16 +08:00
|
|
|
req->data.arg = -2;
|
|
|
|
req->len = sizeof(virProxyPacket);
|
|
|
|
} else {
|
|
|
|
req->data.arg = 0;
|
2009-02-14 03:11:37 +08:00
|
|
|
memmove(&r.full_request.extra.str[0], ostype, ostypelen);
|
2006-11-08 00:28:16 +08:00
|
|
|
req->len = sizeof(virProxyPacket) + ostypelen;
|
|
|
|
}
|
|
|
|
free(ostype);
|
2008-04-11 00:54:54 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto comm_error;
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
ret = proxyWriteClientSocket(nr, req);
|
|
|
|
return(ret);
|
|
|
|
|
|
|
|
comm_error:
|
|
|
|
fprintf(stderr,
|
2008-04-11 00:54:54 +08:00
|
|
|
"Communication error with client %d: malformed packet\n", nr);
|
2006-06-29 02:19:13 +08:00
|
|
|
proxyCloseClientSocket(nr);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* *
|
|
|
|
* Main loop processing *
|
|
|
|
* *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* proxyProcessRequests:
|
|
|
|
*
|
2008-02-06 03:27:37 +08:00
|
|
|
* process requests and timers
|
2006-06-29 02:19:13 +08:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
proxyProcessRequests(void) {
|
|
|
|
int exit_timeout = 30;
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
while (!done) {
|
|
|
|
/*
|
2008-04-11 00:54:54 +08:00
|
|
|
* wait for requests, with a one second timeout
|
|
|
|
*/
|
2006-06-29 02:19:13 +08:00
|
|
|
ret = poll(&pollInfos[0], nbClients + 1, 1000);
|
2008-04-11 00:54:54 +08:00
|
|
|
if (ret == 0) { /* timeout */
|
|
|
|
if ((nbClients == 0) && (persist == 0)) {
|
|
|
|
exit_timeout--;
|
|
|
|
if (exit_timeout == 0) {
|
|
|
|
done = 1;
|
|
|
|
if (debug > 0) {
|
2008-04-24 17:17:29 +08:00
|
|
|
fprintf(stderr, "Exiting after 30s without clients\n");
|
2008-04-11 00:54:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
exit_timeout = 30;
|
|
|
|
if (debug > 1)
|
|
|
|
fprintf(stderr, "poll timeout\n");
|
|
|
|
continue;
|
|
|
|
} else if (ret < 0) {
|
|
|
|
if (errno == EINTR) {
|
|
|
|
if (debug > 0)
|
|
|
|
fprintf(stderr, "poll syscall interrupted\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "poll syscall failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* there have been I/O to process
|
|
|
|
*/
|
|
|
|
exit_timeout = 30;
|
|
|
|
if (pollInfos[0].revents != 0) {
|
|
|
|
if (pollInfos[0].revents & POLLIN) {
|
|
|
|
proxyAcceptClientSocket();
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Got an error %d on incoming socket %d\n",
|
|
|
|
pollInfos[0].revents, pollInfos[0].fd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* process the clients in reverse order since on error or disconnect
|
|
|
|
* pollInfos is compacted to remove the given client.
|
|
|
|
*/
|
|
|
|
for (i = nbClients;i > 0;i--) {
|
|
|
|
if (pollInfos[i].revents & POLLIN) {
|
|
|
|
proxyReadClientSocket(i);
|
|
|
|
} else if (pollInfos[i].revents != 0) {
|
|
|
|
fprintf(stderr, "Got an error %d on client %d socket %d\n",
|
|
|
|
pollInfos[i].revents, i, pollInfos[i].fd);
|
|
|
|
proxyCloseClientSocket(i);
|
|
|
|
}
|
|
|
|
}
|
2008-02-06 03:27:37 +08:00
|
|
|
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* proxyMainLoop:
|
|
|
|
*
|
|
|
|
* main loop for the proxy, continually try to keep the unix socket
|
|
|
|
* open, serve client requests, and process timing events.
|
|
|
|
*/
|
|
|
|
|
2008-02-06 03:27:37 +08:00
|
|
|
static void
|
2006-06-29 02:19:13 +08:00
|
|
|
proxyMainLoop(void) {
|
|
|
|
while (! done) {
|
2008-04-11 00:54:54 +08:00
|
|
|
if (proxyListenUnixSocket(PROXY_SOCKET_PATH) < 0)
|
|
|
|
break;
|
|
|
|
proxyProcessRequests();
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
proxyCloseClientSockets();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* usage:
|
|
|
|
*
|
2008-03-14 19:08:03 +08:00
|
|
|
* dump on stdout information about the program
|
2006-06-29 02:19:13 +08:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
usage(const char *progname) {
|
|
|
|
printf("Usage: %s [-v] [-v]\n", progname);
|
|
|
|
printf(" option -v increase the verbosity level for debugging\n");
|
|
|
|
printf("This is a proxy for xen services used by libvirt to offer\n");
|
|
|
|
printf("safe and fast status information on the Xen virtualization.\n");
|
|
|
|
printf("This need not be run manually it's started automatically.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* main:
|
|
|
|
*
|
2008-04-04 15:58:29 +08:00
|
|
|
* Check that we are running with root privileges, initialize the
|
2006-06-29 02:19:13 +08:00
|
|
|
* connections to the daemon and or hypervisor, and then run the main loop
|
|
|
|
*/
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
int i;
|
|
|
|
|
2006-09-21 23:24:37 +08:00
|
|
|
if (!setlocale(LC_ALL, "")) {
|
|
|
|
perror("setlocale");
|
2008-04-11 00:54:54 +08:00
|
|
|
return -1;
|
2006-09-21 23:24:37 +08:00
|
|
|
}
|
|
|
|
if (!bindtextdomain(GETTEXT_PACKAGE, LOCALEBASEDIR)) {
|
|
|
|
perror("bindtextdomain");
|
2008-04-11 00:54:54 +08:00
|
|
|
return -1;
|
2006-09-21 23:24:37 +08:00
|
|
|
}
|
|
|
|
if (!textdomain(GETTEXT_PACKAGE)) {
|
|
|
|
perror("textdomain");
|
2008-04-11 00:54:54 +08:00
|
|
|
return -1;
|
2006-09-21 23:24:37 +08:00
|
|
|
}
|
|
|
|
|
2006-06-29 02:19:13 +08:00
|
|
|
for (i = 1; i < argc; i++) {
|
2008-05-15 03:51:24 +08:00
|
|
|
if (STREQ(argv[i], "-v")) {
|
2008-04-11 00:54:54 +08:00
|
|
|
debug++;
|
2008-05-15 03:51:24 +08:00
|
|
|
} else if (STREQ(argv[i], "-no-timeout")) {
|
2008-04-11 00:54:54 +08:00
|
|
|
persist = 1;
|
|
|
|
} else {
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
2006-09-21 23:24:37 +08:00
|
|
|
|
|
|
|
|
2006-06-29 02:19:13 +08:00
|
|
|
if (geteuid() != 0) {
|
|
|
|
fprintf(stderr, "%s must be run as root or suid\n", argv[0]);
|
2008-04-11 00:54:54 +08:00
|
|
|
/* exit(1); */
|
2006-06-29 02:19:13 +08:00
|
|
|
}
|
|
|
|
|
2006-06-29 22:44:37 +08:00
|
|
|
/*
|
|
|
|
* setup a connection block
|
|
|
|
*/
|
|
|
|
memset(conn, 0, sizeof(conninfos));
|
|
|
|
conn->magic = VIR_CONNECT_MAGIC;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* very fist thing, use the socket as an exclusive lock, this then
|
|
|
|
* allow to do timed exits, avoiding constant CPU usage in case of
|
|
|
|
* failure.
|
|
|
|
*/
|
|
|
|
if (proxyListenUnixSocket(PROXY_SOCKET_PATH) < 0)
|
|
|
|
exit(0);
|
|
|
|
if (proxyInitXen() == 0)
|
2008-04-11 00:54:54 +08:00
|
|
|
proxyMainLoop();
|
2006-06-29 22:44:37 +08:00
|
|
|
sleep(1);
|
|
|
|
proxyCloseUnixSocket();
|
2006-06-29 02:19:13 +08:00
|
|
|
exit(0);
|
|
|
|
}
|
2007-03-16 01:24:56 +08:00
|
|
|
|
2007-03-15 15:43:16 +08:00
|
|
|
#else /* WITHOUT_XEN */
|
2007-12-07 22:45:39 +08:00
|
|
|
|
2007-03-15 15:43:16 +08:00
|
|
|
int main(void) {
|
|
|
|
fprintf(stderr, "libvirt was compiled without Xen support\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2007-12-07 22:45:39 +08:00
|
|
|
|
2007-03-15 15:43:16 +08:00
|
|
|
#endif /* WITH_XEN */
|