aboutsummaryrefslogtreecommitdiffstats
path: root/xs_tools.c
diff options
context:
space:
mode:
authorkraxel <kraxel>2007-08-16 09:39:08 +0000
committerkraxel <kraxel>2007-08-16 09:39:08 +0000
commitc0502bd98529eb55e6f1aeb630c551071f648f09 (patch)
treeda4c50825b640f1c3c82bed24be557a085ff7a10 /xs_tools.c
parentdbe2e2d981739d80417288a57872d2e24c5acf1d (diff)
downloadxenwatch-c0502bd98529eb55e6f1aeb630c551071f648f09.tar.gz
cleanups
Diffstat (limited to 'xs_tools.c')
-rw-r--r--xs_tools.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/xs_tools.c b/xs_tools.c
new file mode 100644
index 0000000..5a72b45
--- /dev/null
+++ b/xs_tools.c
@@ -0,0 +1,60 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <xs.h>
+
+#include "xs_tools.h"
+
+/* ------------------------------------------------------------- */
+
+struct xs_handle *xenstore_open(int daemon, int domain,
+ int readonly_ok, int verbose)
+{
+ struct xs_handle *xenstore = NULL;
+
+ if (NULL == xenstore && daemon && readonly_ok) {
+ xenstore = xs_daemon_open_readonly();
+ if (NULL == xenstore)
+ fprintf(stderr,"can't connect to %s\n",xs_daemon_socket_ro());
+ else
+ if (verbose)
+ printf("connected to %s\n", xs_daemon_socket_ro());
+ }
+
+ if (NULL == xenstore && daemon) {
+ xenstore = xs_daemon_open();
+ if (NULL == xenstore)
+ fprintf(stderr,"can't connect to %s\n",xs_daemon_socket());
+ else
+ if (verbose)
+ printf("connected to %s\n", xs_daemon_socket());
+ }
+
+ if (NULL == xenstore && domain) {
+ xenstore = xs_domain_open();
+ if (NULL == xenstore)
+ fprintf(stderr, "can't connect to %s\n", xs_domain_dev());
+ else
+ if (verbose)
+ printf("connected to %s\n", xs_domain_dev());
+ }
+ return xenstore;
+}
+
+int xenstore_read(struct xs_handle *xenstore, char *path, char *dst, size_t size)
+{
+ xs_transaction_t xst;
+ char *xs_value = NULL;
+
+ xst = xs_transaction_start(xenstore);
+ if (!xst)
+ return -1;
+
+ xs_value = xs_read(xenstore, xst, path, NULL);
+ xs_transaction_end(xenstore, xst, 0);
+ if (NULL == xs_value)
+ return -2;
+ snprintf(dst, size, "%s", xs_value);
+ free(xs_value);
+ return 0;
+}