aboutsummaryrefslogtreecommitdiffstats
path: root/main/xen/xenstore_client_transaction_fix.patch
blob: 134fc7fa663b887383a46a4abbb604b8260af728 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
--- xen-4.7.0-orig/tools/xenstore/xenstore_client.c	2016-06-20 12:38:15.000000000 +0200
+++ xen-4.7.0/tools/xenstore/xenstore_client.c	2016-10-05 03:16:39.372927512 +0200
@@ -126,7 +126,7 @@
 
 #define MIN(a, b) (((a) < (b))? (a) : (b))
 
-static void do_ls(struct xs_handle *h, char *path, int cur_depth, int show_perms)
+static void do_ls(struct xs_handle *h, xs_transaction_t xth, char *path, int cur_depth, int show_perms)
 {
     char **e;
     char *newpath, *val;
@@ -135,12 +135,14 @@
     unsigned int num, len;
 
     newpath = malloc(STRING_MAX);
-    if (!newpath)
+    if (!newpath) {
       err(1, "malloc in do_ls");
+    }
 
-    e = xs_directory(h, XBT_NULL, path, &num);
-    if (e == NULL)
+    e = xs_directory(h, xth, path, &num);
+    if (e == NULL) {
         err(1, "xs_directory (%s)", path);
+    }
 
     for (i = 0; i<num; i++) {
         char buf[MAX_STRLEN(unsigned int)+1];
@@ -167,7 +169,7 @@
 
 	/* Fetch value */
         if ( newpath_len < STRING_MAX ) {
-            val = xs_read(h, XBT_NULL, newpath, &len);
+            val = xs_read(h, xth, newpath, &len);
         }
         else {
             /* Path was truncated and thus invalid */
@@ -200,7 +202,7 @@
         free(val);
 
         if (show_perms) {
-            perms = xs_get_permissions(h, XBT_NULL, newpath, &nperms);
+            perms = xs_get_permissions(h, xth, newpath, &nperms);
             if (perms == NULL) {
                 warn("\ncould not access permissions for %s", e[i]);
             }
@@ -219,7 +221,7 @@
 
         putchar('\n');
             
-        do_ls(h, newpath, cur_depth+1, show_perms); 
+        do_ls(h, xth, newpath, cur_depth+1, show_perms);
     }
     free(e);
     free(newpath);
@@ -417,7 +419,7 @@
             break;
         }
         case MODE_ls: {
-            do_ls(xsh, argv[optind], 0, prefix);
+	        do_ls(xsh, xth, argv[optind], 0, prefix);
             optind++;
             break;
         }
@@ -505,7 +507,6 @@
     int upto = 0;
     int recurse = 0;
     int nr_watches = -1;
-    int transaction;
     struct winsize ws;
     enum mode mode;
 
@@ -612,43 +613,28 @@
 	}
     }
 
-    switch (mode) {
-    case MODE_read:
-	transaction = (argc - switch_argv - optind) > 1;
-	break;
-    case MODE_write:
-	transaction = (argc - switch_argv - optind) > 2;
-	break;
-    case MODE_ls:
-    case MODE_watch:
-	transaction = 0;
-	break;
-    default:
-	transaction = 1;
-	break;
-    }
-
-    if ( mode == MODE_ls )
-    {
+    if ( mode == MODE_ls ) {
 	memset(&ws, 0, sizeof(ws));
 	ret = ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
-	if (!ret)
+	if (!ret) {
 	    max_width = ws.ws_col - 2;
     }
+    }
 
     xsh = xs_open(socket ? XS_OPEN_SOCKETONLY : 0);
-    if (xsh == NULL) err(1, "xs_open");
+    if (xsh == NULL) {
+	    err(1, "xs_open");
+    }
 
 again:
-    if (transaction) {
 	xth = xs_transaction_start(xsh);
-	if (xth == XBT_NULL)
+    if (xth == XBT_NULL) {
 	    errx(1, "couldn't start transaction");
     }
 
     ret = perform(mode, optind, argc - switch_argv, argv + switch_argv, xsh, xth, prefix, tidy, upto, recurse, nr_watches);
 
-    if (transaction && !xs_transaction_end(xsh, xth, ret)) {
+    if (!xs_transaction_end(xsh, xth, ret)) {
 	if (ret == 0 && errno == EAGAIN) {
 	    output_pos = 0;
 	    goto again;
@@ -656,14 +642,16 @@
 	errx(1, "couldn't end transaction");
     }
 
-    if (output_pos)
+    if (output_pos) {
 	printf("%s", output_buf);
+    }
 
     free(output_buf);
     free(ebuf.buf);
 
-    if (xsh)
+    if (xsh) {
         xs_close(xsh);
+    }
 
     return ret;
 }