Skip to content

Commit 7c60487

Browse files
committed
tailssh: fix platform SFTP session teardown
1 parent 7ef4474 commit 7c60487

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

protocol/tailscale/tailssh/session_platform.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func (b *platformShellBackend) OpenSession(request shellRequest) (shellSession,
2828
return &platformShellSession{
2929
session: session,
3030
master: master,
31+
isPty: request.Term != "",
3132
}, nil
3233
}
3334

@@ -38,6 +39,7 @@ func (b *platformShellBackend) Close() error {
3839
type platformShellSession struct {
3940
session adapter.ShellSession
4041
master *os.File
42+
isPty bool
4143
}
4244

4345
func (s *platformShellSession) Read(p []byte) (int, error) {
@@ -53,8 +55,10 @@ func (s *platformShellSession) Close() error {
5355
}
5456

5557
func (s *platformShellSession) CloseWrite() error {
56-
// The platform owns the master fd lifecycle; rely on Close for teardown.
57-
return nil
58+
if s.isPty {
59+
return nil
60+
}
61+
return syscall.Shutdown(int(s.master.Fd()), syscall.SHUT_WR)
5862
}
5963

6064
func (s *platformShellSession) Resize(rows, cols uint16) error {

protocol/tailscale/tailssh/subprocess_unix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ func StartSocketpairProcess(shell string, args, env []string, dir string, uid, g
4141
if err != nil {
4242
return nil, nil, E.Cause(err, "socketpair")
4343
}
44+
syscall.CloseOnExec(fds[0])
45+
syscall.CloseOnExec(fds[1])
4446
childFile := os.NewFile(uintptr(fds[1]), "socketpair-child")
4547
cmd := exec.Command(shell)
4648
cmd.Args = args

0 commit comments

Comments
 (0)