diff options
author | cl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk> | 2005-09-12 20:46:37 +0000 |
---|---|---|
committer | cl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk> | 2005-09-12 20:46:37 +0000 |
commit | 849d58c0c23c41b275f4db7acb2a78779ae368c6 (patch) | |
tree | 1a3a0968351d9b0f0f929c55c02d89f246bade53 /tools/xenstore/xenstore_client.c | |
parent | 84592bf97c218c5e8cf6ac9ca120a72692dbe193 (diff) | |
download | xen-849d58c0c23c41b275f4db7acb2a78779ae368c6.tar.gz xen-849d58c0c23c41b275f4db7acb2a78779ae368c6.tar.bz2 xen-849d58c0c23c41b275f4db7acb2a78779ae368c6.zip |
Add xenstore-list and xenstore-exists clients
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Diffstat (limited to 'tools/xenstore/xenstore_client.c')
-rw-r--r-- | tools/xenstore/xenstore_client.c | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/tools/xenstore/xenstore_client.c b/tools/xenstore/xenstore_client.c index 842aca33fe..50a774d296 100644 --- a/tools/xenstore/xenstore_client.c +++ b/tools/xenstore/xenstore_client.c @@ -22,7 +22,7 @@ usage(const char *progname) errx(1, "Usage: %s [-h] [-p] key [...]", progname); #elif defined(CLIENT_write) errx(1, "Usage: %s [-h] key value [...]", progname); -#elif defined(CLIENT_rm) +#elif defined(CLIENT_rm) || defined(CLIENT_exists) || defined(CLIENT_list) errx(1, "Usage: %s [-h] key [...]", progname); #endif } @@ -33,8 +33,7 @@ main(int argc, char **argv) struct xs_handle *xsh; bool success; int ret = 0; -#if defined(CLIENT_read) - char *val; +#if defined(CLIENT_read) || defined(CLIENT_list) int prefix = 0; #endif @@ -46,14 +45,14 @@ main(int argc, char **argv) int c, index = 0; static struct option long_options[] = { {"help", 0, 0, 'h'}, -#if defined(CLIENT_read) +#if defined(CLIENT_read) || defined(CLIENT_list) {"prefix", 0, 0, 'p'}, #endif {0, 0, 0, 0} }; c = getopt_long(argc, argv, "h" -#if defined(CLIENT_read) +#if defined(CLIENT_read) || defined(CLIENT_list) "p" #endif , long_options, &index); @@ -64,7 +63,7 @@ main(int argc, char **argv) case 'h': usage(argv[0]); /* NOTREACHED */ -#if defined(CLIENT_read) +#if defined(CLIENT_read) || defined(CLIENT_list) case 'p': prefix = 1; break; @@ -90,7 +89,7 @@ main(int argc, char **argv) while (optind < argc) { #if defined(CLIENT_read) - val = xs_read(xsh, argv[optind], NULL); + char *val = xs_read(xsh, argv[optind], NULL); if (val == NULL) { warnx("couldn't read path %s", argv[optind]); ret = 1; @@ -118,6 +117,29 @@ main(int argc, char **argv) goto out; } optind++; +#elif defined(CLIENT_exists) + char *val = xs_read(xsh, argv[optind], NULL); + if (val == NULL) { + ret = 1; + goto out; + } + free(val); + optind++; +#elif defined(CLIENT_list) + unsigned int i, num; + char **list = xs_directory(xsh, argv[optind], &num); + if (list == NULL) { + warnx("could not list path %s", argv[optind]); + ret = 1; + goto out; + } + for (i = 0; i < num; i++) { + if (prefix) + printf("%s/", argv[optind]); + printf("%s\n", list[i]); + } + free(list); + optind++; #endif } |