| 284 | } |
| 285 | |
| 286 | func (s *Server) exitWithError(sess ssh.Session, err error) { |
| 287 | if err != nil { |
| 288 | causeErr := errors.Cause(err) |
| 289 | if causeErr != nil { |
| 290 | if _, ok := err.(*exec.ExitError); !ok { |
| 291 | _, _ = sess.Stderr().Write([]byte(err.Error() + "\n")) |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | s.log.Debugf("%v", err) |
| 296 | } |
| 297 | |
| 298 | // always exit session |
| 299 | err = sess.Exit(sshhelper.ExitCode(err)) |
| 300 | if err != nil { |
| 301 | s.log.Debugf("session failed to exit: %v", err) |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | func (s *Server) ListenAndServe(ctx context.Context) error { |
| 306 | go func() { |