ia64/xen-unstable

view tools/xenstore/xsls.c @ 8740:3d7ea7972b39

Update patches for linux 2.6.15.

Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Thu Feb 02 17:16:00 2006 +0000 (2006-02-02)
parents 991ccc24bf2e
children 153e69eae665
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <err.h>
5 #include <xs.h>
7 void print_dir(struct xs_handle *h, char *path, int cur_depth)
8 {
9 char **e;
10 char newpath[512], *val;
11 int i;
12 unsigned int num, len;
14 e = xs_directory(h, XBT_NULL, path, &num);
15 if (e == NULL)
16 err(1, "xs_directory (%s)", path);
18 for (i = 0; i<num; i++) {
19 int j;
20 for (j=0; j<cur_depth; j++) printf(" ");
21 printf("%s", e[i]);
22 sprintf(newpath, "%s%s%s", path,
23 path[strlen(path)-1] == '/' ? "" : "/",
24 e[i]);
25 val = xs_read(h, XBT_NULL, newpath, &len);
26 if (val == NULL)
27 printf(":\n");
28 else if ((unsigned)len > (151 - strlen(e[i])))
29 printf(" = \"%.*s...\"\n", (int)(148 - strlen(e[i])), val);
30 else
31 printf(" = \"%s\"\n", val);
32 free(val);
33 print_dir(h, newpath, cur_depth+1);
34 }
35 free(e);
36 }
38 int main(int argc, char *argv[])
39 {
40 struct xs_handle *xsh = xs_daemon_open();
42 if (xsh == NULL)
43 err(1, "xs_daemon_open");
45 print_dir(xsh, argc == 1 ? "/" : argv[1], 0);
47 return 0;
48 }