termio/exec: move subprocess into cgroup

This commit is contained in:
Mitchell Hashimoto
2024-06-05 09:30:21 -07:00
parent a63c8d0913
commit 7d9da34259
2 changed files with 13 additions and 2 deletions

View File

@ -52,6 +52,18 @@ pub fn create(
}
}
/// Move the given PID into the given cgroup.
pub fn moveInto(
cgroup: []const u8,
pid: std.os.linux.pid_t,
) !void {
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
const path = try std.fmt.bufPrint(&buf, "/sys/fs/cgroup{s}/cgroup.procs", .{cgroup});
const file = try std.fs.cwd().openFile(path, .{ .mode = .write_only });
defer file.close();
try file.writer().print("{}", .{pid});
}
/// Returns all available cgroup controllers for the given cgroup.
/// The cgroup should have a '/'-prefix.
///

View File

@ -1346,8 +1346,7 @@ const Subprocess = struct {
// If we have a cgroup set, then we want to move into that cgroup.
if (comptime builtin.os.tag == .linux) {
if (self.linux_cgroup) |cgroup| {
// TODO: do it
_ = cgroup;
try internal_os.cgroup.moveInto(cgroup, 0);
}
}
}