pkg: chrootarchive: chroot_linux: fix docker build
The path we're trying to remove doesn't exist after a successful chroot+chdir because a / is only appended after pivot_root is successful and so we can't cleanup anymore with the old path. Also fix leaking .pivot_root dirs under /var/lib/docker/tmp/docker-builder* on error. Fix https://github.com/docker/docker/issues/22587 Introduced by https://github.com/docker/docker/pull/22506 Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
8a7fc5c59d
commit
3c6c907299
1 changed files with 8 additions and 3 deletions
|
@ -43,7 +43,9 @@ func chroot(path string) (err error) {
|
|||
}
|
||||
|
||||
errCleanup := os.Remove(pivotDir)
|
||||
if errCleanup != nil {
|
||||
// pivotDir doesn't exist if pivot_root failed and chroot+chdir was successful
|
||||
// but we already cleaned it up on failed pivot_root
|
||||
if errCleanup != nil && !os.IsNotExist(errCleanup) {
|
||||
errCleanup = fmt.Errorf("Error cleaning up after pivot: %v", errCleanup)
|
||||
if err == nil {
|
||||
err = errCleanup
|
||||
|
@ -52,7 +54,10 @@ func chroot(path string) (err error) {
|
|||
}()
|
||||
|
||||
if err := syscall.PivotRoot(path, pivotDir); err != nil {
|
||||
// If pivot fails, fall back to the normal chroot
|
||||
// If pivot fails, fall back to the normal chroot after cleaning up temp dir for pivot_root
|
||||
if err := os.Remove(pivotDir); err != nil {
|
||||
return fmt.Errorf("Error cleaning up after failed pivot: %v", err)
|
||||
}
|
||||
return realChroot(path)
|
||||
}
|
||||
mounted = true
|
||||
|
@ -84,7 +89,7 @@ func realChroot(path string) error {
|
|||
return fmt.Errorf("Error after fallback to chroot: %v", err)
|
||||
}
|
||||
if err := syscall.Chdir("/"); err != nil {
|
||||
return fmt.Errorf("Error chaning to new root after chroot: %v", err)
|
||||
return fmt.Errorf("Error changing to new root after chroot: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue