Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
agent: Reap child processes during the pod lifecycle
Browse files Browse the repository at this point in the history
All processes started by libcontainer leave a defunct process behind.
This process is a child from our agent and has to be reaped before we
wait for the end of every process.

Fixes #71

Signed-off-by: Sebastien Boeuf <[email protected]>
  • Loading branch information
Sebastien Boeuf committed Aug 8, 2017
1 parent 3a858b9 commit 56aca91
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,11 @@ func (p *pod) runContainerProcess(cid, pid string, terminal bool, started chan e
}
}

if err := reapChildProcesses(); err != nil {
agentLog.Errorf("Could not reap the child: %v", err)
return err
}

started <- nil

processState, err := p.containers[cid].processes[pid].process.Wait()
Expand All @@ -706,6 +711,7 @@ func (p *pod) runContainerProcess(cid, pid string, terminal bool, started chan e
// Get exit code
exitCode := uint8(255)
if processState != nil {
agentLog.Infof("ProcessState: %+v", processState)
if waitStatus, ok := processState.Sys().(syscall.WaitStatus); ok {
exitCode = uint8(waitStatus.ExitStatus())
}
Expand All @@ -717,6 +723,20 @@ func (p *pod) runContainerProcess(cid, pid string, terminal bool, started chan e
return nil
}

func reapChildProcesses() error {
var ws unix.WaitStatus
var rus unix.Rusage

pid, err := unix.Wait4(0, &ws, 0, &rus)
if err != nil {
return err
}

agentLog.Infof("Process %d reaped", pid)

return nil
}

func (p *pod) buildProcessWithoutTerminal(proc *process) (*process, error) {
rStdin, wStdin, err := os.Pipe()
if err != nil {
Expand Down

0 comments on commit 56aca91

Please sign in to comment.