Forward correct exit status to client (#1)

This commit is contained in:
Axel Wagner 2018-10-25 12:49:32 +02:00 committed by Michael Stapelberg
parent a1fd5f6920
commit 77088e03a7

7
ssh.go
View File

@ -194,13 +194,16 @@ func (s *session) request(ctx context.Context, req *ssh.Request) error {
}()
go func() {
// TODO: correctly pass on the exit code, currently it is always 255
if err := cmd.Wait(); err != nil {
log.Printf("err: %v", err)
}
status := make([]byte, 4)
if ws, ok := cmd.ProcessState.Sys().(syscall.WaitStatus); ok {
binary.BigEndian.PutUint32(status, uint32(ws.ExitStatus()))
}
// See https://tools.ietf.org/html/rfc4254#section-6.10
if _, err := s.channel.SendRequest("exit-status", false /* wantReply */, []byte("\x00\x00\x00\x00")); err != nil {
if _, err := s.channel.SendRequest("exit-status", false /* wantReply */, status); err != nil {
log.Printf("err2: %v", err)
}
s.channel.Close()