Skip to content

Commit ac25048

Browse files
committed
update. add StdoutMutex
1 parent cff2274 commit ac25048

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

connect.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net"
1212
"os"
1313
"os/signal"
14+
"sync"
1415
"syscall"
1516
"time"
1617

@@ -53,6 +54,9 @@ type Connect struct {
5354
// Set the TTY to be used as the input and output for the Session/Cmd.
5455
PtyRelayTty *os.File
5556

57+
// StdoutMutex is a mutex for use Stdout.
58+
StdoutMutex *sync.Mutex
59+
5660
// CheckKnownHosts if true, check knownhosts.
5761
// Ignored if HostKeyCallback is set.
5862
// Set it before CraeteClient.

knownhosts.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ func (c *Connect) VerifyAndAppendNew(hostname string, remote net.Addr, key ssh.P
7979
filepath := knownHostsFiles[0]
8080
var line int
8181

82+
// check mutex
83+
if c.StdoutMutex != nil {
84+
c.StdoutMutex.Lock()
85+
defer c.StdoutMutex.Unlock()
86+
}
87+
8288
// check error
8389
keyErr, ok := err.(*knownhosts.KeyError)
8490
if !ok || len(keyErr.Want) > 0 {
@@ -107,7 +113,7 @@ func (c *Connect) VerifyAndAppendNew(hostname string, remote net.Addr, key ssh.P
107113

108114
err = writeKnownHostsKey(filepath, line, hostname, remote, key)
109115

110-
return nil
116+
return err
111117
}
112118

113119
// askAddingUnknownHostKey

0 commit comments

Comments
 (0)