Skip to content

Commit b7f4418

Browse files
committed
allow multiple local clients, block latch inside latch
Remove single local client restriction so multiple terminals can attach to different sessions simultaneously. Set LATCH_SESSION env var inside pane shells and check it on new/attach/default to prevent running latch inside a local latch session.
1 parent 05969a8 commit b7f4418

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

cmd/latch/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ func main() {
2121
}
2222

2323
if len(os.Args) < 2 {
24+
if os.Getenv("LATCH_SESSION") != "" {
25+
fatal("already inside a latch session")
26+
}
2427
ensureServer(cfg)
2528
if err := client.Attach(server.SocketPath(), "default", true, cfg.PrefixKey); err != nil {
2629
fatal("%v", err)
@@ -55,6 +58,9 @@ func main() {
5558
serve(cfg, sshAddr, webAddr)
5659

5760
case "new":
61+
if os.Getenv("LATCH_SESSION") != "" {
62+
fatal("already inside a latch session")
63+
}
5864
name := "default"
5965
var sshAddr, webAddr string
6066
detached := false
@@ -88,6 +94,9 @@ func main() {
8894
}
8995

9096
case "attach", "a":
97+
if os.Getenv("LATCH_SESSION") != "" {
98+
fatal("already inside a latch session")
99+
}
91100
name := "default"
92101
if len(os.Args) > 2 {
93102
name = os.Args[2]

internal/mux/pane.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func NewPane(id int, cols, rows int, shell string, scrollbackLines ...int) (*Pan
6767
}
6868

6969
cmd := exec.Command(shell, "-l")
70-
cmd.Env = append(os.Environ(), "TERM=xterm-256color")
70+
cmd.Env = append(os.Environ(), "TERM=xterm-256color", "LATCH_SESSION=1")
7171
if home, err := os.UserHomeDir(); err == nil {
7272
cmd.Dir = home
7373
}

internal/server/server.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,6 @@ func (s *Server) attachSession(conn net.Conn, sess *mux.Session) {
251251
meta.Session = sess.Name
252252
meta.closer = conn
253253

254-
// Enforce single local attach.
255-
if meta.Source == "local" && s.tracker.hasLocal() {
256-
proto.Encode(conn, proto.MsgError, []byte("another local client is attached"))
257-
return
258-
}
259-
260254
// Per-session access control for remote clients.
261255
reject := func(reason string) {
262256
s.audit.emit(AuditEvent{

0 commit comments

Comments
 (0)