[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen master] tools/xenstore: introduce get_node_const()
commit dc45c3e8de1dd23e31e99c3752f293232316da86 Author: Juergen Gross <jgross@xxxxxxxx> AuthorDate: Mon Aug 14 09:47:05 2023 +0200 Commit: Julien Grall <jgrall@xxxxxxxxxx> CommitDate: Fri Aug 18 13:49:50 2023 +0100 tools/xenstore: introduce get_node_const() Add a variant of get_node() returning a const struct node pointer. Note that all callers of this new variant don't supply a pointer where to store the canonical node name, while all callers needing a non-const node do supply this pointer. This results in an asymmetric simplification of the two variants. Signed-off-by: Juergen Gross <jgross@xxxxxxxx> Reviewed-by: Julien Grall <jgrall@xxxxxxxxxx> --- tools/xenstore/xenstored_core.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c index 9098b7eee2..7de4df2f28 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -1301,11 +1301,8 @@ static struct node *get_node(struct connection *conn, const void *ctx, const char *name, const char **canonical_name, unsigned int perm, bool allow_special) { - const char *tmp_name; struct node *node; - if (!canonical_name) - canonical_name = &tmp_name; *canonical_name = canonicalize(conn, ctx, name, allow_special); if (!*canonical_name) return NULL; @@ -1316,12 +1313,28 @@ static struct node *get_node(struct connection *conn, const void *ctx, ? node : NULL; } +static const struct node *get_node_const(struct connection *conn, + const void *ctx, const char *name, + unsigned int perm, bool allow_special) +{ + const char *tmp_name; + const struct node *node; + + tmp_name = canonicalize(conn, ctx, name, allow_special); + if (!tmp_name) + return NULL; + + node = read_node_const(conn, ctx, tmp_name); + + return get_node_chk_perm(conn, ctx, node, tmp_name, perm) ? node : NULL; +} + static int send_directory(const void *ctx, struct connection *conn, struct buffered_data *in) { - struct node *node; + const struct node *node; - node = get_node(conn, ctx, onearg(in), NULL, XS_PERM_READ, false); + node = get_node_const(conn, ctx, onearg(in), XS_PERM_READ, false); if (!node) return errno; @@ -1335,14 +1348,14 @@ static int send_directory_part(const void *ctx, struct connection *conn, { unsigned int off, len, maxlen, genlen; char *child, *data; - struct node *node; + const struct node *node; char gen[24]; if (xenstore_count_strings(in->buffer, in->used) != 2) return EINVAL; /* First arg is node name. */ - node = get_node(conn, ctx, in->buffer, NULL, XS_PERM_READ, false); + node = get_node_const(conn, ctx, in->buffer, XS_PERM_READ, false); if (!node) return errno; @@ -1389,9 +1402,9 @@ static int send_directory_part(const void *ctx, struct connection *conn, static int do_read(const void *ctx, struct connection *conn, struct buffered_data *in) { - struct node *node; + const struct node *node; - node = get_node(conn, ctx, onearg(in), NULL, XS_PERM_READ, false); + node = get_node_const(conn, ctx, onearg(in), XS_PERM_READ, false); if (!node) return errno; @@ -1799,11 +1812,11 @@ static int do_rm(const void *ctx, struct connection *conn, static int do_get_perms(const void *ctx, struct connection *conn, struct buffered_data *in) { - struct node *node; + const struct node *node; char *strings; unsigned int len; - node = get_node(conn, ctx, onearg(in), NULL, XS_PERM_READ, true); + node = get_node_const(conn, ctx, onearg(in), XS_PERM_READ, true); if (!node) return errno; -- generated by git-patchbot for /home/xen/git/xen.git#master
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |