killProcessOnContextDone waits for ss.ctx to be done and kills the process, unless the process has already exited.
()
| 863 | // killProcessOnContextDone waits for ss.ctx to be done and kills the process, |
| 864 | // unless the process has already exited. |
| 865 | func (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. |
| 888 | func (c *conn) attachSession(ss *sshSession) { |
no test coverage detected