aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xenstore/xs.c
diff options
context:
space:
mode:
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>2005-09-12 21:12:16 +0000
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>2005-09-12 21:12:16 +0000
commit493519fd231c627f3356107ba0f819870090b180 (patch)
tree97c2196535440836f3322ada09cd099fb3a185f0 /tools/xenstore/xs.c
parent849d58c0c23c41b275f4db7acb2a78779ae368c6 (diff)
downloadxen-493519fd231c627f3356107ba0f819870090b180.tar.gz
xen-493519fd231c627f3356107ba0f819870090b180.tar.bz2
xen-493519fd231c627f3356107ba0f819870090b180.zip
Change xenbus_dev interface from ioctl to read/write.
Check boundaries so we can recover if userspace dies. Also simplifies libxenstore. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Diffstat (limited to 'tools/xenstore/xs.c')
-rw-r--r--tools/xenstore/xs.c62
1 files changed, 5 insertions, 57 deletions
diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
index 5d36a8d642..95fc942c4a 100644
--- a/tools/xenstore/xs.c
+++ b/tools/xenstore/xs.c
@@ -36,12 +36,10 @@
#include "xenstored.h"
#include "xs_lib.h"
#include "utils.h"
-#include "xenbus_dev.h"
struct xs_handle
{
int fd;
- enum { SOCK, DEV } type;
};
/* Get the socket from the store daemon handle.
@@ -68,7 +66,6 @@ static struct xs_handle *get_socket(const char *connect_to)
h = malloc(sizeof(*h));
if (h) {
h->fd = sock;
- h->type = SOCK;
return h;
}
}
@@ -82,16 +79,15 @@ static struct xs_handle *get_socket(const char *connect_to)
static struct xs_handle *get_dev(const char *connect_to)
{
int fd, saved_errno;
- struct xs_handle *h = NULL;
+ struct xs_handle *h;
- fd = open(connect_to, O_RDONLY);
+ fd = open(connect_to, O_RDWR);
if (fd < 0)
return NULL;
h = malloc(sizeof(*h));
if (h) {
h->fd = fd;
- h->type = DEV;
return h;
}
@@ -190,9 +186,9 @@ static void *read_reply(int fd, enum xsd_sockmsg_type *type, unsigned int *len)
}
/* Send message to xs, get malloc'ed reply. NULL and set errno on error. */
-static void *xs_talkv_sock(struct xs_handle *h, enum xsd_sockmsg_type type,
- const struct iovec *iovec, unsigned int num_vecs,
- unsigned int *len)
+static void *xs_talkv(struct xs_handle *h, enum xsd_sockmsg_type type,
+ const struct iovec *iovec, unsigned int num_vecs,
+ unsigned int *len)
{
struct xsd_sockmsg msg;
void *ret = NULL;
@@ -253,54 +249,6 @@ close_fd:
return NULL;
}
-/* Send message to xs, get malloc'ed reply. NULL and set errno on error. */
-static void *xs_talkv_dev(struct xs_handle *h, enum xsd_sockmsg_type type,
- const struct iovec *iovec, unsigned int num_vecs,
- unsigned int *len)
-{
- struct xenbus_dev_talkv dt;
- char *buf;
- int err, buflen = 1024;
-
- again:
- buf = malloc(buflen);
- if (buf == NULL) {
- errno = ENOMEM;
- return NULL;
- }
- dt.type = type;
- dt.iovec = (struct kvec *)iovec;
- dt.num_vecs = num_vecs;
- dt.buf = buf;
- dt.len = buflen;
- err = ioctl(h->fd, IOCTL_XENBUS_DEV_TALKV, &dt);
- if (err < 0) {
- free(buf);
- errno = err;
- return NULL;
- }
- if (err > buflen) {
- free(buf);
- buflen = err;
- goto again;
- }
- if (len)
- *len = err;
- return buf;
-}
-
-/* Send message to xs, get malloc'ed reply. NULL and set errno on error. */
-static void *xs_talkv(struct xs_handle *h, enum xsd_sockmsg_type type,
- const struct iovec *iovec, unsigned int num_vecs,
- unsigned int *len)
-{
- if (h->type == SOCK)
- return xs_talkv_sock(h, type, iovec, num_vecs, len);
- if (h->type == DEV)
- return xs_talkv_dev(h, type, iovec, num_vecs, len);
- return NULL;
-}
-
/* free(), but don't change errno. */
static void free_no_errno(void *p)
{