Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec6645b

Browse files
authored
chore: add parent PID to coder ssh log file name (coder#16080)
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. See also coder#16078.
1 parent 838ee3b commit ec6645b

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

cli/ssh.go

+19-11
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,26 @@ func (r *RootCmd) ssh() *serpent.Command {
131131
if err != nil {
132132
return xerrors.Errorf("generate nonce: %w", err)
133133
}
134-
logFilePath := filepath.Join(
135-
logDirPath,
136-
fmt.Sprintf(
137-
"coder-ssh-%s-%s.log",
138-
// The time portion makes it easier to find the right
139-
// log file.
140-
time.Now().Format("20060102-150405"),
141-
// The nonce prevents collisions, as SSH invocations
142-
// frequently happen in parallel.
143-
nonce,
144-
),
134+
logFileBaseName := fmt.Sprintf(
135+
"coder-ssh-%s-%s",
136+
// The time portion makes it easier to find the right
137+
// log file.
138+
time.Now().Format("20060102-150405"),
139+
// The nonce prevents collisions, as SSH invocations
140+
// frequently happen in parallel.
141+
nonce,
145142
)
143+
if stdio {
144+
// The VS Code extension obtains the PID of the SSH process to
145+
// find the log file associated with a SSH session.
146+
//
147+
// We get the parent PID because it's assumed `ssh` is calling this
148+
// command via the ProxyCommand SSH option.
149+
logFileBaseName += fmt.Sprintf("-%d", os.Getppid())
150+
}
151+
logFileBaseName += ".log"
152+
153+
logFilePath := filepath.Join(logDirPath, logFileBaseName)
146154
logFile, err := os.OpenFile(
147155
logFilePath,
148156
os.O_CREATE|os.O_APPEND|os.O_WRONLY|os.O_EXCL,

0 commit comments

Comments
 (0)