From: David Woodhouse <dwmw2@infradead.org>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>,
Ian Jackson <ian.jackson@eu.citrix.com>, Wei Liu <wl@xen.org>
Subject: [Xen-devel] [PATCH 2/2] tools/xenstore: Accumulate errors in xenstore-ls and exit appropriately
Date: Thu, 19 Mar 2020 20:40:25 +0000 [thread overview]
Message-ID: <20200319204025.2649661-2-dwmw2@infradead.org> (raw)
In-Reply-To: <20200319204025.2649661-1-dwmw2@infradead.org>
From: David Woodhouse <dwmw@amazon.co.uk>
Report only one error to stderr for each node, regardless of whether it's
xs_read, xs_get_permissions or xs_directory on the child that fails.
Always exit with a non-zero code if any failure happens, reporting the
last error that occurred.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
tools/xenstore/xenstore_client.c | 35 ++++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 9 deletions(-)
diff --git a/tools/xenstore/xenstore_client.c b/tools/xenstore/xenstore_client.c
index ae7ed3eb9e..0c891961ae 100644
--- a/tools/xenstore/xenstore_client.c
+++ b/tools/xenstore/xenstore_client.c
@@ -140,7 +140,7 @@ static int show_whole_path = 0;
#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 int do_ls(struct xs_handle *h, char *path, int cur_depth, int show_perms, int error, int ignore_errors)
{
char **e;
char *newpath, *val;
@@ -150,9 +150,16 @@ static void do_ls(struct xs_handle *h, char *path, int cur_depth, int show_perms
e = xs_directory(h, XBT_NULL, path, &num);
if (e == NULL) {
- if (cur_depth && errno == ENOENT) {
- /* If a node disappears while recursing, silently move on. */
- return;
+ if (cur_depth && (errno == ENOENT || errno == EACCES)) {
+ /*
+ * If a node disappears or becomes inaccessible while traversing,
+ * only print an error if previous operations on this node haven't
+ * done do. Then move on.
+ */
+ error = errno;
+ if (!ignore_errors)
+ warn("xs_directory (%s)", path);
+ return error;
}
err(1, "xs_directory (%s)", path);
@@ -197,7 +204,8 @@ static void do_ls(struct xs_handle *h, char *path, int cur_depth, int show_perms
/* Print value */
if (val == NULL) {
- printf(":\n");
+ error = errno;
+ printf(": (%s)", strerror(error));
}
else {
if (max_width < (linewid + len + TAG_LEN)) {
@@ -222,7 +230,11 @@ static void do_ls(struct xs_handle *h, char *path, int cur_depth, int show_perms
if (show_perms) {
perms = xs_get_permissions(h, XBT_NULL, newpath, &nperms);
if (perms == NULL) {
- warn("\ncould not access permissions for %s", e[i]);
+ error = errno;
+ val = NULL;
+ /* Don't repeat an error message if xs_read() already failed */
+ if (val)
+ warn("could not access permissions for %s", e[i]);
}
else {
int i;
@@ -238,11 +250,13 @@ static void do_ls(struct xs_handle *h, char *path, int cur_depth, int show_perms
}
putchar('\n');
-
- do_ls(h, newpath, cur_depth+1, show_perms);
+
+ error = do_ls(h, newpath, cur_depth+1, show_perms, error, !val);
}
free(e);
free(newpath);
+
+ return error;
}
static void
@@ -448,7 +462,10 @@ perform(enum mode mode, int optind, int argc, char **argv, struct xs_handle *xsh
break;
}
case MODE_ls: {
- do_ls(xsh, argv[optind], 0, prefix);
+ int error = do_ls(xsh, argv[optind], 0, prefix, 0, 0);
+ if (error) {
+ errx(1, "Errors during traversal. Last error: %s", strerror(error));
+ }
optind++;
break;
}
--
2.21.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2020-03-19 20:41 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-19 20:40 [Xen-devel] [PATCH 1/2] tools/xenstore: Do not abort xenstore-ls if a node disappears while iterating David Woodhouse
2020-03-19 20:40 ` David Woodhouse [this message]
2020-03-20 11:03 ` [Xen-devel] [PATCH 2/2] tools/xenstore: Accumulate errors in xenstore-ls and exit appropriately Paul Durrant
2020-03-20 12:30 ` David Woodhouse
2020-03-20 14:36 ` [Xen-devel] [PATCH 2/2] tools/xenstore: Accumulate errors in xenstore-ls and exit appropriately [and 1 more messages] Ian Jackson
2020-03-20 6:34 ` [Xen-devel] [PATCH 1/2] tools/xenstore: Do not abort xenstore-ls if a node disappears while iterating Jürgen Groß
2020-03-20 11:19 ` David Woodhouse
2020-03-20 11:26 ` Jürgen Groß
2020-03-20 14:12 ` Ian Jackson
2020-03-20 14:58 ` David Woodhouse
2020-03-20 15:23 ` Jürgen Groß
2020-03-30 16:37 ` Ian Jackson
2020-03-30 16:40 ` Ian Jackson
2020-08-14 14:23 ` David Woodhouse
2020-08-14 15:19 ` Wei Liu
2020-03-20 14:11 ` Ian Jackson
2020-03-20 14:12 ` Jürgen Groß
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200319204025.2649661-2-dwmw2@infradead.org \
--to=dwmw2@infradead.org \
--cc=ian.jackson@eu.citrix.com \
--cc=jgross@suse.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).