diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2007-12-05 11:07:12 +0000 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2007-12-05 11:07:12 +0000 |
commit | 1bb3512f969b20f229cdc092e94afab888dac317 (patch) | |
tree | 1423a8f92333a8da1e3d935fb439368bdf5e4d10 /tools/xenstore | |
parent | dd36792405db37a70f76b7df23e2463499f21d9a (diff) | |
download | xen-1bb3512f969b20f229cdc092e94afab888dac317.tar.gz xen-1bb3512f969b20f229cdc092e94afab888dac317.tar.bz2 xen-1bb3512f969b20f229cdc092e94afab888dac317.zip |
xenstore-ls -f for find(1)-like output
The current output of xenstore-ls can be quite hard to read and it is
not very intractable for postprocessing with sort|diff and the like.
The patch below provides a -f option which produces output with the
full key pathname on each line, and which disables the value
truncation and the `.'-padding when used with -p (since these latter
two aren't likely to be very useful when values are preceded by long
pathnames).
While I was at it I added the `-s' option to the usage message, where
it was previously missing.
The results looks like this:
...
/local/domain/1 = ""
/local/domain/1/vm = "/vm/8b5fd34a-e268-fab5-9cde-c06eda21df16"
/local/domain/1/device = ""
/local/domain/1/device/vbd = ""
/local/domain/1/device/vbd/2049 = ""
/local/domain/1/device/vbd/2049/virtual-device = "2049"
/local/domain/1/device/vbd/2049/device-type = "disk"
/local/domain/1/device/vbd/2049/protocol = "x86_32-abi"
...
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools/xenstore')
-rw-r--r-- | tools/xenstore/xsls.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/tools/xenstore/xsls.c b/tools/xenstore/xsls.c index 061feebd57..cd8e3a9dac 100644 --- a/tools/xenstore/xsls.c +++ b/tools/xenstore/xsls.c @@ -11,6 +11,7 @@ #define STRING_MAX PATH_MAX static int max_width = 80; static int desired_width = 60; +static int show_whole_path = 0; #define TAG " = \"...\"" #define TAG_LEN strlen(TAG) @@ -36,23 +37,31 @@ void print_dir(struct xs_handle *h, char *path, int cur_depth, int show_perms) unsigned int nperms; int linewid; - /* Print indent and path basename */ - for (linewid=0; linewid<cur_depth; linewid++) { - putchar(' '); - } - linewid += printf("%.*s", - (int) (max_width - TAG_LEN - linewid), e[i]); - - /* Compose fullpath and fetch value */ + /* 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 */ @@ -106,7 +115,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 [-w] [-p] [path]\n", argv[0]); + fprintf(stderr, "Usage: %s [-w] [-p] [-f] [-s] [path]\n", argv[0]); } int main(int argc, char *argv[]) @@ -122,7 +131,7 @@ int main(int argc, char *argv[]) if (!ret) max_width = ws.ws_col - PAD; - while (0 < (c = getopt(argc, argv, "psw"))) { + while (0 < (c = getopt(argc, argv, "pswf"))) { switch (c) { case 'w': max_width= STRING_MAX - PAD; @@ -134,6 +143,11 @@ int main(int argc, char *argv[]) case 's': socket = 1; break; + case 'f': + max_width = INT_MAX/2; + desired_width = 0; + show_whole_path = 1; + break; case ':': case '?': default: |