diff options
| -rw-r--r-- | src/tty/tty.zig | 9 | ||||
| -rw-r--r-- | test/daemon.py | 9 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/tty/tty.zig b/src/tty/tty.zig index b4eb6be9..08964d73 100644 --- a/src/tty/tty.zig +++ b/src/tty/tty.zig @@ -2320,7 +2320,14 @@ const Shell = struct { /// entered as the first one was; for one attached already, a view of /// its own (views.zig). Sized, asked what it can do, and drawn whole. fn attachTerminal(s: *Shell, fd: posix.fd_t, stub: posix.fd_t, cooked: ?posix.termios) void { - const live = s.term() orelse return; + // A replica client's view live (its input the last) has no terminal + // here: the session's own is the one a terminal takes, or joins. + const live = s.term() orelse for (s.terms) |slot| { + if (slot) |sc| if (sc.primary) break sc; + } else { + _ = libc.close(fd); + return refuse(stub, "that session has no terminal of its own to attach to"); + }; const screen = if (!live.on) live else extra: { const sc = s.gpa.create(Screen) catch break :extra null; const buf = s.gpa.alloc(u8, 0x10000) catch { diff --git a/test/daemon.py b/test/daemon.py index 273c29e0..da240c5b 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -337,6 +337,15 @@ def clients(binary): and b'from-B' in nine.read(f'/pane/{pane}/body')) wait_for('client A agrees once quiet', lambda: agreed(root / 'a.check', 0)) wait_for('client B agrees once quiet', lambda: agreed(root / 'b.check', 0)) + # A terminal attached while a client's view is live (its input the + # last): it takes the session's own and is drawn. + tt = Term(24, 80) + terms.append(tt) + stub = tt.spawn([binary, '--attach=files'], env) + started.append(stub.pid) + wait_for('the attached terminal\'s frame', lambda: b'line 3 of the notes' in tt.text(), timeout=20) + stub.send_signal(signal.SIGHUP) + stub.wait(timeout=10) # One put off the session's state (PARDES_TEST_DIVERGE): the next # unit's digest finds it, it says so in a line and joins again, and # its keys after go in and it agrees. |
