Skip to content

Commit 32b8f25

Browse files
committed
Revert "ssh/tailssh: change to user directory when running login/command"
This reverts commit dc5bc32. It broke tests. (sadly, ones which we have disabled on CI, but go test ./ssh/tailssh broke)
1 parent 6829caf commit 32b8f25

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

ssh/tailssh/incubator.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ func (ss *sshSession) newIncubatorCommand() (cmd *exec.Cmd) {
113113
"--remote-ip=" + ci.src.Addr().String(),
114114
"--has-tty=false", // updated in-place by startWithPTY
115115
"--tty-name=", // updated in-place by startWithPTY
116-
"--pwd=" + ss.conn.localUser.HomeDir,
117116
}
118117

119118
if isSFTP {
@@ -178,7 +177,6 @@ type incubatorArgs struct {
178177
isShell bool
179178
loginCmdPath string
180179
cmdArgs []string
181-
pwd string
182180
}
183181

184182
func parseIncubatorArgs(args []string) (a incubatorArgs) {
@@ -195,7 +193,6 @@ func parseIncubatorArgs(args []string) (a incubatorArgs) {
195193
flags.BoolVar(&a.isShell, "shell", false, "is launching a shell (with no cmds)")
196194
flags.BoolVar(&a.isSFTP, "sftp", false, "run sftp server (cmd is ignored)")
197195
flags.StringVar(&a.loginCmdPath, "login-cmd", "", "the path to `login` cmd")
198-
flags.StringVar(&a.pwd, "pwd", "/", "process initial working directory, if possible. else / is used")
199196
flags.Parse(args)
200197
a.cmdArgs = flags.Args()
201198
return a
@@ -282,12 +279,6 @@ func beIncubator(args []string) error {
282279
cmd.Stderr = os.Stderr
283280
cmd.Env = os.Environ()
284281

285-
if _, err := os.Stat(ia.pwd); err != nil && os.IsNotExist(err) {
286-
cmd.Dir = "/"
287-
} else {
288-
cmd.Dir = ia.pwd
289-
}
290-
291282
if ia.hasTTY {
292283
// If we were launched with a tty then we should
293284
// mark that as the ctty of the child. However,
@@ -437,7 +428,16 @@ func (ss *sshSession) launchProcess() error {
437428
ss.cmd = ss.newIncubatorCommand()
438429

439430
cmd := ss.cmd
440-
431+
homeDir := ss.conn.localUser.HomeDir
432+
if _, err := os.Stat(homeDir); err == nil {
433+
cmd.Dir = homeDir
434+
} else if os.IsNotExist(err) {
435+
// If the home directory doesn't exist, we can't chdir to it.
436+
// Instead, we'll chdir to the root directory.
437+
cmd.Dir = "/"
438+
} else {
439+
return err
440+
}
441441
cmd.Env = envForUser(ss.conn.localUser)
442442
for _, kv := range ss.Environ() {
443443
if acceptEnvPair(kv) {

0 commit comments

Comments
 (0)