diff options
author | kfraser@localhost.localdomain <kfraser@localhost.localdomain> | 2007-07-11 10:52:19 +0100 |
---|---|---|
committer | kfraser@localhost.localdomain <kfraser@localhost.localdomain> | 2007-07-11 10:52:19 +0100 |
commit | ae9db74d17a7aec713bfcc152e8a631befb44783 (patch) | |
tree | 6f98fe2f7db6efb9ad6b3bff74ec889d71190183 /tools/xenstore | |
parent | d7839765dc724623b6c5d23a1416599ab1c2c7c7 (diff) | |
download | xen-ae9db74d17a7aec713bfcc152e8a631befb44783.tar.gz xen-ae9db74d17a7aec713bfcc152e8a631befb44783.tar.bz2 xen-ae9db74d17a7aec713bfcc152e8a631befb44783.zip |
[xenstore] adds a -w (wide) flag to xenstore-ls to support seeing full
contents of xenstore entries. There is a bit of code cleanup as well
(snprintf vs. sprintf), one formatting fix, and comments).
There is no change to the behavior of xenstore-ls without -w.
Signed-off-by: John Zulauf <john.zulauf@intel.com>
Diffstat (limited to 'tools/xenstore')
-rw-r--r-- | tools/xenstore/xsls.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/tools/xenstore/xsls.c b/tools/xenstore/xsls.c index cf5ff6e7e6..c9e41ef64e 100644 --- a/tools/xenstore/xsls.c +++ b/tools/xenstore/xsls.c @@ -8,6 +8,7 @@ #include <sys/ioctl.h> #include <termios.h> +#define STRING_MAX PATH_MAX static int max_width = 80; static int desired_width = 60; @@ -19,7 +20,8 @@ static int desired_width = 60; void print_dir(struct xs_handle *h, char *path, int cur_depth, int show_perms) { char **e; - char newpath[512], *val; + char newpath[STRING_MAX], *val; + int newpath_len; int i; unsigned int num, len; @@ -33,13 +35,26 @@ void print_dir(struct xs_handle *h, char *path, int cur_depth, int show_perms) unsigned int nperms; int linewid; - for (linewid=0; linewid<cur_depth; linewid++) putchar(' '); + /* Print indent and path basename */ + for (linewid=0; linewid<cur_depth; linewid++) { + putchar(' '); + } linewid += printf("%.*s", (int) (max_width - TAG_LEN - linewid), e[i]); - sprintf(newpath, "%s%s%s", path, + + /* Compose fullpath and fetch value */ + newpath_len = snprintf(newpath, sizeof(newpath), "%s%s%s", path, path[strlen(path)-1] == '/' ? "" : "/", e[i]); - val = xs_read(h, XBT_NULL, newpath, &len); + if ( newpath_len < sizeof(newpath) ) { + val = xs_read(h, XBT_NULL, newpath, &len); + } + else { + /* Path was truncated and thus invalid */ + val = NULL; + } + + /* Print value */ if (val == NULL) { printf(":\n"); } @@ -88,7 +103,7 @@ void print_dir(struct xs_handle *h, char *path, int cur_depth, int show_perms) void usage(int argc, char *argv[]) { - fprintf(stderr, "Usage: %s [-p] [path]\n", argv[0]); + fprintf(stderr, "Usage: %s [-w] [-p] [path]\n", argv[0]); } int main(int argc, char *argv[]) @@ -104,11 +119,14 @@ int main(int argc, char *argv[]) if (!ret) max_width = ws.ws_col - PAD; - while (0 < (c = getopt(argc, argv, "ps"))) { + while (0 < (c = getopt(argc, argv, "psw"))) { switch (c) { + case 'w': + max_width= STRING_MAX - PAD; + desired_width = 0; + break; case 'p': show_perm = 1; - max_width -= 16; break; case 's': socket = 1; @@ -121,6 +139,11 @@ int main(int argc, char *argv[]) } } + /* 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"); |