termio: use host-spawn for pty

This commit is contained in:
Mitchell Hashimoto
2023-02-25 22:36:20 -08:00
parent f012d31ed5
commit fc3802e632
4 changed files with 22 additions and 27 deletions

View File

@ -104,15 +104,12 @@ pub fn childPreExec(self: Pty) !void {
if (setsid() < 0) return error.ProcessGroupFailed;
// Set controlling terminal
// TODO: maybe
if (!@import("os/main.zig").isFlatpak()) {
switch (std.os.system.getErrno(c.ioctl(self.slave, TIOCSCTTY, @as(c_ulong, 0)))) {
.SUCCESS => {},
else => |err| {
log.err("error setting controlling terminal errno={}", .{err});
return error.SetControllingTerminalFailed;
},
}
switch (std.os.system.getErrno(c.ioctl(self.slave, TIOCSCTTY, @as(c_ulong, 0)))) {
.SUCCESS => {},
else => |err| {
log.err("error setting controlling terminal errno={}", .{err});
return error.SetControllingTerminalFailed;
},
}
// Can close master/slave pair now

View File

@ -136,6 +136,7 @@ pub fn threadMain(self: *Thread) void {
}
fn threadMain_(self: *Thread) !void {
defer log.debug("renderer thread exited", .{});
tracy.setThreadName("renderer");
// Run our thread start/end callbacks. This is important because some
@ -185,7 +186,7 @@ fn threadMain_(self: *Thread) !void {
// Run
log.debug("starting renderer thread", .{});
defer log.debug("exiting renderer thread", .{});
defer log.debug("starting renderer thread shutdown", .{});
_ = try self.loop.run(.until_done);
}

View File

@ -365,10 +365,7 @@ const Subprocess = struct {
} else null;
// Set our env vars
var env = if (internal_os.isFlatpak())
EnvMap.init(alloc)
else
try std.process.getEnvMap(alloc);
var env = try std.process.getEnvMap(alloc);
errdefer env.deinit();
try env.put("TERM", "xterm-256color");
try env.put("COLORTERM", "truecolor");
@ -397,17 +394,16 @@ const Subprocess = struct {
var args = try std.ArrayList([]const u8).initCapacity(alloc, 8);
defer args.deinit();
try args.append("/usr/bin/flatpak-spawn");
try args.append("--host");
try args.append("--watch-bus");
var env_it = env.iterator();
while (env_it.next()) |pair| {
try args.append(try std.fmt.allocPrint(
alloc,
"--env={s}={s}",
.{ pair.key_ptr.*, pair.value_ptr.* },
));
}
// We use host-spawn so the PTY is setup properly.
// future: rewrite host-spawn into pure Zig using dbus and
// we can run this directly.
try args.append("/app/bin/host-spawn");
try args.append("-pty");
try args.append("-env");
try args.append("TERM,COLORTERM");
try args.append("/bin/sh");
try args.append("-l");
try args.append("-c");
try args.append(path);
break :args try args.toOwnedSlice();
@ -417,7 +413,7 @@ const Subprocess = struct {
.arena = arena,
.env = env,
.cwd = opts.config.@"working-directory",
.path = if (internal_os.isFlatpak()) "/usr/bin/flatpak-spawn" else path,
.path = if (internal_os.isFlatpak()) args[0] else path,
.args = args,
.grid_size = opts.grid_size,
.screen_size = opts.screen_size,

View File

@ -95,6 +95,7 @@ pub fn threadMain(self: *Thread) void {
}
fn threadMain_(self: *Thread) !void {
defer log.debug("IO thread exited", .{});
tracy.setThreadName("pty io");
// Run our thread start/end callbacks. This allows the implementation
@ -109,7 +110,7 @@ fn threadMain_(self: *Thread) !void {
// Run
log.debug("starting IO thread", .{});
defer log.debug("exiting IO thread", .{});
defer log.debug("starting IO thread shutdown", .{});
try self.loop.run(.until_done);
}