# HG changeset patch
# User cl349@xxxxxxxxxxxxxxxxxxxx
# Node ID d8637529dafff3c610e4bb31349d4ae00a23a18e
# Parent 80afc502461b56539092dec5c1fa6df05df8baf2
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@xxxxxxxxxxxx>
diff -r 80afc502461b -r d8637529daff tools/xenstore/xs.c
--- a/tools/xenstore/xs.c Mon Sep 12 21:12:16 2005
+++ b/tools/xenstore/xs.c Mon Sep 12 21:42:26 2005
@@ -97,19 +97,32 @@
return NULL;
}
+static struct xs_handle *get_handle(const char *connect_to)
+{
+ struct stat buf;
+
+ if (stat(connect_to, &buf) != 0)
+ return NULL;
+
+ if (S_ISSOCK(buf.st_mode))
+ return get_socket(connect_to);
+ else
+ return get_dev(connect_to);
+}
+
struct xs_handle *xs_daemon_open(void)
{
- return get_socket(xs_daemon_socket());
+ return get_handle(xs_daemon_socket());
}
struct xs_handle *xs_daemon_open_readonly(void)
{
- return get_socket(xs_daemon_socket_ro());
+ return get_handle(xs_daemon_socket_ro());
}
struct xs_handle *xs_domain_open(void)
{
- return get_dev(xs_domain_dev());
+ return get_handle(xs_domain_dev());
}
void xs_daemon_close(struct xs_handle *h)
diff -r 80afc502461b -r d8637529daff tools/xenstore/xs_lib.c
--- a/tools/xenstore/xs_lib.c Mon Sep 12 21:12:16 2005
+++ b/tools/xenstore/xs_lib.c Mon Sep 12 21:42:26 2005
@@ -38,37 +38,55 @@
return (s ? s : "/var/run/xenstored");
}
+static const char *xs_daemon_path(void)
+{
+ static char buf[PATH_MAX];
+ char *s = getenv("XENSTORED_PATH");
+ if (s)
+ return s;
+ if (snprintf(buf, PATH_MAX, "%s/socket",
+ xs_daemon_rundir()) >= PATH_MAX)
+ return NULL;
+ return buf;
+}
+
const char *xs_daemon_socket(void)
{
- static char buf[PATH_MAX];
- sprintf(buf, "%s/socket", xs_daemon_rundir());
- return buf;
+ return xs_daemon_path();
}
const char *xs_daemon_socket_ro(void)
{
static char buf[PATH_MAX];
- sprintf(buf, "%s/socket_ro", xs_daemon_rundir());
+ const char *s = xs_daemon_path();
+ if (s == NULL)
+ return NULL;
+ if (snprintf(buf, PATH_MAX, "%s_ro", s) >= PATH_MAX)
+ return NULL;
return buf;
}
const char *xs_daemon_store(void)
{
static char buf[PATH_MAX];
- sprintf(buf, "%s/store", xs_daemon_rootdir());
+ if (snprintf(buf, PATH_MAX, "%s/store",
+ xs_daemon_rootdir()) >= PATH_MAX)
+ return NULL;
return buf;
}
const char *xs_daemon_transactions(void)
{
static char buf[PATH_MAX];
- sprintf(buf, "%s/transactions", xs_daemon_rootdir());
+ if (snprintf(buf, PATH_MAX, "%s/transactions",
+ xs_daemon_rootdir()) >= PATH_MAX)
+ return NULL;
return buf;
}
const char *xs_domain_dev(void)
{
- char *s = getenv("XENSTORED_DOMAIN_DEV");
+ char *s = getenv("XENSTORED_PATH");
return (s ? s : "/proc/xen/xenbus");
}
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|