summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/main.zig17
-rw-r--r--runtime/session.zig4
2 files changed, 19 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)
diff --git a/runtime/session.zig b/runtime/session.zig
index 60644aa6..5e99384e 100644
--- a/runtime/session.zig
+++ b/runtime/session.zig
@@ -188,6 +188,10 @@ pub fn Loop(comptime Frontend: type) type {
/// let go (host_io.restoreCore); its shells and the frontend's
/// devices with it.
fn restore(l: *L, path: []const u8) void {
+ // A pair's session no daemon keeps: a Restore lets every client
+ // go, and its one could not join it again (no socket finds it):
+ // refused, as its Upgrade is (tui.zig `upgradeNow`).
+ if (l.peers.count() > 0 and daemon.link < 0) return l.core.reportFailure(l.core.view().active, "Restore: no daemon keeps this session, so its client could not join it again; this session stays as it is");
const nc = host_io.restoreCore(l.gpa, l.core, path, &l.peers, l.watches.fd, &l.watches.table) orelse return;
l.fe.restoring(nc);
// The old core's pipes end, and an answer to its query is