diff options
author | Keith Shook <keith.shook@ontariosystems.com> | 2013-01-31 15:10:40 -0500 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-02-07 12:02:47 -0800 |
commit | cf127847f2aac42f1d9a44feb5d5ed03da9939ed (patch) | |
tree | b77f9338cc8e4a806379f96d8af58293bbf6f557 | |
parent | e30037e4a616158c2bc918e8ca8441fbba4e5589 (diff) | |
download | chef-10.20.0.tar.gz |
[CHEF-3809] Attached missing win32 CloseHandle function10.20.0
-rw-r--r-- | chef/lib/chef/win32/api/process.rb | 1 | ||||
-rw-r--r-- | chef/lib/chef/win32/handle.rb | 9 |
2 files changed, 9 insertions, 1 deletions
diff --git a/chef/lib/chef/win32/api/process.rb b/chef/lib/chef/win32/api/process.rb index d18ad411b4..0aca992ed5 100644 --- a/chef/lib/chef/win32/api/process.rb +++ b/chef/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/chef/lib/chef/win32/handle.rb b/chef/lib/chef/win32/handle.rb index 60e35916ad..3e92703db9 100644 --- a/chef/lib/chef/win32/handle.rb +++ b/chef/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) |