summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Shook <keith.shook@ontariosystems.com>2013-01-31 15:10:40 -0500
committerBryan McLellan <btm@opscode.com>2013-02-07 08:21:17 -0800
commitbb79b523a445ccdff9b75e8c92c681fc685c46e4 (patch)
tree586d9974c199477ac90e6b3bbb5846ab8ff17a5c
parent8b2e0d46506c6744ddc8fe918f830795aa53c73b (diff)
downloadchef-bb79b523a445ccdff9b75e8c92c681fc685c46e4.tar.gz
[CHEF-3809] Attached missing win32 CloseHandle function
-rw-r--r--lib/chef/win32/api/process.rb1
-rw-r--r--lib/chef/win32/handle.rb9
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/chef/win32/api/process.rb b/lib/chef/win32/api/process.rb
index d18ad411b4..0aca992ed5 100644
--- a/lib/chef/win32/api/process.rb
+++ b/lib/chef/win32/api/process.rb
@@ -33,6 +33,7 @@ class Chef
safe_attach_function :GetCurrentProcess, [], :HANDLE
safe_attach_function :GetProcessHandleCount, [ :HANDLE, :LPDWORD ], :BOOL
safe_attach_function :GetProcessId, [ :HANDLE ], :DWORD
+ safe_attach_function :CloseHandle, [ :HANDLE ], :BOOL
end
end
diff --git a/lib/chef/win32/handle.rb b/lib/chef/win32/handle.rb
index 60e35916ad..3e92703db9 100644
--- a/lib/chef/win32/handle.rb
+++ b/lib/chef/win32/handle.rb
@@ -26,6 +26,10 @@ class Chef
class Handle
extend Chef::ReservedNames::Win32::API::Process
+ # See http://msdn.microsoft.com/en-us/library/windows/desktop/ms683179(v=vs.85).aspx
+ # The handle value returned by the GetCurrentProcess function is the pseudo handle (HANDLE)-1 (which is 0xFFFFFFFF)
+ CURRENT_PROCESS_HANDLE = 4294967295
+
def initialize(handle)
@handle = handle
ObjectSpace.define_finalizer(self, Handle.close_handle_finalizer(handle))
@@ -34,7 +38,10 @@ class Chef
attr_reader :handle
def self.close_handle_finalizer(handle)
- proc { close_handle(handle) }
+ # According to http://msdn.microsoft.com/en-us/library/windows/desktop/ms683179(v=vs.85).aspx, it is not necessary
+ # to close the pseudo handle returned by the GetCurrentProcess function. The docs also say that it doesn't hurt to call
+ # CloseHandle on it. However, doing so from inside of Ruby always seems to produce an invalid handle error.
+ proc { close_handle(handle) unless handle == CURRENT_PROCESS_HANDLE }
end
def self.close_handle(handle)