tree-wide: port various users over to the new getxattr_at_bool() call

This commit is contained in:
Lennart Poettering 2023-10-25 23:02:22 +02:00
parent 70554f7ebc
commit f0b8ac9e0e
3 changed files with 7 additions and 20 deletions

View File

@ -686,17 +686,17 @@ int cg_get_xattr_malloc(const char *path, const char *name, char **ret) {
}
int cg_get_xattr_bool(const char *path, const char *name) {
_cleanup_free_ char *val = NULL;
_cleanup_free_ char *fs = NULL;
int r;
assert(path);
assert(name);
r = cg_get_xattr_malloc(path, name, &val);
r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs);
if (r < 0)
return r;
return parse_boolean(val);
return getxattr_at_bool(AT_FDCWD, fs, name, /* flags= */ 0);
}
int cg_remove_xattr(const char *path, const char *name) {

View File

@ -92,8 +92,7 @@ static int extension_release_strict_xattr_value(int extension_release_fd, const
assert(filename);
/* No xattr or cannot parse it? Then skip this. */
_cleanup_free_ char *extension_release_xattr = NULL;
r = fgetxattr_malloc(extension_release_fd, "user.extension-release.strict", &extension_release_xattr);
r = getxattr_at_bool(extension_release_fd, /* path= */ NULL, "user.extension-release.strict", /* flags= */ 0);
if (ERRNO_IS_NEG_XATTR_ABSENT(r))
return log_debug_errno(r, "%s/%s does not have user.extension-release.strict xattr, ignoring.",
extension_release_dir_path, filename);
@ -102,11 +101,6 @@ static int extension_release_strict_xattr_value(int extension_release_fd, const
extension_release_dir_path, filename);
/* Explicitly set to request strict matching? Skip it. */
r = parse_boolean(extension_release_xattr);
if (r < 0)
return log_debug_errno(r,
"%s/%s: Failed to parse 'user.extension-release.strict' extended attribute from file, ignoring: %m",
extension_release_dir_path, filename);
if (r > 0) {
log_debug("%s/%s: 'user.extension-release.strict' attribute is true, ignoring file.",
extension_release_dir_path, filename);

View File

@ -49,7 +49,6 @@ typedef enum CreditEntropy {
static SeedAction arg_action = _ACTION_INVALID;
static CreditEntropy may_credit(int seed_fd) {
_cleanup_free_ char *creditable = NULL;
const char *e;
int r;
@ -76,7 +75,7 @@ static CreditEntropy may_credit(int seed_fd) {
}
/* Determine if the file is marked as creditable */
r = fgetxattr_malloc(seed_fd, "user.random-seed-creditable", &creditable);
r = getxattr_at_bool(seed_fd, /* path= */ NULL, "user.random-seed-creditable", /* flags= */ 0);
if (r < 0) {
if (ERRNO_IS_XATTR_ABSENT(r))
log_debug_errno(r, "Seed file is not marked as creditable, not crediting.");
@ -85,14 +84,8 @@ static CreditEntropy may_credit(int seed_fd) {
return CREDIT_ENTROPY_NO_WAY;
}
r = parse_boolean(creditable);
if (r <= 0) {
if (r < 0)
log_warning_errno(r, "Failed to parse user.random-seed-creditable extended attribute, ignoring: %s", creditable);
else
log_debug("Seed file is marked as not creditable, not crediting.");
if (r == 0) {
log_debug("Seed file is marked as not creditable, not crediting.");
return CREDIT_ENTROPY_NO_WAY;
}