From 2dad0cdca76021765cc36e8c2974132e22ec4fb4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 6 Dec 2013 18:28:48 -0800 Subject: [PATCH] builder/amazon/chroot: block when obtaining lock [GH-689] --- CHANGELOG.md | 2 ++ builder/amazon/chroot/lockfile_unix.go | 7 +------ builder/amazon/chroot/step_flock.go | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22bea8053..6f7d06a3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ BUG FIXES: * core: Don't change background color on CLI anymore, making things look a tad nicer in some terminals. +* builder/amazon/chroot: Block when obtaining file lock to allow + parallel builds. [GH-689] * builder/vmware: Cleanup of VMX keys works properly so cd-rom won't get stuck with ISO. [GH-685] diff --git a/builder/amazon/chroot/lockfile_unix.go b/builder/amazon/chroot/lockfile_unix.go index f84ea0d57..1a389adb4 100644 --- a/builder/amazon/chroot/lockfile_unix.go +++ b/builder/amazon/chroot/lockfile_unix.go @@ -14,13 +14,8 @@ const LOCK_NB = 4 const LOCK_UN = 8 func lockFile(f *os.File) error { - err := syscall.Flock(int(f.Fd()), LOCK_EX|LOCK_NB) + err := syscall.Flock(int(f.Fd()), LOCK_EX) if err != nil { - errno, ok := err.(syscall.Errno) - if ok && errno == syscall.EWOULDBLOCK { - return errors.New("file already locked") - } - return err } diff --git a/builder/amazon/chroot/step_flock.go b/builder/amazon/chroot/step_flock.go index 989bd3930..9f7ca54b8 100644 --- a/builder/amazon/chroot/step_flock.go +++ b/builder/amazon/chroot/step_flock.go @@ -39,7 +39,7 @@ func (s *StepFlock) Run(state multistep.StateBag) multistep.StepAction { // LOCK! if err := lockFile(f); err != nil { - err := fmt.Errorf("Error creating lock: %s", err) + err := fmt.Errorf("Error obtaining lock: %s", err) state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt