mirror of
https://github.com/systemd/systemd.git
synced 2026-08-04 23:20:32 +00:00
cgroup-show: split out delegation xattr check into its own function
Just some refactoring.
This commit is contained in:
@@ -128,6 +128,27 @@ static int show_cgroup_one_by_path(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int is_delegated(int cgfd, const char *path) {
|
||||
_cleanup_free_ char *b = NULL;
|
||||
int r;
|
||||
|
||||
assert(cgfd >= 0 || path);
|
||||
|
||||
r = getxattr_malloc(cgfd < 0 ? path : FORMAT_PROC_FD_PATH(cgfd), "trusted.delegate", &b);
|
||||
if (r < 0) {
|
||||
if (r == -ENODATA)
|
||||
return false;
|
||||
|
||||
return log_debug_errno(r, "Failed to read trusted.delegate extended attribute, ignoring: %m");
|
||||
}
|
||||
|
||||
r = parse_boolean(b);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to parse trusted.delegate extended attribute boolean value, ignoring: %m");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int show_cgroup_name(
|
||||
const char *path,
|
||||
const char *prefix,
|
||||
@@ -137,7 +158,7 @@ static int show_cgroup_name(
|
||||
uint64_t cgroupid = UINT64_MAX;
|
||||
_cleanup_free_ char *b = NULL;
|
||||
_cleanup_close_ int fd = -1;
|
||||
bool delegate = false;
|
||||
bool delegate;
|
||||
int r;
|
||||
|
||||
if (FLAGS_SET(flags, OUTPUT_CGROUP_XATTRS) || FLAGS_SET(flags, OUTPUT_CGROUP_ID)) {
|
||||
@@ -146,19 +167,7 @@ static int show_cgroup_name(
|
||||
log_debug_errno(errno, "Failed to open cgroup '%s', ignoring: %m", path);
|
||||
}
|
||||
|
||||
r = getxattr_malloc(fd < 0 ? path : FORMAT_PROC_FD_PATH(fd), "trusted.delegate", &b);
|
||||
if (r < 0) {
|
||||
if (r != -ENODATA)
|
||||
log_debug_errno(r, "Failed to read trusted.delegate extended attribute, ignoring: %m");
|
||||
} else {
|
||||
r = parse_boolean(b);
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to parse trusted.delegate extended attribute boolean value, ignoring: %m");
|
||||
else
|
||||
delegate = r > 0;
|
||||
|
||||
b = mfree(b);
|
||||
}
|
||||
delegate = is_delegated(fd, path) > 0;
|
||||
|
||||
if (FLAGS_SET(flags, OUTPUT_CGROUP_ID)) {
|
||||
cg_file_handle fh = CG_FILE_HANDLE_INIT;
|
||||
|
||||
Reference in New Issue
Block a user