Skip to content

Commit c82fc09

Browse files
committed
fix: return tty name
1 parent 9a55991 commit c82fc09

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

pty_other.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ import (
1111

1212
type impl struct{}
1313

14+
func (i *impl) IsZero() bool {
15+
return true
16+
}
17+
18+
func (i *impl) Name() string {
19+
return ""
20+
}
21+
1422
func (i *impl) Read(p []byte) (n int, err error) {
1523
return 0, ErrUnsupported
1624
}

pty_unix.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@ type impl struct {
2121

2222
// Slave is the slave PTY file descriptor.
2323
Slave *os.File
24+
}
25+
26+
func (i *impl) IsZero() bool {
27+
return i.Master == nil && i.Slave == nil
28+
}
2429

25-
// Name is the name of the slave PTY.
26-
Name string
30+
// Name returns the name of the slave PTY.
31+
func (i *impl) Name() string {
32+
return i.Slave.Name()
2733
}
2834

2935
// Read implements ptyInterface.
@@ -60,10 +66,13 @@ func (i *impl) Resize(w int, h int) (rErr error) {
6066
}
6167

6268
func (i *impl) start(c *exec.Cmd) error {
63-
c.Stdin, c.Stdout, c.Stderr := i.Slave, i.Slave, i.Slave
69+
c.Stdin, c.Stdout, c.Stderr = i.Slave, i.Slave, i.Slave
6470
if c.SysProcAttr == nil {
6571
c.SysProcAttr = &syscall.SysProcAttr{}
6672
}
73+
c.SysProcAttr.Setctty = true
74+
c.SysProcAttr.Setsid = true
75+
return c.Start()
6776
}
6877

6978
func newPty(_ Context, _ string, win Window, modes ssh.TerminalModes) (_ impl, rErr error) {
@@ -83,7 +92,7 @@ func newPty(_ Context, _ string, win Window, modes ssh.TerminalModes) (_ impl, r
8392
return impl{}, err
8493
}
8594

86-
return impl{Master: ptm, Slave: pts, Name: pts.Name()}, rErr
95+
return impl{Master: ptm, Slave: pts}, rErr
8796
}
8897

8998
func applyTerminalModesToFd(fd uintptr, width int, height int, modes ssh.TerminalModes) error {

pty_windows.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ type impl struct {
1919
*conpty.ConPty
2020
}
2121

22+
func (i *impl) IsZero() bool {
23+
return i.ConPty == nil
24+
}
25+
26+
func (i *impl) Name() string {
27+
return "windows-pty"
28+
}
29+
2230
func (i *impl) Read(p []byte) (n int, err error) {
2331
return i.ConPty.Read(p)
2432
}

session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ func (sess *session) handleRequests(reqs <-chan *gossh.Request) {
364364

365365
defer closer() // nolint: errcheck
366366

367-
if !sess.EmulatedPty() {
367+
if !sess.EmulatedPty() && !sess.pty.IsZero() {
368368
go func() {
369369
for win := range sess.winch {
370370
if err := resizePty(sess, win); err != nil {

0 commit comments

Comments
 (0)