Wait for all exec process child before exiting from shim

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
Kenfe-Mickael Laventure 2016-09-12 11:22:48 -07:00
parent 920a9c21d7
commit 18c76025a1
2 changed files with 10 additions and 3 deletions

View file

@ -106,7 +106,7 @@ func start(log *os.File) error {
case s := <-signals:
switch s {
case syscall.SIGCHLD:
exits, _ := osutils.Reap()
exits, _ := osutils.Reap(false)
for _, e := range exits {
// check to see if runtime is one of the processes that has exited
if e.Pid == p.pid() {
@ -117,6 +117,9 @@ func start(log *os.File) error {
}
// runtime has exited so the shim can also exit
if exitShim {
// Wait for all the childs this process may have created
// (only needed for exec, but it won't hurt when done on init)
osutils.Reap(true)
// Let containerd take care of calling the runtime delete
f.Close()
p.Wait()

View file

@ -12,13 +12,17 @@ type Exit struct {
// Reap reaps all child processes for the calling process and returns their
// exit information
func Reap() (exits []Exit, err error) {
func Reap(wait bool) (exits []Exit, err error) {
var (
ws syscall.WaitStatus
rus syscall.Rusage
)
flag := syscall.WNOHANG
if wait {
flag = 0
}
for {
pid, err := syscall.Wait4(-1, &ws, syscall.WNOHANG, &rus)
pid, err := syscall.Wait4(-1, &ws, flag, &rus)
if err != nil {
if err == syscall.ECHILD {
return exits, nil