Skip to content

Commit 52ab6f6

Browse files
committed
chore: add parent PID to coder ssh log file name
Part of bringing coder ssh to parity with coder vscodessh is associating the log files with a particular parent process (in this case, the ssh process that spawned the coder CLI via ProxyCommand). coder vscodessh named log files using the parent PID, but coder ssh is missing this. Add the parent PID to the log file name when used in stdio mode so that the VS Code extension will be able to identify the correct log file.
1 parent 6ca1e59 commit 52ab6f6

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

cli/ssh.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,26 @@ func (r *RootCmd) ssh() *serpent.Command {
124124
if err != nil {
125125
return xerrors.Errorf("generate nonce: %w", err)
126126
}
127-
logFilePath := filepath.Join(
128-
logDirPath,
129-
fmt.Sprintf(
130-
"coder-ssh-%s-%s.log",
131-
// The time portion makes it easier to find the right
132-
// log file.
133-
time.Now().Format("20060102-150405"),
134-
// The nonce prevents collisions, as SSH invocations
135-
// frequently happen in parallel.
136-
nonce,
137-
),
127+
logFileBaseName := fmt.Sprintf(
128+
"coder-ssh-%s-%s",
129+
// The time portion makes it easier to find the right
130+
// log file.
131+
time.Now().Format("20060102-150405"),
132+
// The nonce prevents collisions, as SSH invocations
133+
// frequently happen in parallel.
134+
nonce,
138135
)
136+
if stdio {
137+
// The VS Code extension obtains the PID of the SSH process to
138+
// find the log file associated with a SSH session.
139+
//
140+
// We get the parent PID because it's assumed `ssh` is calling this
141+
// command via the ProxyCommand SSH option.
142+
logFileBaseName += fmt.Sprintf("-%d", os.Getppid())
143+
}
144+
logFileBaseName += ".log"
145+
146+
logFilePath := filepath.Join(logDirPath, logFileBaseName)
139147
logFile, err := os.OpenFile(
140148
logFilePath,
141149
os.O_CREATE|os.O_APPEND|os.O_WRONLY|os.O_EXCL,

0 commit comments

Comments
 (0)