Fix return type of extattr_set_* and fix rmextattr(8) utility.

extattr_set_{fd,file,link} is logically a write(2)-like operation and
should return ssize_t, just like extattr_get_*.  Also, the user-space
utility was using an int for the return value of extattr_get_* and
extattr_list_*, both of which return an ssize_t.

MFC after:	1 week
This commit is contained in:
Matthew D Fleming 2013-04-02 05:30:41 +00:00
parent bd9c196a87
commit e324bf91e8
7 changed files with 49 additions and 42 deletions

View File

@ -3707,7 +3707,7 @@ set_xattrs(struct archive_write_disk *a)
size_t size;
archive_entry_xattr_next(entry, &name, &value, &size);
if (name != NULL) {
int e;
ssize_t e;
int namespace;
if (strncmp(name, "user.", 5) == 0) {
@ -3734,7 +3734,7 @@ set_xattrs(struct archive_write_disk *a)
e = extattr_set_file(archive_entry_pathname(entry),
namespace, name, value, size);
}
if (e != (int)size) {
if (e != (ssize_t)size) {
if (errno == ENOTSUP || errno == ENOSYS) {
if (!warning_done) {
warning_done = 1;

View File

@ -47,7 +47,8 @@ DEFINE_TEST(test_extattr_freebsd)
struct stat st;
struct archive *a;
struct archive_entry *ae;
int n, fd;
ssize_t n;
int fd;
int extattr_privilege_bug = 0;
/*

View File

@ -50,7 +50,7 @@
.In sys/extattr.h
.Ft ssize_t
.Fn extattr_get_fd "int fd" "int attrnamespace" "const char *attrname" "void *data" "size_t nbytes"
.Ft int
.Ft ssize_t
.Fn extattr_set_fd "int fd" "int attrnamespace" "const char *attrname" "const void *data" "size_t nbytes"
.Ft int
.Fn extattr_delete_fd "int fd" "int attrnamespace" "const char *attrname"
@ -58,7 +58,7 @@
.Fn extattr_list_fd "int fd" "int attrnamespace" "void *data" "size_t nbytes"
.Ft ssize_t
.Fn extattr_get_file "const char *path" "int attrnamespace" "const char *attrname" "void *data" "size_t nbytes"
.Ft int
.Ft ssize_t
.Fn extattr_set_file "const char *path" "int attrnamespace" "const char *attrname" "const void *data" "size_t nbytes"
.Ft int
.Fn extattr_delete_file "const char *path" "int attrnamespace" "const char *attrname"
@ -66,7 +66,7 @@
.Fn extattr_list_file "const char *path" "int attrnamespace" "void *data" "size_t nbytes"
.Ft ssize_t
.Fn extattr_get_link "const char *path" "int attrnamespace" "const char *attrname" "void *data" "size_t nbytes"
.Ft int
.Ft ssize_t
.Fn extattr_set_link "const char *path" "int attrnamespace" "const char *attrname" "const void *data" "size_t nbytes"
.Ft int
.Fn extattr_delete_link "const char *path" "int attrnamespace" "const char *attrname"

View File

@ -634,7 +634,7 @@
355 AUE_EXTATTRCTL NOPROTO { int extattrctl(const char *path, int cmd, \
const char *filename, int attrnamespace, \
const char *attrname); }
356 AUE_EXTATTR_SET_FILE NOPROTO { int extattr_set_file( \
356 AUE_EXTATTR_SET_FILE NOPROTO { ssize_t extattr_set_file( \
const char *path, int attrnamespace, \
const char *attrname, void *data, \
size_t nbytes); }
@ -665,7 +665,7 @@
368 AUE_NULL UNIMPL __cap_set_fd
369 AUE_NULL UNIMPL __cap_set_file
370 AUE_NULL UNIMPL nosys
371 AUE_EXTATTR_SET_FD NOPROTO { int extattr_set_fd(int fd, \
371 AUE_EXTATTR_SET_FD NOPROTO { ssize_t extattr_set_fd(int fd, \
int attrnamespace, const char *attrname, \
void *data, size_t nbytes); }
372 AUE_EXTATTR_GET_FD NOPROTO { ssize_t extattr_get_fd(int fd, \
@ -726,7 +726,7 @@
409 AUE_NULL UNIMPL __mac_get_pid
410 AUE_NULL UNIMPL __mac_get_link
411 AUE_NULL UNIMPL __mac_set_link
412 AUE_EXTATTR_SET_LINK NOPROTO { int extattr_set_link( \
412 AUE_EXTATTR_SET_LINK NOPROTO { ssize_t extattr_set_link( \
const char *path, int attrnamespace, \
const char *attrname, void *data, \
size_t nbytes); }

View File

@ -632,7 +632,7 @@
355 AUE_EXTATTRCTL STD { int extattrctl(const char *path, int cmd, \
const char *filename, int attrnamespace, \
const char *attrname); }
356 AUE_EXTATTR_SET_FILE STD { int extattr_set_file( \
356 AUE_EXTATTR_SET_FILE STD { ssize_t extattr_set_file( \
const char *path, int attrnamespace, \
const char *attrname, void *data, \
size_t nbytes); }
@ -662,7 +662,7 @@
368 AUE_NULL UNIMPL __cap_set_fd
369 AUE_NULL UNIMPL __cap_set_file
370 AUE_NULL UNIMPL nosys
371 AUE_EXTATTR_SET_FD STD { int extattr_set_fd(int fd, \
371 AUE_EXTATTR_SET_FD STD { ssize_t extattr_set_fd(int fd, \
int attrnamespace, const char *attrname, \
void *data, size_t nbytes); }
372 AUE_EXTATTR_GET_FD STD { ssize_t extattr_get_fd(int fd, \
@ -731,7 +731,7 @@
struct mac *mac_p); }
411 AUE_NULL STD { int __mac_set_link(const char *path_p, \
struct mac *mac_p); }
412 AUE_EXTATTR_SET_LINK STD { int extattr_set_link( \
412 AUE_EXTATTR_SET_LINK STD { ssize_t extattr_set_link( \
const char *path, int attrnamespace, \
const char *attrname, void *data, \
size_t nbytes); }

View File

@ -92,11 +92,11 @@ ssize_t extattr_list_file(const char *_path, int _attrnamespace, void *_data,
size_t _nbytes);
ssize_t extattr_list_link(const char *_path, int _attrnamespace, void *_data,
size_t _nbytes);
int extattr_set_fd(int _fd, int _attrnamespace, const char *_attrname,
ssize_t extattr_set_fd(int _fd, int _attrnamespace, const char *_attrname,
const void *_data, size_t _nbytes);
int extattr_set_file(const char *_path, int _attrnamespace,
ssize_t extattr_set_file(const char *_path, int _attrnamespace,
const char *_attrname, const void *_data, size_t _nbytes);
int extattr_set_link(const char *_path, int _attrnamespace,
ssize_t extattr_set_link(const char *_path, int _attrnamespace,
const char *_attrname, const void *_data, size_t _nbytes);
__END_DECLS

View File

@ -102,6 +102,8 @@ main(int argc, char *argv[])
char *buf, *visbuf, *p;
const char *options, *attrname;
size_t len;
ssize_t ret;
int buflen, visbuflen, ch, error, i, arg_counter, attrnamespace,
minargc;
@ -200,80 +202,84 @@ main(int argc, char *argv[])
continue;
break;
case EASET:
len = strlen(buf) + flag_null;
if (flag_nofollow)
error = extattr_set_link(argv[arg_counter],
attrnamespace, attrname, buf,
strlen(buf) + flag_null);
ret = extattr_set_link(argv[arg_counter],
attrnamespace, attrname, buf, len);
else
error = extattr_set_file(argv[arg_counter],
attrnamespace, attrname, buf,
strlen(buf) + flag_null);
if (error >= 0)
ret = extattr_set_file(argv[arg_counter],
attrnamespace, attrname, buf, len);
if (ret >= 0) {
if ((size_t)ret != len && !flag_quiet) {
warnx("Set %zd bytes of %zu for %s",
ret, len, attrname);
}
continue;
}
break;
case EALS:
if (flag_nofollow)
error = extattr_list_link(argv[arg_counter],
ret = extattr_list_link(argv[arg_counter],
attrnamespace, NULL, 0);
else
error = extattr_list_file(argv[arg_counter],
ret = extattr_list_file(argv[arg_counter],
attrnamespace, NULL, 0);
if (error < 0)
if (ret < 0)
break;
mkbuf(&buf, &buflen, error);
mkbuf(&buf, &buflen, ret);
if (flag_nofollow)
error = extattr_list_link(argv[arg_counter],
ret = extattr_list_link(argv[arg_counter],
attrnamespace, buf, buflen);
else
error = extattr_list_file(argv[arg_counter],
ret = extattr_list_file(argv[arg_counter],
attrnamespace, buf, buflen);
if (error < 0)
if (ret < 0)
break;
if (!flag_quiet)
printf("%s\t", argv[arg_counter]);
for (i = 0; i < error; i += ch + 1) {
for (i = 0; i < ret; i += ch + 1) {
/* The attribute name length is unsigned. */
ch = (unsigned char)buf[i];
printf("%s%*.*s", i ? "\t" : "",
ch, ch, buf + i + 1);
}
if (!flag_quiet || error > 0)
if (!flag_quiet || ret > 0)
printf("\n");
continue;
case EAGET:
if (flag_nofollow)
error = extattr_get_link(argv[arg_counter],
ret = extattr_get_link(argv[arg_counter],
attrnamespace, attrname, NULL, 0);
else
error = extattr_get_file(argv[arg_counter],
ret = extattr_get_file(argv[arg_counter],
attrnamespace, attrname, NULL, 0);
if (error < 0)
if (ret < 0)
break;
mkbuf(&buf, &buflen, error);
mkbuf(&buf, &buflen, ret);
if (flag_nofollow)
error = extattr_get_link(argv[arg_counter],
ret = extattr_get_link(argv[arg_counter],
attrnamespace, attrname, buf, buflen);
else
error = extattr_get_file(argv[arg_counter],
ret = extattr_get_file(argv[arg_counter],
attrnamespace, attrname, buf, buflen);
if (error < 0)
if (ret < 0)
break;
if (!flag_quiet)
printf("%s\t", argv[arg_counter]);
if (flag_string) {
mkbuf(&visbuf, &visbuflen, error * 4 + 1);
strvisx(visbuf, buf, error,
mkbuf(&visbuf, &visbuflen, ret * 4 + 1);
strvisx(visbuf, buf, ret,
VIS_SAFE | VIS_WHITE);
printf("\"%s\"\n", visbuf);
continue;
} else if (flag_hex) {
for (i = 0; i < error; i++)
for (i = 0; i < ret; i++)
printf("%s%02x", i ? " " : "",
buf[i]);
printf("\n");
continue;
} else {
fwrite(buf, error, 1, stdout);
fwrite(buf, ret, 1, stdout);
printf("\n");
continue;
}