aboutsummaryrefslogtreecommitdiffstats
path: root/xenlog.c
diff options
context:
space:
mode:
authorkraxel <kraxel>2005-12-08 11:17:50 +0000
committerkraxel <kraxel>2005-12-08 11:17:50 +0000
commite22cc1e84130dfe1086088c0452efc6596e5b855 (patch)
tree95045ace03f576aa357b079a780853f66044c0ad /xenlog.c
downloadxenwatch-e22cc1e84130dfe1086088c0452efc6596e5b855.tar.gz
Initial revision
Diffstat (limited to 'xenlog.c')
-rw-r--r--xenlog.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/xenlog.c b/xenlog.c
new file mode 100644
index 0000000..d5ab4d0
--- /dev/null
+++ b/xenlog.c
@@ -0,0 +1,55 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <xs.h>
+
+/* ------------------------------------------------------------- */
+
+int main(int argc, char *argv[])
+{
+ struct xs_handle *xenstore;
+ struct xs_transaction_handle *xst;
+ char *xs_value = NULL, **vec;
+ char *value;
+ unsigned int count;
+
+ xenstore = xs_daemon_open_readonly();
+ if (NULL == xenstore) {
+ fprintf(stderr,"can't connect to %s\n",xs_daemon_socket_ro());
+ exit(1);
+ }
+ xs_watch(xenstore, "/", "token");
+
+ for (;;) {
+ vec = xs_read_watch(xenstore, &count);
+ if (NULL == vec) {
+ fprintf(stderr,"xs_read_watch() failed\n");
+ exit(1);
+ }
+ switch (vec[XS_WATCH_PATH][0]) {
+ case '/':
+ xst = xs_transaction_start(xenstore);
+ if (NULL != xst) {
+ xs_value = xs_read(xenstore, xst, vec[XS_WATCH_PATH], NULL);
+ xs_transaction_end(xenstore, xst, 0);
+ if (NULL == xs_value)
+ value = "<deleted>";
+ else
+ value = xs_value;
+ } else {
+ value = "<error>";
+ }
+ break;
+ default:
+ value = "<null>";
+ break;
+ }
+ fprintf(stderr,"%-64s : \"%s\"\n", vec[XS_WATCH_PATH], value);
+
+ if (xs_value) {
+ free(xs_value);
+ xs_value = NULL;
+ }
+ free(vec);
+ }
+}