ia64/xen-unstable

changeset 6770: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>
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 +static const char *xs_daemon_path(void)
     2.8 +{
     2.9 +	static char buf[PATH_MAX];
    2.10 +	char *s = getenv("XENSTORED_PATH");
    2.11 +	if (s)
    2.12 +		return s;
    2.13 +	if (snprintf(buf, PATH_MAX, "%s/socket",
    2.14 +		     xs_daemon_rundir()) >= PATH_MAX)
    2.15 +		return NULL;
    2.16 +	return buf;
    2.17 +}
    2.18 +
    2.19  const char *xs_daemon_socket(void)
    2.20  {
    2.21 -	static char buf[PATH_MAX];
    2.22 -	sprintf(buf, "%s/socket", xs_daemon_rundir());
    2.23 -	return buf;
    2.24 +	return xs_daemon_path();
    2.25  }
    2.26  
    2.27  const char *xs_daemon_socket_ro(void)
    2.28  {
    2.29  	static char buf[PATH_MAX];
    2.30 -	sprintf(buf, "%s/socket_ro", xs_daemon_rundir());
    2.31 +	const char *s = xs_daemon_path();
    2.32 +	if (s == NULL)
    2.33 +		return NULL;
    2.34 +	if (snprintf(buf, PATH_MAX, "%s_ro", s) >= PATH_MAX)
    2.35 +		return NULL;
    2.36  	return buf;
    2.37  }
    2.38  
    2.39  const char *xs_daemon_store(void)
    2.40  {
    2.41  	static char buf[PATH_MAX];
    2.42 -	sprintf(buf, "%s/store", xs_daemon_rootdir());
    2.43 +	if (snprintf(buf, PATH_MAX, "%s/store",
    2.44 +		     xs_daemon_rootdir()) >= PATH_MAX)
    2.45 +		return NULL;
    2.46  	return buf;
    2.47  }
    2.48  
    2.49  const char *xs_daemon_transactions(void)
    2.50  {
    2.51  	static char buf[PATH_MAX];
    2.52 -	sprintf(buf, "%s/transactions", xs_daemon_rootdir());
    2.53 +	if (snprintf(buf, PATH_MAX, "%s/transactions",
    2.54 +		     xs_daemon_rootdir()) >= PATH_MAX)
    2.55 +		return NULL;
    2.56  	return buf;
    2.57  }
    2.58  
    2.59  const char *xs_domain_dev(void)
    2.60  {
    2.61 -	char *s = getenv("XENSTORED_DOMAIN_DEV");
    2.62 +	char *s = getenv("XENSTORED_PATH");
    2.63  	return (s ? s : "/proc/xen/xenbus");
    2.64  }
    2.65