summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc A. Paradise <marcparadise@users.noreply.github.com>2022-10-10 12:40:41 +0000
committerGitHub <noreply@github.com>2022-10-10 12:40:41 +0000
commita54c85c058c0a0faec4bb4eb7d32d6d201b8925e (patch)
tree850c0e3dcc4c076471cfe3a74f8f7e93591d7972
parente9c2a8b884d42a6427e7bfb28b8dcb344a10871e (diff)
parentdb595dca23b18e3da882b105b22679a0d2e1433c (diff)
downloadchef-a54c85c058c0a0faec4bb4eb7d32d6d201b8925e.tar.gz
Merge pull request #13229 from chef/mp/pipeline-workaround-server2012-2
Do not raise if we can't close win resource handle
-rw-r--r--lib/chef/win32/handle.rb13
-rw-r--r--spec/unit/platform/query_helpers_spec.rb4
2 files changed, 6 insertions, 11 deletions
diff --git a/lib/chef/win32/handle.rb b/lib/chef/win32/handle.rb
index 1b0257ed68..a677b4021e 100644
--- a/lib/chef/win32/handle.rb
+++ b/lib/chef/win32/handle.rb
@@ -26,10 +26,6 @@ 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))
@@ -38,13 +34,16 @@ class Chef
attr_reader :handle
def self.close_handle_finalizer(handle)
+ proc { close_handle(handle) }
+ end
+
+ def self.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
+ # The recommendation is to use GetCurrentProcess instead of the const (HANDLE)-1, to ensure we're making the correct comparison.
+ return if handle == GetCurrentProcess()
- def self.close_handle(handle)
unless CloseHandle(handle)
Chef::ReservedNames::Win32::Error.raise!
end
diff --git a/spec/unit/platform/query_helpers_spec.rb b/spec/unit/platform/query_helpers_spec.rb
index 424bd6348b..0671d98476 100644
--- a/spec/unit/platform/query_helpers_spec.rb
+++ b/spec/unit/platform/query_helpers_spec.rb
@@ -41,12 +41,8 @@ end
describe "Chef::Platform#dsc_refresh_mode_disabled?", :windows_only do
let(:node) { instance_double("Chef::Node") }
- let(:powershell) { Class.new { include ChefPowerShell::ChefPowerShellModule::PowerShellExec } }
- subject(:object) { powershell.new }
it "returns true when RefreshMode is Disabled" do
- execution = object.powershell_exec("Get-DscLocalConfigurationManager", :powershell, timeout: -1)
- expect(execution.result["RefreshMode"]).to eq "PUSH"
expect(Chef::Platform.dsc_refresh_mode_disabled?(node)).to be false
end
end