Commit 2dad0cdc authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/amazon/chroot: block when obtaining lock [GH-689]

parent 2385f087
...@@ -11,6 +11,8 @@ BUG FIXES: ...@@ -11,6 +11,8 @@ BUG FIXES:
* core: Don't change background color on CLI anymore, making things look * core: Don't change background color on CLI anymore, making things look
a tad nicer in some terminals. 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 * builder/vmware: Cleanup of VMX keys works properly so cd-rom won't
get stuck with ISO. [GH-685] get stuck with ISO. [GH-685]
......
...@@ -14,13 +14,8 @@ const LOCK_NB = 4 ...@@ -14,13 +14,8 @@ const LOCK_NB = 4
const LOCK_UN = 8 const LOCK_UN = 8
func lockFile(f *os.File) error { 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 { if err != nil {
errno, ok := err.(syscall.Errno)
if ok && errno == syscall.EWOULDBLOCK {
return errors.New("file already locked")
}
return err return err
} }
......
...@@ -39,7 +39,7 @@ func (s *StepFlock) Run(state multistep.StateBag) multistep.StepAction { ...@@ -39,7 +39,7 @@ func (s *StepFlock) Run(state multistep.StateBag) multistep.StepAction {
// LOCK! // LOCK!
if err := lockFile(f); err != nil { 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) state.Put("error", err)
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment