diff --git a/integration/exec_test.go b/integration/exec_test.go index faa3fc15..8132e25b 100644 --- a/integration/exec_test.go +++ b/integration/exec_test.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "os" "strings" + "syscall" "testing" "github.com/docker/libcontainer" @@ -252,11 +253,6 @@ func TestEnter(t *testing.T) { t.Fatal(err) } - process, err := os.FindProcess(pid) - if err != nil { - t.Fatal(err) - } - // Execute a first process in the container stdinR2, stdinW2, err := os.Pipe() if err != nil { @@ -273,11 +269,6 @@ func TestEnter(t *testing.T) { t.Fatal(err) } - process2, err := os.FindProcess(pid2) - if err != nil { - t.Fatal(err) - } - processes, err := container.Processes() if err != nil { t.Fatal(err) @@ -293,22 +284,27 @@ func TestEnter(t *testing.T) { t.Fatal("unexpected number of processes", processes, pid, pid2) } + // Wait processes + var status syscall.WaitStatus + stdinW2.Close() - s, err := process2.Wait() + exitCode, err := container.WaitProcess(pid2) if err != nil { t.Fatal(err) } - if !s.Success() { - t.Fatal(s.String()) + status = syscall.WaitStatus(exitCode) + if status.ExitStatus() != 0 { + t.Fatal(exitCode) } stdinW.Close() - s, err = process.Wait() + exitCode, err = container.WaitProcess(pid) if err != nil { t.Fatal(err) } - if !s.Success() { - t.Fatal(s.String()) + status = syscall.WaitStatus(exitCode) + if status.ExitStatus() != 0 { + t.Fatal(exitCode) } // Check that both processes live in the same pidns diff --git a/linux_container.go b/linux_container.go index 971ebd3e..e5c6826a 100644 --- a/linux_container.go +++ b/linux_container.go @@ -181,11 +181,16 @@ func (c *linuxContainer) Signal(pid, signal int) error { } func (c *linuxContainer) Wait() (int, error) { - glog.Info("wait container") - panic("not implemented") + return c.WaitProcess(c.state.InitPid) } func (c *linuxContainer) WaitProcess(pid int) (int, error) { - glog.Infof("wait process %d", pid) - panic("not implemented") + var status syscall.WaitStatus + + _, err := syscall.Wait4(pid, &status, 0, nil) + if err != nil { + return -1, newGenericError(err, SystemError) + } + + return int(status), err }