mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-08 10:56:34 +00:00
execute the child command
This commit is contained in:
20
src/Pty.zig
20
src/Pty.zig
@@ -14,6 +14,7 @@ const c = switch (builtin.os.tag) {
|
||||
@cInclude("util.h"); // openpty()
|
||||
}),
|
||||
else => @cImport({
|
||||
@cInclude("sys/ioctl.h"); // ioctl and constants
|
||||
@cInclude("pty.h");
|
||||
}),
|
||||
};
|
||||
@@ -27,6 +28,8 @@ const winsize = extern struct {
|
||||
ws_ypixel: u16,
|
||||
};
|
||||
|
||||
pub extern "c" fn setsid() std.c.pid_t;
|
||||
|
||||
/// The file descriptors for the master and slave side of the pty.
|
||||
master: fd_t,
|
||||
slave: fd_t,
|
||||
@@ -73,6 +76,23 @@ pub fn setSize(self: Pty, size: winsize) !void {
|
||||
return error.IoctlFailed;
|
||||
}
|
||||
|
||||
/// This should be called prior to exec in the forked child process
|
||||
/// in order to setup the tty properly.
|
||||
pub fn childPreExec(self: Pty) !void {
|
||||
// Create a new process group
|
||||
if (setsid() < 0) return error.ProcessGroupFailed;
|
||||
|
||||
// Set controlling terminal
|
||||
if (std.os.linux.ioctl(self.slave, c.TIOCSCTTY, 0) < 0)
|
||||
return error.SetControllingTerminalFailed;
|
||||
|
||||
// Can close master/slave pair now
|
||||
std.os.close(self.slave);
|
||||
std.os.close(self.master);
|
||||
|
||||
// TODO: reset signals
|
||||
}
|
||||
|
||||
test {
|
||||
var ws: winsize = .{
|
||||
.ws_row = 50,
|
||||
|
Reference in New Issue
Block a user