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

View File

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

View File

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

View File

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