Skip to content

Commit

Permalink
Cleanup mounts if we fail to mount one element of rootfs
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Campbell <ian.campbell@docker.com>
  • Loading branch information
ijc committed Jul 20, 2017
1 parent 8b36511 commit 300f083
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions linux/shim/init.go
Expand Up @@ -72,22 +72,23 @@ func newInitProcess(context context.Context, path, namespace string, r *shimapi.
// what was actually done rather than what should have been
// done.
nrRootMounts := 0
cleanupMounts := func() {
if err2 := mount.UnmountN(rootfs, 0, nrRootMounts); err2 != nil {
log.G(context).WithError(err2).Warn("Failed to cleanup rootfs mount")
}
}
for _, rm := range r.Rootfs {
m := &mount.Mount{
Type: rm.Type,
Source: rm.Source,
Options: rm.Options,
}
if err := m.Mount(rootfs); err != nil {
cleanupMounts()
return nil, errors.Wrapf(err, "failed to mount rootfs component %v", m)
}
nrRootMounts++
}
cleanupMounts := func() {
if err2 := mount.UnmountN(rootfs, 0, nrRootMounts); err2 != nil {
log.G(context).WithError(err2).Warn("Failed to cleanup rootfs mount")
}
}
runtime := &runc.Runc{
Command: r.Runtime,
Log: filepath.Join(path, "log.json"),
Expand Down

0 comments on commit 300f083

Please sign in to comment.