Commit 85590511 for xz
commit 85590511c0081dd834e1c902864b0d7cac2185fc
Author: Daniel Robbins <drobbins@kernel-seeds.org>
Date: Wed Aug 5 00:25:34 2026 -0400
tuklib_cgroup: Keep looking for limits in parent cgroups
Controller files are exposed to a child only when the controller is
enabled in its parent. Thus memory.max or cpu.max may be missing in the
process's cgroup even while an ancestor still imposes a limit.
Continue walking toward the root after open() fails so such limits
aren't missed.
Link: https://github.com/tukaani-project/xz/pull/235
diff --git a/src/common/tuklib_cgroup.c b/src/common/tuklib_cgroup.c
index a24c2630..d69c6db1 100644
--- a/src/common/tuklib_cgroup.c
+++ b/src/common/tuklib_cgroup.c
@@ -114,23 +114,23 @@ get_cgroup_limit(const char *filename,
// the directory separator (slash) in buf.
memcpy(buf + len, filename, filename_size);
- // The file should exist in all non-root cgroups.
- // If opening it fails, don't waste time looking at
- // parent directories.
+ // A controller file may be missing if the controller wasn't
+ // enabled for this part of the subtree. An ancestor can still
+ // impose a limit, so keep walking towards the root if opening
+ // the file fails.
const int fd = open(buf, O_RDONLY);
- if (fd == -1)
- break;
-
- // The file should contain one short line.
- char line[64];
- const ssize_t read_size = read(fd, line, sizeof(line));
- (void)close(fd);
-
- if (read_size > 0 && line[read_size - 1] == '\n') {
- line[read_size - 1] = '\0';
- const unsigned long long value = parse(line);
- if (ret > value)
- ret = value;
+ if (fd != -1) {
+ // The file should contain one short line.
+ char line[64];
+ const ssize_t read_size = read(fd, line, sizeof(line));
+ (void)close(fd);
+
+ if (read_size > 0 && line[read_size - 1] == '\n') {
+ line[read_size - 1] = '\0';
+ const unsigned long long value = parse(line);
+ if (ret > value)
+ ret = value;
+ }
}
// Continue from the parent directory.