MCPcopy Create free account
hub / github.com/tailscale/tailscale / killProcessOnContextDone

Method killProcessOnContextDone

ssh/tailssh/tailssh.go:865–885  ·  view source on GitHub ↗

killProcessOnContextDone waits for ss.ctx to be done and kills the process, unless the process has already exited.

()

Source from the content-addressed store, hash-verified

863// killProcessOnContextDone waits for ss.ctx to be done and kills the process,
864// unless the process has already exited.
865func (ss *sshSession) killProcessOnContextDone() {
866 defer close(ss.exitHandled)
867 <-ss.ctx.Done()
868 // Either the process has already exited, in which case this does nothing.
869 // Or, the process is still running in which case this will kill it.
870 ss.exitOnce.Do(func() {
871 err := context.Cause(ss.ctx)
872 if serr, ok := err.(SSHTerminationError); ok {
873 msg := serr.SSHTerminationMessage()
874 if msg != "" {
875 io.WriteString(ss.Stderr(), "\r\n\r\n"+msg+"\r\n\r\n")
876 }
877 }
878 ss.logf("terminating SSH session from %v: %v", ss.conn.info.src.Addr(), err)
879 // We don't need to Process.Wait here, sshSession.run() does
880 // the waiting regardless of termination reason.
881
882 // TODO(maisem): should this be a SIGTERM followed by a SIGKILL?
883 ss.cmd.Process.Kill()
884 })
885}
886
887// attachSession registers ss as an active session.
888func (c *conn) attachSession(ss *sshSession) {

Callers 1

runMethod · 0.95

Calls 7

WriteStringMethod · 0.80
DoneMethod · 0.65
DoMethod · 0.65
SSHTerminationMessageMethod · 0.65
StderrMethod · 0.65
logfMethod · 0.45
AddrMethod · 0.45

Tested by

no test coverage detected