diff options
author | Christoph <cgriesshammer@gmail.com> | 2016-12-06 17:19:20 -0500 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2016-12-06 17:19:20 -0500 |
commit | 205eb04f3e50216d2e1014ffbe8545fba6868890 (patch) | |
tree | 4d068ac5c04257f9e5ee3cbdc929c09107443149 | |
parent | 8d127b7d9ce31581de8f367bbbff8eb3fd0e24f3 (diff) | |
download | chef-205eb04f3e50216d2e1014ffbe8545fba6868890.tar.gz |
Ensures correct version of shutdown is called when using the reboot resource on Windows (#5596)
Use a fixed path to shutdown.exe on windows in Chef::Platform::Rebooter, fixes #5594
Signed-off-by: Christoph Griesshammer <cgriesshammer@gmail.com>
-rw-r--r-- | lib/chef/platform/rebooter.rb | 4 | ||||
-rw-r--r-- | spec/functional/rebooter_spec.rb | 6 |
2 files changed, 6 insertions, 4 deletions
diff --git a/lib/chef/platform/rebooter.rb b/lib/chef/platform/rebooter.rb index 74c8b2da1f..6829b66539 100644 --- a/lib/chef/platform/rebooter.rb +++ b/lib/chef/platform/rebooter.rb @@ -35,7 +35,9 @@ class Chef cmd = if Chef::Platform.windows? # should this do /f as well? do we then need a minimum delay to let apps quit? - "shutdown /r /t #{reboot_info[:delay_mins] * 60} /c \"#{reboot_info[:reason]}\"" + # Use explicit path to shutdown.exe, to protect against https://github.com/chef/chef/issues/5594 + windows_shutdown_path = "#{ENV['SYSTEMROOT']}/System32/shutdown.exe" + "#{windows_shutdown_path} /r /t #{reboot_info[:delay_mins] * 60} /c \"#{reboot_info[:reason]}\"" else # probably Linux-only. "shutdown -r +#{reboot_info[:delay_mins]} \"#{reboot_info[:reason]}\"" diff --git a/spec/functional/rebooter_spec.rb b/spec/functional/rebooter_spec.rb index 0006f3bcdb..1b6e95b39c 100644 --- a/spec/functional/rebooter_spec.rb +++ b/spec/functional/rebooter_spec.rb @@ -43,7 +43,7 @@ describe Chef::Platform::Rebooter do let(:expected) do { - :windows => 'shutdown /r /t 300 /c "rebooter spec test"', + :windows => "#{ENV['SYSTEMROOT']}/System32/shutdown.exe /r /t 300 /c \"rebooter spec test\"", :linux => 'shutdown -r +5 "rebooter spec test"', } end @@ -80,7 +80,7 @@ describe Chef::Platform::Rebooter do describe "when using #reboot_if_needed!" do include_context "test a reboot method" - it "should produce the correct string on Windows" do + it "should produce the correct string on Windows", :windows_only do test_rebooter_method(:reboot_if_needed!, true, expected[:windows]) end @@ -92,7 +92,7 @@ describe Chef::Platform::Rebooter do describe "when using #reboot!" do include_context "test a reboot method" - it "should produce the correct string on Windows" do + it "should produce the correct string on Windows", :windows_only do test_rebooter_method(:reboot!, true, expected[:windows]) end |