diff options
author | Kevin Krakauer <krakauer@google.com> | 2018-06-28 14:55:46 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-06-28 14:56:36 -0700 |
commit | 16d37973ebc8f36ef613c0885879648cceaf1c45 (patch) | |
tree | c797f2c9352518b5372e961b74a6ae14f56fc307 /runsc/sandbox/sandbox.go | |
parent | 5a8e014c3d424abfe931b8493d06a129c3fdd388 (diff) |
runsc: Add the "wait" subcommand.
Users can now call "runsc wait <container id>" to wait on a particular process
inside the container. -pid can also be used to wait on a specific PID.
Manually tested the wait subcommand for a single waiter and multiple waiters
(simultaneously 2 processes waiting on the container and 2 processes waiting on
a PID within the container).
PiperOrigin-RevId: 202548978
Change-Id: Idd507c2cdea613c3a14879b51cfb0f7ea3fb3d4c
Diffstat (limited to 'runsc/sandbox/sandbox.go')
-rw-r--r-- | runsc/sandbox/sandbox.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/runsc/sandbox/sandbox.go b/runsc/sandbox/sandbox.go index e1e7b39d1..9200fbee9 100644 --- a/runsc/sandbox/sandbox.go +++ b/runsc/sandbox/sandbox.go @@ -432,7 +432,29 @@ func (s *Sandbox) Wait(cid string) (syscall.WaitStatus, error) { defer conn.Close() if err := conn.Call(boot.ContainerWait, &cid, &ws); err != nil { - return ws, fmt.Errorf("err waiting on container %q: %v", cid, err) + return ws, fmt.Errorf("error waiting on container %q: %v", cid, err) + } + return ws, nil +} + +// WaitPID waits for process 'pid' in the container's sandbox and returns its +// WaitStatus. +func (s *Sandbox) WaitPID(pid int32, cid string) (syscall.WaitStatus, error) { + log.Debugf("Waiting for PID %d in sandbox %q", pid, s.ID) + var ws syscall.WaitStatus + conn, err := s.connect() + if err != nil { + return ws, err + } + defer conn.Close() + + args := &boot.WaitPIDArgs{ + PID: pid, + CID: cid, + } + + if err := conn.Call(boot.ContainerWaitPID, args, &ws); err != nil { + return ws, fmt.Errorf("error waiting on PID %d in sandbox %q: %v", pid, s.ID, err) } if s.IsRootContainer(cid) { |