mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-07 18:36:33 +00:00
termio: plumb a lot more to get ready to move into cgroup
This commit is contained in:
@@ -166,8 +166,8 @@ fn createScope(connection: *c.GDBusConnection) !void {
|
|||||||
&err,
|
&err,
|
||||||
) orelse {
|
) orelse {
|
||||||
if (err) |e| log.err(
|
if (err) |e| log.err(
|
||||||
"creating transient cgroup scope failed err={s}",
|
"creating transient cgroup scope failed code={} err={s}",
|
||||||
.{e.message},
|
.{ e.code, e.message },
|
||||||
);
|
);
|
||||||
return error.DbusCallFailed;
|
return error.DbusCallFailed;
|
||||||
};
|
};
|
||||||
|
@@ -179,13 +179,6 @@ pub fn init(alloc: Allocator, opts: termio.Options) !Exec {
|
|||||||
term.width_px = subprocess.screen_size.width;
|
term.width_px = subprocess.screen_size.width;
|
||||||
term.height_px = subprocess.screen_size.height;
|
term.height_px = subprocess.screen_size.height;
|
||||||
|
|
||||||
// TODO: make work
|
|
||||||
if (comptime builtin.os.tag == .linux) {
|
|
||||||
if (opts.linux_cgroup) |cgroup| {
|
|
||||||
log.warn("DESIRED cgroup={s}", .{cgroup});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.alloc = alloc,
|
.alloc = alloc,
|
||||||
.terminal = term,
|
.terminal = term,
|
||||||
@@ -904,6 +897,7 @@ const Subprocess = struct {
|
|||||||
pty: ?Pty = null,
|
pty: ?Pty = null,
|
||||||
command: ?Command = null,
|
command: ?Command = null,
|
||||||
flatpak_command: ?FlatpakHostCommand = null,
|
flatpak_command: ?FlatpakHostCommand = null,
|
||||||
|
linux_cgroup: termio.Options.LinuxCgroup = termio.Options.linux_cgroup_default,
|
||||||
|
|
||||||
/// Initialize the subprocess. This will NOT start it, this only sets
|
/// Initialize the subprocess. This will NOT start it, this only sets
|
||||||
/// up the internal state necessary to start it later.
|
/// up the internal state necessary to start it later.
|
||||||
@@ -1200,6 +1194,15 @@ const Subprocess = struct {
|
|||||||
else
|
else
|
||||||
null;
|
null;
|
||||||
|
|
||||||
|
// If we have a cgroup, then we copy that into our arena so the
|
||||||
|
// memory remains valid when we start.
|
||||||
|
const linux_cgroup: termio.Options.LinuxCgroup = cgroup: {
|
||||||
|
const default = termio.Options.linux_cgroup_default;
|
||||||
|
if (comptime builtin.os.tag != .linux) break :cgroup default;
|
||||||
|
const path = opts.linux_cgroup orelse break :cgroup default;
|
||||||
|
break :cgroup try alloc.dupe(u8, path);
|
||||||
|
};
|
||||||
|
|
||||||
// Our screen size should be our padded size
|
// Our screen size should be our padded size
|
||||||
const padded_size = opts.screen_size.subPadding(opts.padding);
|
const padded_size = opts.screen_size.subPadding(opts.padding);
|
||||||
|
|
||||||
@@ -1210,6 +1213,7 @@ const Subprocess = struct {
|
|||||||
.args = args,
|
.args = args,
|
||||||
.grid_size = opts.grid_size,
|
.grid_size = opts.grid_size,
|
||||||
.screen_size = padded_size,
|
.screen_size = padded_size,
|
||||||
|
.linux_cgroup = linux_cgroup,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1303,12 +1307,14 @@ const Subprocess = struct {
|
|||||||
.pseudo_console = if (builtin.os.tag == .windows) pty.pseudo_console else {},
|
.pseudo_console = if (builtin.os.tag == .windows) pty.pseudo_console else {},
|
||||||
.pre_exec = if (builtin.os.tag == .windows) null else (struct {
|
.pre_exec = if (builtin.os.tag == .windows) null else (struct {
|
||||||
fn callback(cmd: *Command) void {
|
fn callback(cmd: *Command) void {
|
||||||
const p = cmd.getData(Pty) orelse unreachable;
|
const sp = cmd.getData(Subprocess) orelse unreachable;
|
||||||
p.childPreExec() catch |err|
|
sp.childPreExec() catch |err| log.err(
|
||||||
log.err("error initializing child: {}", .{err});
|
"error initializing child: {}",
|
||||||
|
.{err},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}).callback,
|
}).callback,
|
||||||
.data = &self.pty.?,
|
.data = self,
|
||||||
};
|
};
|
||||||
try cmd.start(alloc);
|
try cmd.start(alloc);
|
||||||
errdefer killCommand(&cmd) catch |err| {
|
errdefer killCommand(&cmd) catch |err| {
|
||||||
@@ -1330,6 +1336,22 @@ const Subprocess = struct {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This should be called after fork but before exec in the child process.
|
||||||
|
/// To repeat: this function RUNS IN THE FORKED CHILD PROCESS before
|
||||||
|
/// exec is called; it does NOT run in the main Ghostty process.
|
||||||
|
fn childPreExec(self: *Subprocess) !void {
|
||||||
|
// Setup our pty
|
||||||
|
try self.pty.?.childPreExec();
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Called to notify that we exited externally so we can unset our
|
/// Called to notify that we exited externally so we can unset our
|
||||||
/// running state.
|
/// running state.
|
||||||
pub fn externalExit(self: *Subprocess) void {
|
pub fn externalExit(self: *Subprocess) void {
|
||||||
|
Reference in New Issue
Block a user