[Pkg-libvirt-commits] [libguestfs] 20/233: daemon: xattr: move the listxattrs code in an own function

Hilko Bengen bengen at moszumanska.debian.org
Wed Feb 19 21:10:42 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch experimental
in repository libguestfs.

commit 59d8cf62cb67688cea42a985029adea874f0b7a2
Author: Pino Toscano <ptoscano at redhat.com>
Date:   Fri Jan 10 15:10:03 2014 +0100

    daemon: xattr: move the listxattrs code in an own function
    
    Move in an own function the code that does the (l)listxattrs allocating
    the buffer of the right legth, as it will be useful later.
    
    No functional changes, just code motion.
---
 daemon/xattr.c | 64 ++++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 44 insertions(+), 20 deletions(-)

diff --git a/daemon/xattr.c b/daemon/xattr.c
index b84cf3d..e01e9e2 100644
--- a/daemon/xattr.c
+++ b/daemon/xattr.c
@@ -54,6 +54,7 @@ optgroup_linuxxattrs_available (void)
 static guestfs_int_xattr_list *getxattrs (const char *path, ssize_t (*listxattr) (const char *path, char *list, size_t size), ssize_t (*getxattr) (const char *path, const char *name, void *value, size_t size));
 static int _setxattr (const char *xattr, const char *val, int vallen, const char *path, int (*setxattr) (const char *path, const char *name, const void *value, size_t size, int flags));
 static int _removexattr (const char *xattr, const char *path, int (*removexattr) (const char *path, const char *name));
+static char *_listxattrs (const char *path, ssize_t (*listxattr) (const char *path, char *list, size_t size), ssize_t *size);
 
 guestfs_int_xattr_list *
 do_getxattrs (const char *path)
@@ -111,27 +112,10 @@ getxattrs (const char *path,
   size_t i, j;
   guestfs_int_xattr_list *r = NULL;
 
-  CHROOT_IN;
-  len = listxattr (path, NULL, 0);
-  CHROOT_OUT;
-  if (len == -1) {
-    reply_with_perror ("listxattr: %s", path);
+  buf = _listxattrs (path, listxattr, &len);
+  if (buf == NULL)
+    /* _listxattrs issues reply_with_perror already. */
     goto error;
-  }
-
-  buf = malloc (len);
-  if (buf == NULL) {
-    reply_with_perror ("malloc");
-    goto error;
-  }
-
-  CHROOT_IN;
-  len = listxattr (path, buf, len);
-  CHROOT_OUT;
-  if (len == -1) {
-    reply_with_perror ("listxattr: %s", path);
-    goto error;
-  }
 
   r = calloc (1, sizeof (*r));
   if (r == NULL) {
@@ -252,6 +236,46 @@ _removexattr (const char *xattr, const char *path,
   return 0;
 }
 
+static char *
+_listxattrs (const char *path,
+             ssize_t (*listxattr) (const char *path, char *list, size_t size),
+             ssize_t *size)
+{
+  int r;
+  char *buf = NULL;
+  ssize_t len;
+
+  CHROOT_IN;
+  len = listxattr (path, NULL, 0);
+  CHROOT_OUT;
+  if (len == -1) {
+    reply_with_perror ("listxattr: %s", path);
+    goto error;
+  }
+
+  buf = malloc (len);
+  if (buf == NULL) {
+    reply_with_perror ("malloc");
+    goto error;
+  }
+
+  CHROOT_IN;
+  len = listxattr (path, buf, len);
+  CHROOT_OUT;
+  if (len == -1) {
+    reply_with_perror ("listxattr: %s", path);
+    goto error;
+  }
+
+  if (size)
+    *size = len;
+  return buf;
+
+ error:
+  free (buf);
+  return NULL;
+}
+
 guestfs_int_xattr_list *
 do_internal_lxattrlist (const char *path, char *const *names)
 {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list