X Tutup
Skip to content

Commit bde2607

Browse files
committed
cgroup-show: split out delegation xattr check into its own function
Just some refactoring.
1 parent 45cab6e commit bde2607

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/shared/cgroup-show.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,27 @@ static int show_cgroup_one_by_path(
128128
return 0;
129129
}
130130

131+
static int is_delegated(int cgfd, const char *path) {
132+
_cleanup_free_ char *b = NULL;
133+
int r;
134+
135+
assert(cgfd >= 0 || path);
136+
137+
r = getxattr_malloc(cgfd < 0 ? path : FORMAT_PROC_FD_PATH(cgfd), "trusted.delegate", &b);
138+
if (r < 0) {
139+
if (r == -ENODATA)
140+
return false;
141+
142+
return log_debug_errno(r, "Failed to read trusted.delegate extended attribute, ignoring: %m");
143+
}
144+
145+
r = parse_boolean(b);
146+
if (r < 0)
147+
return log_debug_errno(r, "Failed to parse trusted.delegate extended attribute boolean value, ignoring: %m");
148+
149+
return r;
150+
}
151+
131152
static int show_cgroup_name(
132153
const char *path,
133154
const char *prefix,
@@ -137,7 +158,7 @@ static int show_cgroup_name(
137158
uint64_t cgroupid = UINT64_MAX;
138159
_cleanup_free_ char *b = NULL;
139160
_cleanup_close_ int fd = -1;
140-
bool delegate = false;
161+
bool delegate;
141162
int r;
142163

143164
if (FLAGS_SET(flags, OUTPUT_CGROUP_XATTRS) || FLAGS_SET(flags, OUTPUT_CGROUP_ID)) {
@@ -146,19 +167,7 @@ static int show_cgroup_name(
146167
log_debug_errno(errno, "Failed to open cgroup '%s', ignoring: %m", path);
147168
}
148169

149-
r = getxattr_malloc(fd < 0 ? path : FORMAT_PROC_FD_PATH(fd), "trusted.delegate", &b);
150-
if (r < 0) {
151-
if (r != -ENODATA)
152-
log_debug_errno(r, "Failed to read trusted.delegate extended attribute, ignoring: %m");
153-
} else {
154-
r = parse_boolean(b);
155-
if (r < 0)
156-
log_debug_errno(r, "Failed to parse trusted.delegate extended attribute boolean value, ignoring: %m");
157-
else
158-
delegate = r > 0;
159-
160-
b = mfree(b);
161-
}
170+
delegate = is_delegated(fd, path) > 0;
162171

163172
if (FLAGS_SET(flags, OUTPUT_CGROUP_ID)) {
164173
cg_file_handle fh = CG_FILE_HANDLE_INIT;

0 commit comments

Comments
 (0)
X Tutup