mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-08-02 13:49:10 +00:00
This changes the way Ghostty assigns itself and subprocesses to cgroups and how resource controls are applied. * Ghostty itself no longer modifies it's own cgroup or moves itself to a transient scope. To modify the main Ghostty process' resource controls ensure that you're launching Ghostty with a systemd unit and use the standard systemd methods for overriding and applying changes to systemd units. * If configured (on by default), the process used to run your command will be moved to a transient systemd scope after it is forked from Ghostty but before the user's command is executed. Resource controls will be applied to the transient scope at this time. Changes to the `linux-cgroup*` configuration entries will not alter existing commands. If changes are made to the `linux-cgroup*` configuration entries commands will need to be relaunched. Resource limits can also be modified after launch outside of Ghostty using systemd tooling. The transient scope name can be shown by running `systemctl --user whoami` in a shell running inside Ghostty. Fixes #2084. Related to #6669
27 lines
1.0 KiB
Zig
27 lines
1.0 KiB
Zig
const std = @import("std");
|
|
|
|
const log = std.log.scoped(.@"linux-cgroup");
|
|
|
|
/// Returns the path to the cgroup for the given pid.
|
|
pub fn current(buf: []u8, pid: u32) ?[]const u8 {
|
|
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
|
|
|
|
// Read our cgroup by opening /proc/<pid>/cgroup and reading the first
|
|
// line. The first line will look something like this:
|
|
// 0::/user.slice/user-1000.slice/session-1.scope
|
|
// The cgroup path is the third field.
|
|
const path = std.fmt.bufPrint(&path_buf, "/proc/{}/cgroup", .{pid}) catch return null;
|
|
const file = std.fs.openFileAbsolute(path, .{}) catch return null;
|
|
defer file.close();
|
|
|
|
var read_buf: [64]u8 = undefined;
|
|
var file_reader = file.reader(&read_buf);
|
|
const reader = &file_reader.interface;
|
|
const len = reader.readSliceShort(buf) catch return null;
|
|
const contents = buf[0..len];
|
|
|
|
// Find the last ':'
|
|
const idx = std.mem.lastIndexOfScalar(u8, contents, ':') orelse return null;
|
|
return std.mem.trimRight(u8, contents[idx + 1 ..], " \r\n");
|
|
}
|