aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xenstore
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2008-04-09 13:31:19 +0100
committerKeir Fraser <keir.fraser@citrix.com>2008-04-09 13:31:19 +0100
commitad2d0860f3055836c1e3b988ce2ed5d59e616b48 (patch)
treec671652b5e7975fd2ecc9f17a2b3eb794e014b27 /tools/xenstore
parent58b534c5d793826b1b3511dffc29e37853b5a08b (diff)
downloadxen-ad2d0860f3055836c1e3b988ce2ed5d59e616b48.tar.gz
xen-ad2d0860f3055836c1e3b988ce2ed5d59e616b48.tar.bz2
xen-ad2d0860f3055836c1e3b988ce2ed5d59e616b48.zip
xenstore: merge xenstore-ls into the multicall binary.
This is done separately from moving the other utilities into the mutlicall since ls is slightly different and was already separate. Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'tools/xenstore')
-rw-r--r--tools/xenstore/Makefile12
-rw-r--r--tools/xenstore/xenstore_client.c183
-rw-r--r--tools/xenstore/xsls.c171
3 files changed, 176 insertions, 190 deletions
diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index 6bfb1b6b6b..9b7e9e89c6 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -13,7 +13,7 @@ CFLAGS += -Wp,-MD,.$(@F).d
DEP = .*.d
CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm xenstore-chmod
-CLIENTS += xenstore-write
+CLIENTS += xenstore-write xenstore-ls
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
@@ -27,14 +27,14 @@ ifneq ($(XENSTORE_STATIC_CLIENTS),y)
LIBXENSTORE := libxenstore.so
else
LIBXENSTORE := libxenstore.a
-xenstore xenstore-control xenstore-ls: CFLAGS += -static
+xenstore xenstore-control: CFLAGS += -static
endif
.PHONY: all
all: libxenstore.so libxenstore.a xenstored clients xs_tdb_dump
.PHONY: clients
-clients: xenstore $(CLIENTS) xenstore-control xenstore-ls
+clients: xenstore $(CLIENTS) xenstore-control
ifeq ($(CONFIG_SunOS),y)
xenstored_probes.h: xenstored_probes.d
@@ -60,9 +60,6 @@ xenstore: xenstore_client.o $(LIBXENSTORE)
xenstore-control: xenstore_control.o $(LIBXENSTORE)
$(CC) $(CFLAGS) $(LDFLAGS) $< -L. -lxenstore $(SOCKET_LIBS) -o $@
-xenstore-ls: xsls.o $(LIBXENSTORE)
- $(CC) $(CFLAGS) $(LDFLAGS) $< -L. -lxenstore $(SOCKET_LIBS) -o $@
-
xs_tdb_dump: xs_tdb_dump.o utils.o tdb.o talloc.o
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
@@ -83,7 +80,7 @@ libxenstore.a: xs.o xs_lib.o
clean:
rm -f *.a *.o *.opic *.so* xenstored_probes.h
rm -f xenstored xs_random xs_stress xs_crashme
- rm -f xs_tdb_dump xenstore-control xenstore-ls
+ rm -f xs_tdb_dump xenstore-control
rm -f xenstore $(CLIENTS)
$(RM) $(DEP)
@@ -108,7 +105,6 @@ install: all
set -e ; for c in $(CLIENTS) ; do \
ln -f $(DESTDIR)/usr/bin/xenstore $(DESTDIR)/usr/bin/$${c} ; \
done
- $(INSTALL_PROG) xenstore-ls $(DESTDIR)$(BINDIR)
$(INSTALL_DIR) $(DESTDIR)$(LIBDIR)
$(INSTALL_PROG) libxenstore.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)
ln -sf libxenstore.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)/libxenstore.so.$(MAJOR)
diff --git a/tools/xenstore/xenstore_client.c b/tools/xenstore/xenstore_client.c
index 422fc231a4..dabf4f72a9 100644
--- a/tools/xenstore/xenstore_client.c
+++ b/tools/xenstore/xenstore_client.c
@@ -16,8 +16,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <termios.h>
+#include <unistd.h>
#include <xs.h>
+#include <sys/ioctl.h>
+
#define PATH_SEP '/'
#define MAX_PATH_LEN 256
@@ -28,6 +32,7 @@ enum mode {
MODE_chmod,
MODE_exists,
MODE_list,
+ MODE_ls,
MODE_read,
MODE_rm,
MODE_write,
@@ -84,6 +89,9 @@ usage(enum mode mode, int incl_mode, const char *progname)
case MODE_list:
mstr = mstr ? : incl_mode ? "list " : "";
errx(1, "Usage: %s %s[-h] [-s] key [...]", progname, mstr);
+ case MODE_ls:
+ mstr = mstr ? : incl_mode ? "ls " : "";
+ errx(1, "Usage: %s %s[-h] [-s] [path]", progname, mstr);
case MODE_chmod:
mstr = incl_mode ? "chmod " : "";
errx(1, "Usage: %s %s[-h] [-s] key <mode [modes...]>", progname, mstr);
@@ -103,6 +111,111 @@ do_rm(char *path, struct xs_handle *xsh, xs_transaction_t xth)
}
}
+#define STRING_MAX XENSTORE_ABS_PATH_MAX+1024
+static int max_width = 80;
+static int desired_width = 60;
+static int show_whole_path = 0;
+
+#define TAG " = \"...\""
+#define TAG_LEN strlen(TAG)
+
+#define MIN(a, b) (((a) < (b))? (a) : (b))
+
+void do_ls(struct xs_handle *h, char *path, int cur_depth, int show_perms)
+{
+ static struct expanding_buffer ebuf;
+ char **e;
+ char newpath[STRING_MAX], *val;
+ int newpath_len;
+ int i;
+ unsigned int num, len;
+
+ e = xs_directory(h, XBT_NULL, path, &num);
+ if (e == NULL)
+ err(1, "xs_directory (%s)", path);
+
+ for (i = 0; i<num; i++) {
+ char buf[MAX_STRLEN(unsigned int)+1];
+ struct xs_permissions *perms;
+ unsigned int nperms;
+ int linewid;
+
+ /* Compose fullpath */
+ newpath_len = snprintf(newpath, sizeof(newpath), "%s%s%s", path,
+ path[strlen(path)-1] == '/' ? "" : "/",
+ e[i]);
+
+ /* Print indent and path basename */
+ linewid = 0;
+ if (show_whole_path) {
+ fputs(newpath, stdout);
+ } else {
+ for (; linewid<cur_depth; linewid++) {
+ putchar(' ');
+ }
+ linewid += printf("%.*s",
+ (int) (max_width - TAG_LEN - linewid), e[i]);
+ }
+
+ /* Fetch value */
+ if ( newpath_len < sizeof(newpath) ) {
+ val = xs_read(h, XBT_NULL, newpath, &len);
+ }
+ else {
+ /* Path was truncated and thus invalid */
+ val = NULL;
+ len = 0;
+ }
+
+ /* Print value */
+ if (val == NULL) {
+ printf(":\n");
+ }
+ else {
+ if (max_width < (linewid + len + TAG_LEN)) {
+ printf(" = \"%.*s\\...\"",
+ (int)(max_width - TAG_LEN - linewid),
+ sanitise_value(&ebuf, val, len));
+ }
+ else {
+ linewid += printf(" = \"%s\"",
+ sanitise_value(&ebuf, val, len));
+ if (show_perms) {
+ putchar(' ');
+ for (linewid++;
+ linewid < MIN(desired_width, max_width);
+ linewid++)
+ putchar((linewid & 1)? '.' : ' ');
+ }
+ }
+ }
+ free(val);
+
+ if (show_perms) {
+ perms = xs_get_permissions(h, XBT_NULL, newpath, &nperms);
+ if (perms == NULL) {
+ warn("\ncould not access permissions for %s", e[i]);
+ }
+ else {
+ int i;
+ fputs(" (", stdout);
+ for (i = 0; i < nperms; i++) {
+ if (i)
+ putchar(',');
+ xs_perm_to_string(perms+i, buf, sizeof(buf));
+ fputs(buf, stdout);
+ }
+ putchar(')');
+ }
+ }
+
+ putchar('\n');
+
+ do_ls(h, newpath, cur_depth+1, show_perms);
+ }
+ free(e);
+}
+
static void
do_chmod(char *path, struct xs_permissions *perms, int nperms, int upto,
int recurse, struct xs_handle *xsh, xs_transaction_t xth)
@@ -154,6 +267,19 @@ 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)
{
+ switch (mode) {
+ case MODE_ls:
+ if (optind == argc)
+ {
+ optind=0;
+ argc=1;
+ argv[0] = "/";
+ }
+ break;
+ default:
+ break;
+ }
+
while (optind < argc) {
switch (mode) {
case MODE_unknown:
@@ -256,8 +382,13 @@ perform(enum mode mode, int optind, int argc, char **argv, struct xs_handle *xsh
output("%s\n", list[i]);
}
free(list);
- optind++;
- break;
+ optind++;
+ break;
+ }
+ case MODE_ls: {
+ do_ls(xsh, argv[optind], 0, prefix);
+ optind++;
+ break;
}
case MODE_chmod: {
struct xs_permissions perms[MAX_PERMS];
@@ -311,6 +442,8 @@ static enum mode lookup_mode(const char *m)
return MODE_exists;
else if (strcmp(m, "list") == 0)
return MODE_list;
+ else if (strcmp(m, "ls") == 0)
+ return MODE_ls;
else if (strcmp(m, "rm") == 0)
return MODE_rm;
else if (strcmp(m, "write") == 0)
@@ -332,6 +465,7 @@ main(int argc, char **argv)
int upto = 0;
int recurse = 0;
int transaction;
+ struct winsize ws;
enum mode mode;
const char *_command = strrchr(argv[0], '/');
@@ -365,7 +499,7 @@ main(int argc, char **argv)
{0, 0, 0, 0}
};
- c = getopt_long(argc - switch_argv, argv + switch_argv, "hsptur",
+ c = getopt_long(argc - switch_argv, argv + switch_argv, "fhsptur",
long_options, &index);
if (c == -1)
break;
@@ -374,11 +508,20 @@ main(int argc, char **argv)
case 'h':
usage(mode, switch_argv, argv[0]);
/* NOTREACHED */
+ case 'f':
+ if ( mode == MODE_read || mode == MODE_list || mode == MODE_ls ) {
+ max_width = INT_MAX/2;
+ desired_width = 0;
+ show_whole_path = 1;
+ } else {
+ usage(mode, switch_argv, argv[0]);
+ }
+ break;
case 's':
socket = 1;
break;
case 'p':
- if ( mode == MODE_read || mode == MODE_list )
+ if ( mode == MODE_read || mode == MODE_list || mode == MODE_ls )
prefix = 1;
else
usage(mode, switch_argv, argv[0]);
@@ -404,13 +547,20 @@ main(int argc, char **argv)
}
}
- if (optind == argc) {
- usage(mode, switch_argv, argv[0]);
- /* NOTREACHED */
- }
- if (mode == MODE_write && (argc - switch_argv - optind) % 2 == 1) {
- usage(mode, switch_argv, argv[0]);
- /* NOTREACHED */
+ switch (mode) {
+ case MODE_ls:
+ break;
+ case MODE_write:
+ if ((argc - switch_argv - optind) % 2 == 1) {
+ usage(mode, switch_argv, argv[0]);
+ /* NOTREACHED */
+ }
+ /* DROP-THRU */
+ default:
+ if (optind == argc - switch_argv) {
+ usage(mode, switch_argv, argv[0]);
+ /* NOTREACHED */
+ }
}
switch (mode) {
@@ -420,11 +570,22 @@ main(int argc, char **argv)
case MODE_write:
transaction = (argc - switch_argv - optind) > 2;
break;
+ case MODE_ls:
+ transaction = 0;
+ break;
default:
transaction = 1;
break;
}
+ if ( mode == MODE_ls )
+ {
+ memset(&ws, 0, sizeof(ws));
+ ret = ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
+ if (!ret)
+ max_width = ws.ws_col - 2;
+ }
+
xsh = socket ? xs_daemon_open() : xs_domain_open();
if (xsh == NULL)
err(1, socket ? "xs_daemon_open" : "xs_domain_open");
diff --git a/tools/xenstore/xsls.c b/tools/xenstore/xsls.c
deleted file mode 100644
index 337e87cc5b..0000000000
--- a/tools/xenstore/xsls.c
+++ /dev/null
@@ -1,171 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <err.h>
-#include <xs.h>
-#include <getopt.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <termios.h>
-
-#define STRING_MAX XENSTORE_ABS_PATH_MAX+1024
-static int max_width = 80;
-static int desired_width = 60;
-static int show_whole_path = 0;
-
-#define TAG " = \"...\""
-#define TAG_LEN strlen(TAG)
-
-#define MIN(a, b) (((a) < (b))? (a) : (b))
-
-void print_dir(struct xs_handle *h, char *path, int cur_depth, int show_perms)
-{
- static struct expanding_buffer ebuf;
- char **e;
- char newpath[STRING_MAX], *val;
- int newpath_len;
- int i;
- unsigned int num, len;
-
- e = xs_directory(h, XBT_NULL, path, &num);
- if (e == NULL)
- err(1, "xs_directory (%s)", path);
-
- for (i = 0; i<num; i++) {
- char buf[MAX_STRLEN(unsigned int)+1];
- struct xs_permissions *perms;
- unsigned int nperms;
- int linewid;
-
- /* Compose fullpath */
- newpath_len = snprintf(newpath, sizeof(newpath), "%s%s%s", path,
- path[strlen(path)-1] == '/' ? "" : "/",
- e[i]);
-
- /* Print indent and path basename */
- linewid = 0;
- if (show_whole_path) {
- fputs(newpath, stdout);
- } else {
- for (; linewid<cur_depth; linewid++) {
- putchar(' ');
- }
- linewid += printf("%.*s",
- (int) (max_width - TAG_LEN - linewid), e[i]);
- }
-
- /* Fetch value */
- if ( newpath_len < sizeof(newpath) ) {
- val = xs_read(h, XBT_NULL, newpath, &len);
- }
- else {
- /* Path was truncated and thus invalid */
- val = NULL;
- len = 0;
- }
-
- /* Print value */
- if (val == NULL) {
- printf(":\n");
- }
- else {
- if (max_width < (linewid + len + TAG_LEN)) {
- printf(" = \"%.*s\\...\"",
- (int)(max_width - TAG_LEN - linewid),
- sanitise_value(&ebuf, val, len));
- }
- else {
- linewid += printf(" = \"%s\"",
- sanitise_value(&ebuf, val, len));
- if (show_perms) {
- putchar(' ');
- for (linewid++;
- linewid < MIN(desired_width, max_width);
- linewid++)
- putchar((linewid & 1)? '.' : ' ');
- }
- }
- }
- free(val);
-
- if (show_perms) {
- perms = xs_get_permissions(h, XBT_NULL, newpath, &nperms);
- if (perms == NULL) {
- warn("\ncould not access permissions for %s", e[i]);
- }
- else {
- int i;
- fputs(" (", stdout);
- for (i = 0; i < nperms; i++) {
- if (i)
- putchar(',');
- xs_perm_to_string(perms+i, buf, sizeof(buf));
- fputs(buf, stdout);
- }
- putchar(')');
- }
- }
-
- putchar('\n');
-
- print_dir(h, newpath, cur_depth+1, show_perms);
- }
- free(e);
-}
-
-void usage(int argc, char *argv[])
-{
- fprintf(stderr, "Usage: %s [-w] [-p] [-f] [-s] [path]\n", argv[0]);
-}
-
-int main(int argc, char *argv[])
-{
- struct winsize ws;
- int ret, c, socket = 0, show_perm = 0;
- struct xs_handle *xsh;
-
-#define PAD 2
-
- memset(&ws, 0, sizeof(ws));
- ret = ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
- if (!ret)
- max_width = ws.ws_col - PAD;
-
- while (0 < (c = getopt(argc, argv, "pswf"))) {
- switch (c) {
- case 'w':
- max_width= STRING_MAX - PAD;
- desired_width = 0;
- break;
- case 'p':
- show_perm = 1;
- break;
- case 's':
- socket = 1;
- break;
- case 'f':
- max_width = INT_MAX/2;
- desired_width = 0;
- show_whole_path = 1;
- break;
- case ':':
- case '?':
- default:
- usage(argc, argv);
- return 0;
- }
- }
-
- /* Adjust the width here to avoid argument order dependency */
- if ( show_perm ) {
- max_width -= 16;
- }
-
- xsh = socket ? xs_daemon_open() : xs_domain_open();
- if (xsh == NULL)
- err(1, socket ? "xs_daemon_open" : "xs_domain_open");
-
- print_dir(xsh, (argc - optind) == 1 ? argv[optind] : "/", 0, show_perm);
-
- return 0;
-}