--- 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 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; }