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:
parent
920a9c21d7
commit
18c76025a1
2 changed files with 10 additions and 3 deletions
|
@ -106,7 +106,7 @@ func start(log *os.File) error {
|
||||||
case s := <-signals:
|
case s := <-signals:
|
||||||
switch s {
|
switch s {
|
||||||
case syscall.SIGCHLD:
|
case syscall.SIGCHLD:
|
||||||
exits, _ := osutils.Reap()
|
exits, _ := osutils.Reap(false)
|
||||||
for _, e := range exits {
|
for _, e := range exits {
|
||||||
// check to see if runtime is one of the processes that has exited
|
// check to see if runtime is one of the processes that has exited
|
||||||
if e.Pid == p.pid() {
|
if e.Pid == p.pid() {
|
||||||
|
@ -117,6 +117,9 @@ func start(log *os.File) error {
|
||||||
}
|
}
|
||||||
// runtime has exited so the shim can also exit
|
// runtime has exited so the shim can also exit
|
||||||
if exitShim {
|
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
|
// Let containerd take care of calling the runtime delete
|
||||||
f.Close()
|
f.Close()
|
||||||
p.Wait()
|
p.Wait()
|
||||||
|
|
|
@ -12,13 +12,17 @@ type Exit struct {
|
||||||
|
|
||||||
// Reap reaps all child processes for the calling process and returns their
|
// Reap reaps all child processes for the calling process and returns their
|
||||||
// exit information
|
// exit information
|
||||||
func Reap() (exits []Exit, err error) {
|
func Reap(wait bool) (exits []Exit, err error) {
|
||||||
var (
|
var (
|
||||||
ws syscall.WaitStatus
|
ws syscall.WaitStatus
|
||||||
rus syscall.Rusage
|
rus syscall.Rusage
|
||||||
)
|
)
|
||||||
|
flag := syscall.WNOHANG
|
||||||
|
if wait {
|
||||||
|
flag = 0
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
pid, err := syscall.Wait4(-1, &ws, syscall.WNOHANG, &rus)
|
pid, err := syscall.Wait4(-1, &ws, flag, &rus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == syscall.ECHILD {
|
if err == syscall.ECHILD {
|
||||||
return exits, nil
|
return exits, nil
|
||||||
|
|
Loading…
Reference in a new issue