ia64/xen-unstable

changeset 6768:282d5698ea40

Add xenstore-list and xenstore-exists clients
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Mon Sep 12 20:46:37 2005 +0000 (2005-09-12)
parents d22091179975
children 80afc502461b
files tools/xenstore/Makefile tools/xenstore/xenstore_client.c
line diff
     1.1 --- a/tools/xenstore/Makefile	Mon Sep 12 20:24:58 2005 +0000
     1.2 +++ b/tools/xenstore/Makefile	Mon Sep 12 20:46:37 2005 +0000
     1.3 @@ -25,7 +25,8 @@ TESTDIR  = `pwd`/testsuite/tmp
     1.4  TESTFLAGS= -DTESTING
     1.5  TESTENV  = XENSTORED_ROOTDIR=$(TESTDIR) XENSTORED_RUNDIR=$(TESTDIR)
     1.6  
     1.7 -CLIENTS := xenstore-read xenstore-rm xenstore-write
     1.8 +CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm
     1.9 +CLIENTS += xenstore-write
    1.10  CLIENTS_OBJS := $(patsubst xenstore-%,xenstore_%.o,$(CLIENTS))
    1.11  
    1.12  all: libxenstore.so xenstored $(CLIENTS)
     2.1 --- a/tools/xenstore/xenstore_client.c	Mon Sep 12 20:24:58 2005 +0000
     2.2 +++ b/tools/xenstore/xenstore_client.c	Mon Sep 12 20:46:37 2005 +0000
     2.3 @@ -22,7 +22,7 @@ usage(const char *progname)
     2.4      errx(1, "Usage: %s [-h] [-p] key [...]", progname);
     2.5  #elif defined(CLIENT_write)
     2.6      errx(1, "Usage: %s [-h] key value [...]", progname);
     2.7 -#elif defined(CLIENT_rm)
     2.8 +#elif defined(CLIENT_rm) || defined(CLIENT_exists) || defined(CLIENT_list)
     2.9      errx(1, "Usage: %s [-h] key [...]", progname);
    2.10  #endif
    2.11  }
    2.12 @@ -33,8 +33,7 @@ main(int argc, char **argv)
    2.13      struct xs_handle *xsh;
    2.14      bool success;
    2.15      int ret = 0;
    2.16 -#if defined(CLIENT_read)
    2.17 -    char *val;
    2.18 +#if defined(CLIENT_read) || defined(CLIENT_list)
    2.19      int prefix = 0;
    2.20  #endif
    2.21  
    2.22 @@ -46,14 +45,14 @@ main(int argc, char **argv)
    2.23  	int c, index = 0;
    2.24  	static struct option long_options[] = {
    2.25  	    {"help", 0, 0, 'h'},
    2.26 -#if defined(CLIENT_read)
    2.27 +#if defined(CLIENT_read) || defined(CLIENT_list)
    2.28  	    {"prefix", 0, 0, 'p'},
    2.29  #endif
    2.30  	    {0, 0, 0, 0}
    2.31  	};
    2.32  
    2.33  	c = getopt_long(argc, argv, "h"
    2.34 -#if defined(CLIENT_read)
    2.35 +#if defined(CLIENT_read) || defined(CLIENT_list)
    2.36  			"p"
    2.37  #endif
    2.38  			, long_options, &index);
    2.39 @@ -64,7 +63,7 @@ main(int argc, char **argv)
    2.40  	case 'h':
    2.41  	    usage(argv[0]);
    2.42  	    /* NOTREACHED */
    2.43 -#if defined(CLIENT_read)
    2.44 +#if defined(CLIENT_read) || defined(CLIENT_list)
    2.45  	case 'p':
    2.46  	    prefix = 1;
    2.47  	    break;
    2.48 @@ -90,7 +89,7 @@ main(int argc, char **argv)
    2.49  
    2.50      while (optind < argc) {
    2.51  #if defined(CLIENT_read)
    2.52 -	val = xs_read(xsh, argv[optind], NULL);
    2.53 +	char *val = xs_read(xsh, argv[optind], NULL);
    2.54  	if (val == NULL) {
    2.55  	    warnx("couldn't read path %s", argv[optind]);
    2.56  	    ret = 1;
    2.57 @@ -118,6 +117,29 @@ main(int argc, char **argv)
    2.58  	    goto out;
    2.59  	}
    2.60  	optind++;
    2.61 +#elif defined(CLIENT_exists)
    2.62 +	char *val = xs_read(xsh, argv[optind], NULL);
    2.63 +	if (val == NULL) {
    2.64 +	    ret = 1;
    2.65 +	    goto out;
    2.66 +	}
    2.67 +	free(val);
    2.68 +	optind++;
    2.69 +#elif defined(CLIENT_list)
    2.70 +	unsigned int i, num;
    2.71 +	char **list = xs_directory(xsh, argv[optind], &num);
    2.72 +	if (list == NULL) {
    2.73 +	    warnx("could not list path %s", argv[optind]);
    2.74 +	    ret = 1;
    2.75 +	    goto out;
    2.76 +	}
    2.77 +	for (i = 0; i < num; i++) {
    2.78 +	    if (prefix)
    2.79 +		printf("%s/", argv[optind]);
    2.80 +	    printf("%s\n", list[i]);
    2.81 +	}
    2.82 +	free(list);
    2.83 +	optind++;
    2.84  #endif
    2.85      }
    2.86