new-api: implement Wait, WaitProcess

Signed-off-by: Andrew Vagin <avagin@openvz.org>
This commit is contained in:
Andrew Vagin 2015-01-21 18:41:30 +03:00
parent e79e87e426
commit 61fef16f4a
2 changed files with 21 additions and 20 deletions

View File

@ -5,6 +5,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"strings" "strings"
"syscall"
"testing" "testing"
"github.com/docker/libcontainer" "github.com/docker/libcontainer"
@ -252,11 +253,6 @@ func TestEnter(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
process, err := os.FindProcess(pid)
if err != nil {
t.Fatal(err)
}
// Execute a first process in the container // Execute a first process in the container
stdinR2, stdinW2, err := os.Pipe() stdinR2, stdinW2, err := os.Pipe()
if err != nil { if err != nil {
@ -273,11 +269,6 @@ func TestEnter(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
process2, err := os.FindProcess(pid2)
if err != nil {
t.Fatal(err)
}
processes, err := container.Processes() processes, err := container.Processes()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -293,22 +284,27 @@ func TestEnter(t *testing.T) {
t.Fatal("unexpected number of processes", processes, pid, pid2) t.Fatal("unexpected number of processes", processes, pid, pid2)
} }
// Wait processes
var status syscall.WaitStatus
stdinW2.Close() stdinW2.Close()
s, err := process2.Wait() exitCode, err := container.WaitProcess(pid2)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if !s.Success() { status = syscall.WaitStatus(exitCode)
t.Fatal(s.String()) if status.ExitStatus() != 0 {
t.Fatal(exitCode)
} }
stdinW.Close() stdinW.Close()
s, err = process.Wait() exitCode, err = container.WaitProcess(pid)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if !s.Success() { status = syscall.WaitStatus(exitCode)
t.Fatal(s.String()) if status.ExitStatus() != 0 {
t.Fatal(exitCode)
} }
// Check that both processes live in the same pidns // Check that both processes live in the same pidns

View File

@ -181,11 +181,16 @@ func (c *linuxContainer) Signal(pid, signal int) error {
} }
func (c *linuxContainer) Wait() (int, error) { func (c *linuxContainer) Wait() (int, error) {
glog.Info("wait container") return c.WaitProcess(c.state.InitPid)
panic("not implemented")
} }
func (c *linuxContainer) WaitProcess(pid int) (int, error) { func (c *linuxContainer) WaitProcess(pid int) (int, error) {
glog.Infof("wait process %d", pid) var status syscall.WaitStatus
panic("not implemented")
_, err := syscall.Wait4(pid, &status, 0, nil)
if err != nil {
return -1, newGenericError(err, SystemError)
}
return int(status), err
} }