Destroy container along with processes before stdio

We need to make sure the container is destroyed before closing the stdio
for the container.  This becomes a big issues when running in the host's
pid namespace because the other processes could have inherited the stdio
of the initial process.  The call to close will just block as they still
have the io open.

Calling destroy before closing io, especially in the host pid namespace
will cause all additional processes to be killed in the container's
cgroup.  This will allow the io to be closed successfuly.

This change makes sure the order for destroy and close is correct as
well as ensuring that if any errors encoutered during start or exec will
be handled by terminating the process and destroying the container.  We
cannot use defers here because we need to enforce the correct ordering
on destroy.

This also sets the subreaper setting for runc so that when running in
pid host, runc can wait on the addiontal processes launched by the
container, useful on destroy, but also good for reaping the additional
processes that were launched.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2016-03-14 15:46:08 -07:00
parent be30e557bf
commit fdb100d247
7 changed files with 116 additions and 51 deletions
+5 -2
View File
@@ -68,6 +68,10 @@ using the runc checkpoint command.`,
Value: "",
Usage: "specify the file to write the process id to",
},
cli.BoolFlag{
Name: "no-subreaper",
Usage: "disable the use of the subreaper used to reap reparented processes",
},
},
Action: func(context *cli.Context) {
imagePath := context.String("image-path")
@@ -140,8 +144,7 @@ func restoreContainer(context *cli.Context, spec *specs.Spec, config *configs.Co
return -1, err
}
defer tty.Close()
handler := newSignalHandler(tty)
defer handler.Close()
handler := newSignalHandler(tty, !context.Bool("no-subreaper"))
if err := container.Restore(process, options); err != nil {
return -1, err
}