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 -2
View File
@@ -135,12 +135,12 @@ static int is_delegated(int cgfd, const char *path) {
assert(cgfd >= 0 || path);
r = getxattr_malloc(cgfd < 0 ? path : FORMAT_PROC_FD_PATH(cgfd), "trusted.delegate", &b);
if (r == -ENODATA) {
if (r < 0 && ERRNO_IS_XATTR_ABSENT(r)) {
/* If the trusted xattr isn't set (preferred), then check the untrusted one. Under the
* assumption that whoever is trusted enough to own the cgroup, is also trusted enough to
* decide if it is delegated or not this should be safe. */
r = getxattr_malloc(cgfd < 0 ? path : FORMAT_PROC_FD_PATH(cgfd), "user.delegate", &b);
if (r == -ENODATA)
if (r < 0 && ERRNO_IS_XATTR_ABSENT(r))
return false;
}
if (r < 0)
+1 -1
View File
@@ -32,7 +32,7 @@ static int chown_one(
/* Drop any ACL if there is one */
FOREACH_STRING(n, "system.posix_acl_access", "system.posix_acl_default")
if (removexattr(FORMAT_PROC_FD_PATH(fd), n) < 0)
if (!IN_SET(errno, ENODATA, EOPNOTSUPP, ENOSYS, ENOTTY))
if (!ERRNO_IS_XATTR_ABSENT(errno))
return -errno;
r = fchmod_and_chown(fd, st->st_mode & mask, uid, gid);
+2 -2
View File
@@ -2379,7 +2379,7 @@ int verity_settings_load(
if (r < 0) {
_cleanup_free_ char *p = NULL;
if (!IN_SET(r, -ENODATA, -ENOENT) && !ERRNO_IS_NOT_SUPPORTED(r))
if (r != -ENOENT && !ERRNO_IS_XATTR_ABSENT(r))
return r;
p = build_auxiliary_path(image, ".roothash");
@@ -2408,7 +2408,7 @@ int verity_settings_load(
if (r < 0) {
_cleanup_free_ char *p = NULL;
if (!IN_SET(r, -ENODATA, -ENOENT) && !ERRNO_IS_NOT_SUPPORTED(r))
if (r != -ENOENT && !ERRNO_IS_XATTR_ABSENT(r))
return r;
p = build_auxiliary_path(image, ".usrhash");