WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] xenstore-ls -f for find(1)-like output

To: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] xenstore-ls -f for find(1)-like output
From: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Date: Mon, 3 Dec 2007 15:42:25 +0000
Delivery-date: Mon, 03 Dec 2007 07:43:43 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
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
<Prev in Thread] Current Thread [Next in Thread>