aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xenstore/xs.c
diff options
context:
space:
mode:
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>2005-10-07 15:51:53 +0100
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>2005-10-07 15:51:53 +0100
commit76bd51c23dad4ceb2d3b7677229aac117693b97c (patch)
treeff3dd6430e1ff4e03a4c80ee4090fb00deebc9ee /tools/xenstore/xs.c
parent86a5b732c1a88dee3ed80c34ebf0ed92d75989d6 (diff)
downloadxen-76bd51c23dad4ceb2d3b7677229aac117693b97c.tar.gz
xen-76bd51c23dad4ceb2d3b7677229aac117693b97c.tar.bz2
xen-76bd51c23dad4ceb2d3b7677229aac117693b97c.zip
Change xs_read_watch interface to return a sized array (in userspace and in
kernel). Add index macros (XS_WATCH_*) for accessing the array to allow for future expansion. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'tools/xenstore/xs.c')
-rw-r--r--tools/xenstore/xs.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
index a842a6e39c..4f21bbc590 100644
--- a/tools/xenstore/xs.c
+++ b/tools/xenstore/xs.c
@@ -449,25 +449,44 @@ bool xs_watch(struct xs_handle *h, const char *path, const char *token)
* Returns array of two pointers: path and token, or NULL.
* Call free() after use.
*/
-char **xs_read_watch(struct xs_handle *h)
+char **xs_read_watch(struct xs_handle *h, unsigned int *num)
{
struct xsd_sockmsg msg;
char **ret;
+ char *strings;
+ unsigned int num_strings, i;
if (!read_all(h->fd, &msg, sizeof(msg)))
return NULL;
assert(msg.type == XS_WATCH_EVENT);
- ret = malloc(sizeof(char *)*2 + msg.len);
- if (!ret)
+ strings = malloc(msg.len);
+ if (!strings)
return NULL;
- ret[0] = (char *)(ret + 2);
- if (!read_all(h->fd, ret[0], msg.len)) {
- free_no_errno(ret);
+ if (!read_all(h->fd, strings, msg.len)) {
+ free_no_errno(strings);
return NULL;
}
- ret[1] = ret[0] + strlen(ret[0]) + 1;
+
+ num_strings = xs_count_strings(strings, msg.len);
+
+ ret = malloc(sizeof(char*) * num_strings + msg.len);
+ if (!ret) {
+ free_no_errno(strings);
+ return NULL;
+ }
+
+ ret[0] = (char *)(ret + num_strings);
+ memcpy(ret[0], strings, msg.len);
+ free(strings);
+
+ for (i = 1; i < num_strings; i++) {
+ ret[i] = ret[i - 1] + strlen(ret[i - 1]) + 1;
+ }
+
+ *num = num_strings;
+
return ret;
}