debuggers.hg
changeset 6788:d8637529daff
Always allow overriding where clients connect through XENSTORED_PATH.
Detect if we're connecting to a socket or to the domain device and
open accordingly.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Detect if we're connecting to a socket or to the domain device and
open accordingly.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author | cl349@firebug.cl.cam.ac.uk |
---|---|
date | Mon Sep 12 21:42:26 2005 +0000 (2005-09-12) |
parents | 80afc502461b |
children | 1cb7adaa3355 |
files | tools/xenstore/xs.c tools/xenstore/xs_lib.c |
line diff
1.1 --- a/tools/xenstore/xs.c Mon Sep 12 21:12:16 2005 +0000 1.2 +++ b/tools/xenstore/xs.c Mon Sep 12 21:42:26 2005 +0000 1.3 @@ -97,19 +97,32 @@ static struct xs_handle *get_dev(const c 1.4 return NULL; 1.5 } 1.6 1.7 +static struct xs_handle *get_handle(const char *connect_to) 1.8 +{ 1.9 + struct stat buf; 1.10 + 1.11 + if (stat(connect_to, &buf) != 0) 1.12 + return NULL; 1.13 + 1.14 + if (S_ISSOCK(buf.st_mode)) 1.15 + return get_socket(connect_to); 1.16 + else 1.17 + return get_dev(connect_to); 1.18 +} 1.19 + 1.20 struct xs_handle *xs_daemon_open(void) 1.21 { 1.22 - return get_socket(xs_daemon_socket()); 1.23 + return get_handle(xs_daemon_socket()); 1.24 } 1.25 1.26 struct xs_handle *xs_daemon_open_readonly(void) 1.27 { 1.28 - return get_socket(xs_daemon_socket_ro()); 1.29 + return get_handle(xs_daemon_socket_ro()); 1.30 } 1.31 1.32 struct xs_handle *xs_domain_open(void) 1.33 { 1.34 - return get_dev(xs_domain_dev()); 1.35 + return get_handle(xs_domain_dev()); 1.36 } 1.37 1.38 void xs_daemon_close(struct xs_handle *h)
2.1 --- a/tools/xenstore/xs_lib.c Mon Sep 12 21:12:16 2005 +0000 2.2 +++ b/tools/xenstore/xs_lib.c Mon Sep 12 21:42:26 2005 +0000 2.3 @@ -38,37 +38,55 @@ static const char *xs_daemon_rundir(void 2.4 return (s ? s : "/var/run/xenstored"); 2.5 } 2.6 2.7 -const char *xs_daemon_socket(void) 2.8 +static const char *xs_daemon_path(void) 2.9 { 2.10 static char buf[PATH_MAX]; 2.11 - sprintf(buf, "%s/socket", xs_daemon_rundir()); 2.12 + char *s = getenv("XENSTORED_PATH"); 2.13 + if (s) 2.14 + return s; 2.15 + if (snprintf(buf, PATH_MAX, "%s/socket", 2.16 + xs_daemon_rundir()) >= PATH_MAX) 2.17 + return NULL; 2.18 return buf; 2.19 } 2.20 2.21 +const char *xs_daemon_socket(void) 2.22 +{ 2.23 + return xs_daemon_path(); 2.24 +} 2.25 + 2.26 const char *xs_daemon_socket_ro(void) 2.27 { 2.28 static char buf[PATH_MAX]; 2.29 - sprintf(buf, "%s/socket_ro", xs_daemon_rundir()); 2.30 + const char *s = xs_daemon_path(); 2.31 + if (s == NULL) 2.32 + return NULL; 2.33 + if (snprintf(buf, PATH_MAX, "%s_ro", s) >= PATH_MAX) 2.34 + return NULL; 2.35 return buf; 2.36 } 2.37 2.38 const char *xs_daemon_store(void) 2.39 { 2.40 static char buf[PATH_MAX]; 2.41 - sprintf(buf, "%s/store", xs_daemon_rootdir()); 2.42 + if (snprintf(buf, PATH_MAX, "%s/store", 2.43 + xs_daemon_rootdir()) >= PATH_MAX) 2.44 + return NULL; 2.45 return buf; 2.46 } 2.47 2.48 const char *xs_daemon_transactions(void) 2.49 { 2.50 static char buf[PATH_MAX]; 2.51 - sprintf(buf, "%s/transactions", xs_daemon_rootdir()); 2.52 + if (snprintf(buf, PATH_MAX, "%s/transactions", 2.53 + xs_daemon_rootdir()) >= PATH_MAX) 2.54 + return NULL; 2.55 return buf; 2.56 } 2.57 2.58 const char *xs_domain_dev(void) 2.59 { 2.60 - char *s = getenv("XENSTORED_DOMAIN_DEV"); 2.61 + char *s = getenv("XENSTORED_PATH"); 2.62 return (s ? s : "/proc/xen/xenbus"); 2.63 } 2.64