feat: Set SSH env vars: SSH_CLIENT, SSH_CONNECTION and SSH_TTY (#3622)

Fixes #2339
This commit is contained in:
Mathias Fredriksson
2022-08-23 21:19:57 +03:00
committed by GitHub
parent 9c0cd5287c
commit e44f7adb7e
4 changed files with 45 additions and 1 deletions
+3
View File
@@ -4,6 +4,7 @@
package pty
import (
"fmt"
"os/exec"
"runtime"
"strings"
@@ -18,6 +19,8 @@ func startPty(cmd *exec.Cmd) (PTY, Process, error) {
if err != nil {
return nil, nil, xerrors.Errorf("open: %w", err)
}
cmd.Env = append(cmd.Env, fmt.Sprintf("SSH_PTY=%s", tty.Name()))
cmd.SysProcAttr = &syscall.SysProcAttr{
Setsid: true,
Setctty: true,
+8 -1
View File
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows
package pty_test
@@ -40,4 +39,12 @@ func TestStart(t *testing.T) {
require.True(t, xerrors.As(err, &exitErr))
assert.NotEqual(t, 0, exitErr.ExitCode())
})
t.Run("SSH_PTY", func(t *testing.T) {
t.Parallel()
pty, ps := ptytest.Start(t, exec.Command("env"))
pty.ExpectMatch("SSH_PTY=/dev/")
err := ps.Wait()
require.NoError(t, err)
})
}