mirror of
https://github.com/Gu1llaum-3/sshm.git
synced 2026-03-13 19:31:44 +01:00
fix: replace sshm process with ssh via syscall.Exec (issue #41)
When running `sshm <host>`, the sshm process was staying alive as a parent for the entire SSH session. History is recorded before SSH starts, so the parent process served no purpose. Use syscall.Exec() to replace the sshm process in-place with ssh, keeping the same PID. Falls back to exec.Command() on Windows where syscall.Exec is not supported.
This commit is contained in:
@@ -196,6 +196,15 @@ func connectToHost(hostName string, remoteCommand []string) {
|
||||
fmt.Printf("Connecting to %s...\n", hostName)
|
||||
}
|
||||
|
||||
sshPath, lookErr := exec.LookPath("ssh")
|
||||
if lookErr == nil {
|
||||
argv := append([]string{"ssh"}, args...)
|
||||
// On Unix, Exec replaces the process and never returns on success.
|
||||
// On Windows, Exec is not supported and returns an error; fall through to the exec.Command fallback.
|
||||
_ = syscall.Exec(sshPath, argv, os.Environ())
|
||||
}
|
||||
|
||||
// Fallback for Windows or if LookPath failed
|
||||
sshCmd := exec.Command("ssh", args...)
|
||||
sshCmd.Stdin = os.Stdin
|
||||
sshCmd.Stdout = os.Stdout
|
||||
|
||||
Reference in New Issue
Block a user