summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarks <none@none>2008-01-24 14:02:00 -0800
committermarks <none@none>2008-01-24 14:02:00 -0800
commit575bd8a230f2c20b1878ebb473c30a12f0eb1b2e (patch)
tree5ae2b288d66bd9a77e926d52369068691a2553c1
parent2f79bea12c9814c8829dad82312f3c944423bcce (diff)
downloadillumos-gate-575bd8a230f2c20b1878ebb473c30a12f0eb1b2e.tar.gz
6653731 getattrat() needs a little cleanup
-rw-r--r--usr/src/cmd/ls/ls.c7
-rw-r--r--usr/src/lib/libc/port/gen/attrat.c42
-rw-r--r--usr/src/lib/libcmdutils/common/process_xattrs.c9
-rw-r--r--usr/src/lib/libcmdutils/common/sysattrs.c11
4 files changed, 32 insertions, 37 deletions
diff --git a/usr/src/cmd/ls/ls.c b/usr/src/cmd/ls/ls.c
index 2ea223e719..9d4acd6790 100644
--- a/usr/src/cmd/ls/ls.c
+++ b/usr/src/cmd/ls/ls.c
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -1981,14 +1981,9 @@ get_sysxattr(char *fname, struct lbuf *rep)
char *name;
int i;
- if ((error = nvlist_alloc(&response, NV_UNIQUE_NAME, 0)) != 0) {
- perror("ls:nvlist_alloc");
- return (error);
- }
if ((error = getattrat(AT_FDCWD, XATTR_VIEW_READWRITE, fname,
&response)) != 0) {
perror("ls:getattrat");
- nvlist_free(response);
return (error);
}
diff --git a/usr/src/lib/libc/port/gen/attrat.c b/usr/src/lib/libc/port/gen/attrat.c
index f2a26d17cd..53c5205d83 100644
--- a/usr/src/lib/libc/port/gen/attrat.c
+++ b/usr/src/lib/libc/port/gen/attrat.c
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -75,7 +75,7 @@ attrat_init()
if (libnvhandle)
dlclose(libnvhandle);
lmutex_unlock(&attrlock);
- return (EINVAL);
+ return (-1);
}
initialized = 1;
@@ -91,14 +91,17 @@ attr_nv_pack(nvlist_t *request, void **nv_request, size_t *nv_requestlen)
char *packbuf = NULL;
if (nvsize(request, &bufsize, NV_ENCODE_XDR) != 0) {
- return (EINVAL);
+ errno = EINVAL;
+ return (-1);
}
packbuf = malloc(bufsize);
if (packbuf == NULL)
- return (EINVAL);
+ return (-1);
if (nvpacker(request, &packbuf, &bufsize, NV_ENCODE_XDR, 0) != 0) {
free(packbuf);
+ errno = EINVAL;
+ return (-1);
} else {
*nv_request = (void *)packbuf;
*nv_requestlen = bufsize;
@@ -129,7 +132,7 @@ xattr_openat(int basefd, xattr_view_t view, int mode)
oflag = mode & O_RDWR;
break;
default:
- (void) __set_errno(EINVAL);
+ errno = EINVAL;
return (-1);
}
if (mode & O_XATTR)
@@ -154,20 +157,28 @@ cgetattr(int fd, nvlist_t **response)
struct stat buf;
if (error = attrat_init())
- return (__set_errno(error));
+ return (error);
if ((error = fstat(fd, &buf)) != 0)
- return (__set_errno(error));
+ return (error);
nv_responselen = buf.st_size;
if ((nv_response = malloc(nv_responselen)) == NULL)
- return (__set_errno(ENOMEM));
+ return (-1);
bytesread = read(fd, nv_response, nv_responselen);
- if (bytesread != nv_responselen)
- return (__set_errno(EFAULT));
+ if (bytesread != nv_responselen) {
+ free(nv_response);
+ errno = EFAULT;
+ return (-1);
+ }
+
+ if (nvunpacker(nv_response, nv_responselen, response)) {
+ free(nv_response);
+ errno = ENOMEM;
+ return (-1);
+ }
- error = nvunpacker(nv_response, nv_responselen, response);
free(nv_response);
- return (error);
+ return (0);
}
static int
@@ -179,18 +190,17 @@ csetattr(int fd, nvlist_t *request)
size_t nv_requestlen;
if (error = attrat_init())
- return (__set_errno(error));
+ return (error);
if ((error = attr_nv_pack(request, &nv_request, &nv_requestlen)) != 0)
- return (__set_errno(error));
+ return (error);
- (void) __set_errno(0);
byteswritten = write(fd, nv_request, nv_requestlen);
if (byteswritten != nv_requestlen) {
saveerrno = errno;
free(nv_request);
errno = saveerrno;
- return (__set_errno(errno));
+ return (-1);
}
free(nv_request);
diff --git a/usr/src/lib/libcmdutils/common/process_xattrs.c b/usr/src/lib/libcmdutils/common/process_xattrs.c
index 5c8df946a1..e6a5c1f7c7 100644
--- a/usr/src/lib/libcmdutils/common/process_xattrs.c
+++ b/usr/src/lib/libcmdutils/common/process_xattrs.c
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -280,17 +280,10 @@ sysattr_list(char *cmd, int fd, char *fname)
f_attr_t fattr;
char *name;
- if (nvlist_alloc(&response, NV_UNIQUE_NAME, 0) != 0) {
- (void) fprintf(stderr, dgettext(TEXT_DOMAIN,
- "%s: %s: nvlist_alloc failed\n"),
- cmd, fname);
- return (NULL);
- }
if (fgetattr(fd, XATTR_VIEW_READWRITE, &response) != 0) {
(void) fprintf(stderr, dgettext(TEXT_DOMAIN,
"%s: %s: fgetattr failed\n"),
cmd, fname);
- nvlist_free(response);
return (NULL);
}
pair = NULL;
diff --git a/usr/src/lib/libcmdutils/common/sysattrs.c b/usr/src/lib/libcmdutils/common/sysattrs.c
index a22e8e5e21..5868e765cc 100644
--- a/usr/src/lib/libcmdutils/common/sysattrs.c
+++ b/usr/src/lib/libcmdutils/common/sysattrs.c
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -48,18 +48,15 @@
int
sysattr_status(char *file, xattr_view_t view)
{
- nvlist_t *response;
+ nvlist_t *response = NULL;
int saveerrno;
int status;
- if (nvlist_alloc(&response, NV_UNIQUE_NAME, 0) != 0) {
- return (0);
- }
-
status = getattrat(AT_FDCWD, view, file, &response);
saveerrno = errno;
- (void) nvlist_free(response);
+ if (response)
+ (void) nvlist_free(response);
errno = saveerrno;
return (status == 0);