ENXIO,
ENOENT);
}
+
+/* Quite often we want to handle cases where the backing FS doesn't support extended attributes at all and
+ * where it simply doesn't have the requested xattr the same way */
+static inline bool ERRNO_IS_XATTR_ABSENT(int r) {
+ return abs(r) == ENODATA ||
+ ERRNO_IS_NOT_SUPPORTED(r);
+}
/* No xattr or cannot parse it? Then skip this. */
_cleanup_free_ char *extension_release_xattr = NULL;
k = fgetxattr_malloc(extension_release_fd, "user.extension-release.strict", &extension_release_xattr);
- if (k < 0 && !ERRNO_IS_NOT_SUPPORTED(k) && k != -ENODATA)
+ if (k < 0 && !ERRNO_IS_XATTR_ABSENT(k))
log_debug_errno(k,
"%s/%s: Failed to read 'user.extension-release.strict' extended attribute from file: %m",
extension_release_dir_path, de->d_name);
}
r = cg_remove_xattr(SYSTEMD_CGROUP_CONTROLLER, cgroup_path, name);
- if (r < 0 && r != -ENODATA)
+ if (r < 0 && !ERRNO_IS_XATTR_ABSENT(r))
log_unit_debug_errno(u, r, "Failed to remove '%s' xattr flag on control group %s, ignoring: %m", name, empty_to_root(cgroup_path));
}
return 0;
r = cg_get_xattr_malloc(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path, "user.oomd_ooms", &value);
- if (r < 0 && r != -ENODATA)
+ if (r < 0 && !ERRNO_IS_XATTR_ABSENT(r))
return r;
if (!isempty(value)) {
_cleanup_free_ char *exec_label = NULL;
r = mac_smack_read_fd(executable_fd, SMACK_ATTR_EXEC, &exec_label);
- if (r < 0 && !IN_SET(r, -ENODATA, -EOPNOTSUPP))
+ if (r < 0 && !ERRNO_IS_XATTR_ABSENT(r))
return r;
r = mac_smack_apply_pid(0, exec_label ? : manager->default_smack_process_label);
return log_debug_errno(r, "Failed to synchronize image before marking it clean: %m");
ret = fremovexattr(fd, "user.home-dirty");
- if (ret < 0 && errno != ENODATA)
+ if (ret < 0 && !ERRNO_IS_XATTR_ABSENT(errno))
return log_debug_errno(errno, "Could not mark home directory as clean: %m");
}
n = getxattr(ip, "user.home-dirty", x, sizeof(x));
if (n < 0) {
- if (errno != ENODATA)
+ if (!ERRNO_IS_XATTR_ABSENT(errno))
log_debug_errno(errno, "Unable to read dirty xattr off image file, ignoring: %m");
} else if (n == 1 && x[0] == '1')
#include <sys/xattr.h>
#include <unistd.h>
+#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "format-util.h"
assert(xattr);
r = cg_get_xattr_malloc(SYSTEMD_CGROUP_CONTROLLER, path, xattr, &value);
- if (r < 0 && r != -ENODATA)
+ if (r < 0 && !ERRNO_IS_XATTR_ABSENT(r))
return r;
if (!isempty(value)) {
r = cg_get_xattr_bool(SYSTEMD_CGROUP_CONTROLLER, ctx->path, "user.oomd_avoid");
if (r == -ENOMEM)
return log_oom_debug();
- if (r < 0 && r != -ENODATA)
+ if (r < 0 && !ERRNO_IS_XATTR_ABSENT(r))
log_debug_errno(r, "Failed to get xattr user.oomd_avoid, ignoring: %m");
ctx->preference = r > 0 ? MANAGED_OOM_PREFERENCE_AVOID : ctx->preference;
r = cg_get_xattr_bool(SYSTEMD_CGROUP_CONTROLLER, ctx->path, "user.oomd_omit");
if (r == -ENOMEM)
return log_oom_debug();
- if (r < 0 && r != -ENODATA)
+ if (r < 0 && !ERRNO_IS_XATTR_ABSENT(r))
log_debug_errno(r, "Failed to get xattr user.oomd_omit, ignoring: %m");
ctx->preference = r > 0 ? MANAGED_OOM_PREFERENCE_OMIT : ctx->preference;
} else
* we have to preserve it. Copy it out so that it can be applied later. */
r = fgetfilecon_raw(fd, &con);
- if (r < 0 && errno != ENODATA)
+ if (r < 0 && !ERRNO_IS_XATTR_ABSENT(errno))
log_debug_errno(errno, "Failed to get SELinux file context from '%s', ignoring: %m", de->d_name);
#endif
/* Determine if the file is marked as creditable */
r = fgetxattr_malloc(seed_fd, "user.random-seed-creditable", &creditable);
if (r < 0) {
- if (IN_SET(r, -ENODATA, -ENOSYS, -EOPNOTSUPP))
+ if (ERRNO_IS_XATTR_ABSENT(r))
log_debug_errno(r, "Seed file is not marked as creditable, not crediting.");
else
log_warning_errno(r, "Failed to read extended attribute, ignoring: %m");
* it. */
if (fremovexattr(seed_fd, "user.random-seed-creditable") < 0) {
- if (!IN_SET(errno, ENODATA, ENOSYS, EOPNOTSUPP))
+ if (!ERRNO_IS_XATTR_ABSENT(errno))
log_warning_errno(errno, "Failed to remove extended attribute, ignoring: %m");
/* Otherwise, there was no creditable flag set, which is OK. */
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)
/* 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);
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");
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");
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;
}
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);
}
r = cg_get_xattr_bool(SYSTEMD_CGROUP_CONTROLLER, cgroup, "trusted.delegate");
- if (IN_SET(r, 0, -ENODATA))
+ if (r == 0 || (r < 0 && ERRNO_IS_XATTR_ABSENT(r)))
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "The cgroup %s is not delegated to us.", cgroup);
if (r < 0)
return log_debug_errno(r, "Failed to read trusted.delegate attribute: %m");