[Libguestfs] [PATCH libguestfs 1/3] daemon: xattr: Refactor code which splits attr names from the kernel.
Pino Toscano
ptoscano at redhat.com
Fri Mar 13 13:28:25 UTC 2020
On Thursday, 12 March 2020 15:44:46 CET Richard W.M. Jones wrote:
> +static char **
> +split_attr_names (const char *buf, size_t len)
> +{
> + size_t i;
> + DECLARE_STRINGSBUF (ret);
Declare this as CLEANUP_FREE_STRINGSBUF, so there is no need for the
manual calls to free_stringsbuf on failure. take_stringsbuf at the
return is fine, as it will hand over the resources to the caller.
> CHROOT_OUT;
> if (vlen == -1) {
> - reply_with_perror ("getxattr");
> + reply_with_perror ("%s: getxattr", names[i]);
IIRC "what: details" is more common, so "getxattr: %s". (Same for the
other ocurrences.)
> goto error;
> }
>
> if (vlen > XATTR_SIZE_MAX) {
> /* The next call to getxattr will fail anyway, so ... */
> - reply_with_error ("extended attribute is too large");
> + reply_with_error ("%s: extended attribute is too large", names[i]);
> goto error;
> }
>
> - r->guestfs_int_xattr_list_val[j].attrname = strdup (&buf[i]);
> - r->guestfs_int_xattr_list_val[j].attrval.attrval_val = malloc (vlen);
> - r->guestfs_int_xattr_list_val[j].attrval.attrval_len = vlen;
> + r->guestfs_int_xattr_list_val[i].attrname = strdup (&buf[i]);
names[i]
[you already fixed this, I just amended this message before sending it,
as I started to write it yesterday]
> @@ -378,36 +406,36 @@ do_internal_lxattrlist (const char *path, char *const *names)
> entry[m].attrval.attrval_val = NULL;
> }
>
> - for (i = 0, j = 0; i < (size_t) len; i += strlen (&buf[i]) + 1, ++j) {
> + for (i = 0; attrnames[i] != NULL; ++i) {
Considering we have nr_attrs at this point, we can use it.
--
Pino Toscano
--
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20200313/4119932c/attachment.sig>
More information about the Libguestfs
mailing list