new-api: implement Wait, WaitProcess
Signed-off-by: Andrew Vagin <avagin@openvz.org>
This commit is contained in:
parent
e79e87e426
commit
61fef16f4a
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue