summaryrefslogtreecommitdiff
path: root/lib/chef/win32/mutex.rb
diff options
context:
space:
mode:
authorsersut <serdar@opscode.com>2013-10-25 12:32:46 -0700
committersersut <serdar@opscode.com>2013-10-25 12:32:46 -0700
commit123c79b1d249e99e50d1002dc543cb8044a0c9ba (patch)
tree775796fd9b321a1bd0ddba604097e893d1ff5cdf /lib/chef/win32/mutex.rb
parentbe67ca1217fde4fce8f1d94870fc0c8d4ec943d7 (diff)
downloadchef-123c79b1d249e99e50d1002dc543cb8044a0c9ba.tar.gz
Ability to process Ctrl+C when waiting for a different chef-client run.
Make sure that we let ruby to process system signals while waiting on system mutex.
Diffstat (limited to 'lib/chef/win32/mutex.rb')
-rw-r--r--lib/chef/win32/mutex.rb32
1 files changed, 21 insertions, 11 deletions
diff --git a/lib/chef/win32/mutex.rb b/lib/chef/win32/mutex.rb
index 3ca0c97ef2..0b7d99f111 100644
--- a/lib/chef/win32/mutex.rb
+++ b/lib/chef/win32/mutex.rb
@@ -42,17 +42,27 @@ class Chef
#####################################################
# Attempts to grab the mutex and waits until it is acquired.
def wait
- wait_result = WaitForSingleObject(handle, INFINITE)
- case wait_result
- when WAIT_ABANDONED
- # Previous owner of the mutex died before it can release the
- # mutex. Log a warning and continue.
- Chef::Log.debug "Existing owner of the mutex exited prematurely."
- when WAIT_OBJECT_0
- # Mutex is successfully acquired.
- else
- Chef::Log.error("Failed to acquire system mutex '#{name}'. Return code: #{wait_result}")
- Chef::ReservedNames::Win32::Error.raise!
+ loop do
+ wait_result = WaitForSingleObject(handle, 1000)
+ case wait_result
+ when WAIT_TIMEOUT
+ # We are periodically waking up in order to give ruby a
+ # chance to process any signal it got while we were
+ # sleeping. This condition shouldn't contain any logic
+ # other than sleeping.
+ sleep 0.1
+ when WAIT_ABANDONED
+ # Previous owner of the mutex died before it can release the
+ # mutex. Log a warning and continue.
+ Chef::Log.debug "Existing owner of the mutex exited prematurely."
+ break
+ when WAIT_OBJECT_0
+ # Mutex is successfully acquired.
+ break
+ else
+ Chef::Log.error("Failed to acquire system mutex '#{name}'. Return code: #{wait_result}")
+ Chef::ReservedNames::Win32::Error.raise!
+ end
end
end