assert(path);
r = cg_get_xattr_bool(path, "trusted.delegate");
- if (ERRNO_IS_NEG_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 = cg_get_xattr_bool(path, "user.delegate");
- if (ERRNO_IS_NEG_XATTR_ABSENT(r))
- return false;
- }
+ if (!ERRNO_IS_NEG_XATTR_ABSENT(r))
+ return r;
- return 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 = cg_get_xattr_bool(path, "user.delegate");
+ return ERRNO_IS_NEG_XATTR_ABSENT(r) ? false : r;
+}
+
+int cg_is_delegated_fd(int fd) {
+ int r;
+
+ assert(fd >= 0);
+
+ r = getxattr_at_bool(fd, /* path= */ NULL, "trusted.delegate", /* flags= */ 0);
+ if (!ERRNO_IS_NEG_XATTR_ABSENT(r))
+ return r;
+
+ r = getxattr_at_bool(fd, /* path= */ NULL, "user.delegate", /* flags= */ 0);
+ return ERRNO_IS_NEG_XATTR_ABSENT(r) ? false : r;
}
int cg_has_coredump_receive(const char *path) {