diff -r 89116f28083f tools/xenstore/xs.c --- a/tools/xenstore/xs.c Wed Dec 08 10:46:31 2010 +0000 +++ b/tools/xenstore/xs.c Thu Dec 09 22:48:18 2010 -0800 @@ -182,12 +182,15 @@ return -1; } -static int get_dev(const char *connect_to) +static int get_dev(const char *connect_to, int ro) { - return open(connect_to, O_RDWR); + if (!ro) + return open(connect_to, O_RDWR); + else + return open(connect_to, O_RDONLY); } -static struct xs_handle *get_handle(const char *connect_to) +static struct xs_handle *get_handle(const char *connect_to, int ro) { struct stat buf; struct xs_handle *h = NULL; @@ -199,7 +202,7 @@ if (S_ISSOCK(buf.st_mode)) fd = get_socket(connect_to); else - fd = get_dev(connect_to); + fd = get_dev(connect_to, ro); if (fd == -1) return NULL; @@ -237,17 +240,37 @@ struct xs_handle *xs_daemon_open(void) { - return get_handle(xs_daemon_socket()); + return xs_open(0); } struct xs_handle *xs_daemon_open_readonly(void) { - return get_handle(xs_daemon_socket_ro()); + return xs_open(1); } struct xs_handle *xs_domain_open(void) { - return get_handle(xs_domain_dev()); + return xs_open(0); +} + +struct xs_handle *xs_open(int ro) +{ + struct xs_handle *xsh = NULL; + + if(!ro) { + xsh = get_handle(xs_daemon_socket(), 0); + + if(!xsh) + xsh = get_handle(xs_domain_dev(), 0); + } + else { + xsh = get_handle(xs_daemon_socket_ro(), 1); + + if(!xsh) + xsh = get_handle(xs_domain_dev(), 1); + } + + return xsh; } static void close_free_msgs(struct xs_handle *h) { diff -r 89116f28083f tools/xenstore/xs.h --- a/tools/xenstore/xs.h Wed Dec 08 10:46:31 2010 +0000 +++ b/tools/xenstore/xs.h Thu Dec 09 22:48:18 2010 -0800 @@ -39,6 +39,7 @@ */ struct xs_handle *xs_daemon_open(void); struct xs_handle *xs_domain_open(void); +struct xs_handle *xs_open(int ro); /* Connect to the xs daemon (readonly for non-root clients). * Returns a handle or NULL.