diff options
Diffstat (limited to 'runtime/main.zig')
| -rw-r--r-- | runtime/main.zig | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/runtime/main.zig b/runtime/main.zig index b0338831..aa35e687 100644 --- a/runtime/main.zig +++ b/runtime/main.zig @@ -1632,8 +1632,7 @@ fn nativeMain(std_init: std.process.Init) !void { // No controlling terminal (a detached pty, a daemon): said, not // an error trace. error.NoDevice => { - std.Io.File.stderr().writeStreamingAll(init.io, "pardes: no terminal to draw on: /dev/tty will not open; run it in a terminal, or --detach\n") catch {}; - std.process.exit(1); + noTerminal(init.io); }, else => return err, }, @@ -1761,6 +1760,13 @@ fn pardesBeside(buf: *[4104]u8) ?[:0]const u8 { /// the client exits. No fork to be had: returns, and this process is the /// session, with no terminal: said by the caller's run. A window with no /// `pardes` beside it returns at once, its own session as before. +/// A terminal's launch with no terminal to draw on (a detached pty, a +/// daemon): said, not an error trace, and exit 1. +fn noTerminal(io: std.Io) noreturn { + std.Io.File.stderr().writeStreamingAll(io, "pardes: no terminal to draw on: /dev/tty will not open; run it in a terminal, or --detach\n") catch {}; + std.process.exit(1); +} + fn pair(init: std.process.Init, opts: *pardes.Options, args: []const [:0]const u8) void { var path_buf: [4104]u8 = undefined; var fd_buf: [32]u8 = undefined; @@ -1771,6 +1777,13 @@ fn pair(init: std.process.Init, opts: *pardes.Options, args: []const [:0]const u argv[0] = path.ptr; for (args[1..], 2..) |a, k| argv[k] = a.ptr; } + // Its client draws on /dev/tty: none to be had, said as the own path + // says it, before a session is forked for nobody. + if (pardes.platform == .tui) { + const tty = std.c.open("/dev/tty", .{ .ACCMODE = .RDWR, .CLOEXEC = true }, @as(std.c.mode_t, 0)); + if (tty < 0) noTerminal(init.io); + _ = std.c.close(tty); + } const conn: ?c_int = if (pardes.platform == .tui and daemon.wanted()) daemon.connect(true) else null; var fds: [2]c_int = undefined; if (std.c.socketpair(std.c.AF.UNIX, std.c.SOCK.STREAM | std.c.SOCK.CLOEXEC, 0, &fds) != 0) |
