@@ -61,6 +61,7 @@ type MuxPortForwarding struct {
6161 session session.Session
6262 muxClient * MuxClient
6363 mgsConn * MgsConn
64+ out io.Writer
6465}
6566
6667func (c * MgsConn ) close () {
@@ -131,7 +132,7 @@ func (p *MuxPortForwarding) WriteStream(outputMessage message.ClientMessage) err
131132 binary .Read (buf , binary .BigEndian , & flag )
132133
133134 if message .ConnectToPortError == flag {
134- fmt .Printf ( "\n Connection to destination port failed, check SSM Agent logs.\n " )
135+ fmt .Fprintf ( p . out , "\n Connection to destination port failed, check SSM Agent logs.\n " )
135136 }
136137 }
137138 return nil
@@ -190,12 +191,12 @@ func (p *MuxPortForwarding) handleControlSignals(log log.T) {
190191 signal .Notify (c , sessionutil .ControlSignals ... )
191192 go func () {
192193 <- c
193- fmt .Println ( "Terminate signal received, exiting." )
194+ fmt .Fprintln ( p . out , "Terminate signal received, exiting." )
194195
195196 if err := p .session .DataChannel .SendFlag (log , message .TerminateSession ); err != nil {
196197 log .Errorf ("Failed to send TerminateSession flag: %v" , err )
197198 }
198- fmt .Fprintf (os . Stdout , "\n \n Exiting session with sessionId: %s.\n \n " , p .sessionId )
199+ fmt .Fprintf (p . out , "\n \n Exiting session with sessionId: %s.\n \n " , p .sessionId )
199200 p .Stop ()
200201 }()
201202}
@@ -252,10 +253,10 @@ func (p *MuxPortForwarding) handleClientConnections(log log.T, ctx context.Conte
252253 defer listener .Close ()
253254
254255 log .Infof (displayMsg )
255- fmt .Printf ( displayMsg )
256+ fmt .Fprintf ( p . out , displayMsg )
256257
257258 log .Infof ("Waiting for connections...\n " )
258- fmt .Printf ( "\n Waiting for connections...\n " )
259+ fmt .Fprintf ( p . out , "\n Waiting for connections...\n " )
259260
260261 var once sync.Once
261262 for {
@@ -269,7 +270,7 @@ func (p *MuxPortForwarding) handleClientConnections(log log.T, ctx context.Conte
269270 log .Infof ("Connection accepted from %s\n for session [%s]" , conn .RemoteAddr (), p .sessionId )
270271
271272 once .Do (func () {
272- fmt .Printf ( "\n Connection accepted for session [%s]\n " , p .sessionId )
273+ fmt .Fprintf ( p . out , "\n Connection accepted for session [%s]\n " , p .sessionId )
273274 })
274275
275276 stream , err := p .muxClient .session .OpenStream ()
0 commit comments