# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1207744279 -3600
# Node ID b982ab47285e12b007222e8cd05cab95af2984cf
# Parent 7259de99f7fdbf3f2bcd2943e9776b29da0299b5
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@xxxxxxxxxx>
---
tools/xenstore/xsls.c | 171 ------------------------------------
tools/xenstore/Makefile | 12 --
tools/xenstore/xenstore_client.c | 183 ++++++++++++++++++++++++++++++++++++---
3 files changed, 176 insertions(+), 190 deletions(-)
diff -r 7259de99f7fd -r b982ab47285e tools/xenstore/Makefile
--- a/tools/xenstore/Makefile Wed Apr 09 13:30:37 2008 +0100
+++ b/tools/xenstore/Makefile Wed Apr 09 13:31:19 2008 +0100
@@ -13,7 +13,7 @@ DEP = .*.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 @@ LIBXENSTORE := libxenstore.so
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-control: xenstore_control.o $(L
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 @@ clean:
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 -r 7259de99f7fd -r b982ab47285e tools/xenstore/xenstore_client.c
--- a/tools/xenstore/xenstore_client.c Wed Apr 09 13:30:37 2008 +0100
+++ b/tools/xenstore/xenstore_client.c Wed Apr 09 13:31:19 2008 +0100
@@ -16,7 +16,11 @@
#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, con
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);
@@ -101,6 +109,111 @@ do_rm(char *path, struct xs_handle *xsh,
warnx("could not remove path %s", path);
return 1;
}
+}
+
+#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
@@ -154,6 +267,19 @@ perform(enum mode mode, int optind, 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
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
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,9 +570,20 @@ 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();
diff -r 7259de99f7fd -r b982ab47285e tools/xenstore/xsls.c
--- a/tools/xenstore/xsls.c Wed Apr 09 13:30:37 2008 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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;
-}
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|