tree-wide: add ERRNO_IS_XATTR_ABSENT() helper

We check the same list of error codes on various xattr operations, and
we should on some more. Add a common helper for this purpose.
This commit is contained in:
Lennart Poettering
2022-10-10 16:00:15 +02:00
parent dcf1bf3b6d
commit 00675c363f
15 changed files with 29 additions and 23 deletions
+2 -4
View File
@@ -32,10 +32,8 @@ static const uint8_t default_acl[] = {
static bool has_xattr(const char *p) {
char buffer[sizeof(acl) * 4];
if (lgetxattr(p, "system.posix_acl_access", buffer, sizeof(buffer)) < 0) {
if (IN_SET(errno, EOPNOTSUPP, ENOTTY, ENODATA, ENOSYS))
return false;
}
if (lgetxattr(p, "system.posix_acl_access", buffer, sizeof(buffer)) < 0)
return !ERRNO_IS_XATTR_ABSENT(errno);
return true;
}
+1 -1
View File
@@ -46,7 +46,7 @@ TEST(getxattr_at_malloc) {
fd = open("/", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY);
assert_se(fd >= 0);
r = getxattr_at_malloc(fd, "usr", "user.idontexist", 0, &value);
assert_se(r == -ENODATA || ERRNO_IS_NOT_SUPPORTED(r));
assert_se(r < 0 && ERRNO_IS_XATTR_ABSENT(r));
safe_close(fd);
fd = open(x, O_PATH|O_CLOEXEC);