Merge pull request #837 from mlaventure/fix-reaper-monitor
Make reaper.Monitor returns an error when exit code is not 0
This commit is contained in:
		@@ -9,6 +9,7 @@ import (
 | 
				
			|||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/containerd/containerd/sys"
 | 
						"github.com/containerd/containerd/sys"
 | 
				
			||||||
 | 
						"github.com/pkg/errors"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Reap should be called when the process receives an SIGCHLD.  Reap will reap
 | 
					// Reap should be called when the process receives an SIGCHLD.  Reap will reap
 | 
				
			||||||
@@ -57,10 +58,8 @@ func (m *Monitor) CombinedOutput(c *exec.Cmd) ([]byte, error) {
 | 
				
			|||||||
	var b bytes.Buffer
 | 
						var b bytes.Buffer
 | 
				
			||||||
	c.Stdout = &b
 | 
						c.Stdout = &b
 | 
				
			||||||
	c.Stderr = &b
 | 
						c.Stderr = &b
 | 
				
			||||||
	if err := m.Run(c); err != nil {
 | 
						err := m.Run(c)
 | 
				
			||||||
		return nil, err
 | 
						return b.Bytes(), err
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return b.Bytes(), nil
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Start starts the command a registers the process with the reaper
 | 
					// Start starts the command a registers the process with the reaper
 | 
				
			||||||
@@ -111,7 +110,11 @@ func (m *Monitor) WaitPid(pid int) (int, error) {
 | 
				
			|||||||
	if !ok {
 | 
						if !ok {
 | 
				
			||||||
		return 255, fmt.Errorf("process does not exist")
 | 
							return 255, fmt.Errorf("process does not exist")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return <-rc.ExitCh, nil
 | 
						ec := <-rc.ExitCh
 | 
				
			||||||
 | 
						if ec != 0 {
 | 
				
			||||||
 | 
							return ec, errors.Errorf("exit status %d", ec)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return ec, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Cmd struct {
 | 
					type Cmd struct {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user