[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] xenstore: add xenstore-watch command line client
# HG changeset patch # User Ian Campbell <ian.campbell@xxxxxxxxxx> # Date 1287681290 -3600 # Node ID bfb3c97ef5071b99d33683ce9c8b7a6f727146bd # Parent 4ad1603dce89841b9abde8dd3bc9159c1d391108 xenstore: add xenstore-watch command line client # xenstore-watch x | while read w ; do > echo "watch fired on $w" > echo "value" $(xenstore-read $w) > echo > done # xenstore-write x/y/z 42 output from while loop: watch fired on x/t/z value 42 [ also add line to .hgignore - iwj ] Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx> Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> --- .hgignore | 1 tools/xenstore/Makefile | 2 - tools/xenstore/xenstore_client.c | 49 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 4 deletions(-) diff -r 4ad1603dce89 -r bfb3c97ef507 .hgignore --- a/.hgignore Thu Oct 21 18:00:39 2010 +0100 +++ b/.hgignore Thu Oct 21 18:14:50 2010 +0100 @@ -262,6 +262,7 @@ ^tools/xenstore/xenstore-write$ ^tools/xenstore/xenstore-control$ ^tools/xenstore/xenstore-ls$ +^tools/xenstore/xenstore-watch$ ^tools/xenstore/xenstored$ ^tools/xenstore/xenstored_test$ ^tools/xenstore/xs_crashme$ diff -r 4ad1603dce89 -r bfb3c97ef507 tools/xenstore/Makefile --- a/tools/xenstore/Makefile Thu Oct 21 18:00:39 2010 +0100 +++ b/tools/xenstore/Makefile Thu Oct 21 18:14:50 2010 +0100 @@ -9,7 +9,7 @@ CFLAGS += $(CFLAGS_libxenctrl) CFLAGS += $(CFLAGS_libxenctrl) CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm xenstore-chmod -CLIENTS += xenstore-write xenstore-ls +CLIENTS += xenstore-write xenstore-ls xenstore-watch XENSTORED_OBJS = xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o tdb.o hashtable.o diff -r 4ad1603dce89 -r bfb3c97ef507 tools/xenstore/xenstore_client.c --- a/tools/xenstore/xenstore_client.c Thu Oct 21 18:00:39 2010 +0100 +++ b/tools/xenstore/xenstore_client.c Thu Oct 21 18:14:50 2010 +0100 @@ -36,6 +36,7 @@ enum mode { MODE_read, MODE_rm, MODE_write, + MODE_watch, }; static char *output_buf = NULL; @@ -95,6 +96,9 @@ usage(enum mode mode, int incl_mode, con case MODE_chmod: mstr = incl_mode ? "chmod " : ""; errx(1, "Usage: %s %s[-h] [-u] [-r] [-s] key <mode [modes...]>", progname, mstr); + case MODE_watch: + mstr = incl_mode ? "watch " : ""; + errx(1, "Usage: %s %s[-h] [-n NR] key", progname, mstr); } } @@ -263,9 +267,28 @@ do_chmod(char *path, struct xs_permissio } } +static void +do_watch(struct xs_handle *xsh, int max_events) +{ + int count = 0; + char **vec = NULL; + + for ( count = 0; max_events == -1 || count < max_events; count++ ) { + unsigned int num; + + vec = xs_read_watch(xsh, &num); + if (vec == NULL) + continue; + + printf("%s\n", vec[XS_WATCH_PATH]); + fflush(stdout); + free(vec); + } +} + static int perform(enum mode mode, int optind, int argc, char **argv, struct xs_handle *xsh, - xs_transaction_t xth, int prefix, int tidy, int upto, int recurse) + xs_transaction_t xth, int prefix, int tidy, int upto, int recurse, int nr_watches) { switch (mode) { case MODE_ls: @@ -428,6 +451,15 @@ perform(enum mode mode, int optind, int do_chmod(path, perms, nperms, upto, recurse, xsh, xth); break; } + case MODE_watch: { + for (; argv[optind]; optind++) { + const char *w = argv[optind]; + + if (!xs_watch(xsh, w, w)) + errx(1, "Unable to add watch on %s\n", w); + } + do_watch(xsh, nr_watches); + } } } @@ -452,6 +484,8 @@ static enum mode lookup_mode(const char return MODE_write; else if (strcmp(m, "read") == 0) return MODE_read; + else if (strcmp(m, "watch") == 0) + return MODE_watch; errx(1, "unknown mode %s\n", m); return 0; @@ -467,6 +501,7 @@ main(int argc, char **argv) int tidy = 0; int upto = 0; int recurse = 0; + int nr_watches = -1; int transaction; struct winsize ws; enum mode mode; @@ -500,10 +535,11 @@ main(int argc, char **argv) {"tidy", 0, 0, 't'}, /* MODE_rm */ {"upto", 0, 0, 'u'}, /* MODE_chmod */ {"recurse", 0, 0, 'r'}, /* MODE_chmod */ + {"number", 1, 0, 'n'}, /* MODE_watch */ {0, 0, 0, 0} }; - c = getopt_long(argc - switch_argv, argv + switch_argv, "hfsptur", + c = getopt_long(argc - switch_argv, argv + switch_argv, "hfspturn:", long_options, &index); if (c == -1) break; @@ -548,6 +584,12 @@ main(int argc, char **argv) else usage(mode, switch_argv, argv[0]); break; + case 'n': + if ( mode == MODE_watch ) + nr_watches = atoi(optarg); + else + usage(mode, switch_argv, argv[0]); + break; } } @@ -575,6 +617,7 @@ main(int argc, char **argv) transaction = (argc - switch_argv - optind) > 2; break; case MODE_ls: + case MODE_watch: transaction = 0; break; default: @@ -601,7 +644,7 @@ again: errx(1, "couldn't start transaction"); } - ret = perform(mode, optind, argc - switch_argv, argv + switch_argv, xsh, xth, prefix, tidy, upto, recurse); + ret = perform(mode, optind, argc - switch_argv, argv + switch_argv, xsh, xth, prefix, tidy, upto, recurse, nr_watches); if (transaction && !xs_transaction_end(xsh, xth, ret)) { if (ret == 0 && errno == EAGAIN) { _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |