[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] 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" ... Ian. Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> diff -r 6e9ee9b86661 tools/xenstore/xsls.c --- a/tools/xenstore/xsls.c Fri Nov 30 15:03:30 2007 +0000 +++ b/tools/xenstore/xsls.c Mon Dec 03 12:16:31 2007 +0000 @@ -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) @@ -35,23 +37,31 @@ void print_dir(struct xs_handle *h, char 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 */ @@ -103,7 +115,7 @@ void print_dir(struct xs_handle *h, char 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[]) @@ -119,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; @@ -130,6 +142,11 @@ int main(int argc, char *argv[]) break; case 's': socket = 1; + break; + case 'f': + max_width = INT_MAX/2; + desired_width = 0; + show_whole_path = 1; break; case ':': case '?': _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |