diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-04-04 19:22:04 +0300 |
|---|---|---|
| committer | Can Celik <ogulcancelik@gmail.com> | 2026-04-05 01:23:06 +0300 |
| commit | 41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch) | |
| tree | 3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/src/os/cgroup.zig | |
| parent | 55c138263e190a1e79d4b997bfb9397306c0ec1f (diff) | |
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/os/cgroup.zig')
| -rw-r--r-- | vendor/libghostty-vt/src/os/cgroup.zig | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/os/cgroup.zig b/vendor/libghostty-vt/src/os/cgroup.zig new file mode 100644 index 00000000..9e68a50f --- /dev/null +++ b/vendor/libghostty-vt/src/os/cgroup.zig @@ -0,0 +1,26 @@ +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"); +} |
