debuggers.hg
changeset 16571:b6fb8b4dc261
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>
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>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Wed Dec 05 11:07:12 2007 +0000 (2007-12-05) |
parents | b47849b774f1 |
children | 671ef298d491 |
files | tools/xenstore/xsls.c |
line diff
1.1 --- a/tools/xenstore/xsls.c Wed Dec 05 11:05:47 2007 +0000 1.2 +++ b/tools/xenstore/xsls.c Wed Dec 05 11:07:12 2007 +0000 1.3 @@ -11,6 +11,7 @@ 1.4 #define STRING_MAX PATH_MAX 1.5 static int max_width = 80; 1.6 static int desired_width = 60; 1.7 +static int show_whole_path = 0; 1.8 1.9 #define TAG " = \"...\"" 1.10 #define TAG_LEN strlen(TAG) 1.11 @@ -36,23 +37,31 @@ void print_dir(struct xs_handle *h, char 1.12 unsigned int nperms; 1.13 int linewid; 1.14 1.15 - /* Print indent and path basename */ 1.16 - for (linewid=0; linewid<cur_depth; linewid++) { 1.17 - putchar(' '); 1.18 - } 1.19 - linewid += printf("%.*s", 1.20 - (int) (max_width - TAG_LEN - linewid), e[i]); 1.21 - 1.22 - /* Compose fullpath and fetch value */ 1.23 + /* Compose fullpath */ 1.24 newpath_len = snprintf(newpath, sizeof(newpath), "%s%s%s", path, 1.25 path[strlen(path)-1] == '/' ? "" : "/", 1.26 e[i]); 1.27 + 1.28 + /* Print indent and path basename */ 1.29 + linewid = 0; 1.30 + if (show_whole_path) { 1.31 + fputs(newpath, stdout); 1.32 + } else { 1.33 + for (; linewid<cur_depth; linewid++) { 1.34 + putchar(' '); 1.35 + } 1.36 + linewid += printf("%.*s", 1.37 + (int) (max_width - TAG_LEN - linewid), e[i]); 1.38 + } 1.39 + 1.40 + /* Fetch value */ 1.41 if ( newpath_len < sizeof(newpath) ) { 1.42 val = xs_read(h, XBT_NULL, newpath, &len); 1.43 } 1.44 else { 1.45 /* Path was truncated and thus invalid */ 1.46 val = NULL; 1.47 + len = 0; 1.48 } 1.49 1.50 /* Print value */ 1.51 @@ -106,7 +115,7 @@ void print_dir(struct xs_handle *h, char 1.52 1.53 void usage(int argc, char *argv[]) 1.54 { 1.55 - fprintf(stderr, "Usage: %s [-w] [-p] [path]\n", argv[0]); 1.56 + fprintf(stderr, "Usage: %s [-w] [-p] [-f] [-s] [path]\n", argv[0]); 1.57 } 1.58 1.59 int main(int argc, char *argv[]) 1.60 @@ -122,7 +131,7 @@ int main(int argc, char *argv[]) 1.61 if (!ret) 1.62 max_width = ws.ws_col - PAD; 1.63 1.64 - while (0 < (c = getopt(argc, argv, "psw"))) { 1.65 + while (0 < (c = getopt(argc, argv, "pswf"))) { 1.66 switch (c) { 1.67 case 'w': 1.68 max_width= STRING_MAX - PAD; 1.69 @@ -134,6 +143,11 @@ int main(int argc, char *argv[]) 1.70 case 's': 1.71 socket = 1; 1.72 break; 1.73 + case 'f': 1.74 + max_width = INT_MAX/2; 1.75 + desired_width = 0; 1.76 + show_whole_path = 1; 1.77 + break; 1.78 case ':': 1.79 case '?': 1.80 default: