summaryrefslogtreecommitdiffhomepage
path: root/runsc
diff options
context:
space:
mode:
Diffstat (limited to 'runsc')
-rw-r--r--runsc/container/container.go41
-rw-r--r--runsc/sandbox/sandbox.go33
2 files changed, 37 insertions, 37 deletions
diff --git a/runsc/container/container.go b/runsc/container/container.go
index 7f066905a..6a9a07afe 100644
--- a/runsc/container/container.go
+++ b/runsc/container/container.go
@@ -789,30 +789,31 @@ func (c *Container) stop() error {
}
func (c *Container) waitForStopped() error {
+ if c.GoferPid == 0 {
+ return nil
+ }
+
+ if c.IsSandboxRunning() {
+ if err := c.SignalContainer(unix.Signal(0), false); err == nil {
+ return fmt.Errorf("container is still running")
+ }
+ }
+
+ if c.goferIsChild {
+ // The gofer process is a child of the current process,
+ // so we can wait it and collect its zombie.
+ if _, err := unix.Wait4(int(c.GoferPid), nil, 0, nil); err != nil {
+ return fmt.Errorf("error waiting the gofer process: %v", err)
+ }
+ c.GoferPid = 0
+ return nil
+ }
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
b := backoff.WithContext(backoff.NewConstantBackOff(100*time.Millisecond), ctx)
op := func() error {
- if c.IsSandboxRunning() {
- if err := c.SignalContainer(unix.Signal(0), false); err == nil {
- return fmt.Errorf("container is still running")
- }
- }
- if c.GoferPid == 0 {
- return nil
- }
- if c.goferIsChild {
- // The gofer process is a child of the current process,
- // so we can wait it and collect its zombie.
- wpid, err := unix.Wait4(int(c.GoferPid), nil, unix.WNOHANG, nil)
- if err != nil {
- return fmt.Errorf("error waiting the gofer process: %v", err)
- }
- if wpid == 0 {
- return fmt.Errorf("gofer is still running")
- }
-
- } else if err := unix.Kill(c.GoferPid, 0); err == nil {
+ if err := unix.Kill(c.GoferPid, 0); err == nil {
return fmt.Errorf("gofer is still running")
}
c.GoferPid = 0
diff --git a/runsc/sandbox/sandbox.go b/runsc/sandbox/sandbox.go
index 48efbb0b8..5fb7dc834 100644
--- a/runsc/sandbox/sandbox.go
+++ b/runsc/sandbox/sandbox.go
@@ -1157,27 +1157,26 @@ func (s *Sandbox) destroyContainer(cid string) error {
}
func (s *Sandbox) waitForStopped() error {
+ if s.child {
+ s.statusMu.Lock()
+ defer s.statusMu.Unlock()
+ if s.Pid == 0 {
+ return nil
+ }
+ // The sandbox process is a child of the current process,
+ // so we can wait it and collect its zombie.
+ if _, err := unix.Wait4(int(s.Pid), &s.status, 0, nil); err != nil {
+ return fmt.Errorf("error waiting the sandbox process: %v", err)
+ }
+ s.Pid = 0
+ return nil
+ }
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
b := backoff.WithContext(backoff.NewConstantBackOff(100*time.Millisecond), ctx)
op := func() error {
- if s.child {
- s.statusMu.Lock()
- defer s.statusMu.Unlock()
- if s.Pid == 0 {
- return nil
- }
- // The sandbox process is a child of the current process,
- // so we can wait it and collect its zombie.
- wpid, err := unix.Wait4(int(s.Pid), &s.status, unix.WNOHANG, nil)
- if err != nil {
- return fmt.Errorf("error waiting the sandbox process: %v", err)
- }
- if wpid == 0 {
- return fmt.Errorf("sandbox is still running")
- }
- s.Pid = 0
- } else if s.IsRunning() {
+ if s.IsRunning() {
return fmt.Errorf("sandbox is still running")
}
return nil