in chefctl/src/chefctl.rb [745:776]
def wait_for_lock(timeout = -1)
endtime = Time.now + timeout
open_for_writing = false
loop do
unless open_for_writing
begin
@lock[:fd] = File.open(@lock[:file], 'a+')
open_for_writing = true
rescue Errno::EACCES
open_for_writing = false
end
end
if open_for_writing
acquired = @lock[:fd].flock(File::LOCK_EX | File::LOCK_NB)
return true if acquired
end
if Time.now >= endtime
@lock[:fd].close if open_for_writing
return false
else
sleep 2
end
end
end