summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire McQuin <mcquin@users.noreply.github.com>2014-06-24 22:31:28 -0700
committerClaire McQuin <mcquin@users.noreply.github.com>2014-06-24 22:31:28 -0700
commit7bd5fa322e6bb75aad596ccfde04fac49dc84cf4 (patch)
treed77522b42289058021e482d27d22f0d1937335ce
parent12eca18c3e3865fa1cf379d0e4cd4f2b14fc055c (diff)
parent7efe1706cb83f3a899d51b2fa9a83ae2bf0cb306 (diff)
downloadchef-7bd5fa322e6bb75aad596ccfde04fac49dc84cf4.tar.gz
Merge pull request #1525 from opscode/mcquin/chefdk-69
Use FFI binders to attach :SendMessageTimeout instead of Win32API.
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/chef/provider/env/windows.rb9
-rw-r--r--lib/chef/win32/api/system.rb14
-rw-r--r--lib/chef/win32/version.rb8
4 files changed, 24 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 56492db8b6..dbc0b59192 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -121,6 +121,7 @@
* Add helper to warn for broken [windows] paths. (CHEF-5322)
* Send md5 checksummed data for registry key if data type is binary, dword, or qword. (Chef-5323)
* Add warning if host resembles winrm command and knife-windows is not present.
+* Use FFI binders to attach :SendMessageTimeout to avoid DL deprecation warning. (ChefDK Issues 69)
## Release: 11.12.4 (04/30/2014)
http://www.getchef.com/blog/2014/04/30/release-chef-client-11-12-4-ohai-7-0-4/
diff --git a/lib/chef/provider/env/windows.rb b/lib/chef/provider/env/windows.rb
index d0c136451f..96b5d3871f 100644
--- a/lib/chef/provider/env/windows.rb
+++ b/lib/chef/provider/env/windows.rb
@@ -16,14 +16,13 @@
# limitations under the License.
#
-if RUBY_PLATFORM =~ /mswin|mingw32|windows/
- require 'Win32API'
-end
+require 'chef/win32/api/system' if RUBY_PLATFORM =~ /mswin|mingw32|windows/
class Chef
class Provider
class Env
class Windows < Chef::Provider::Env
+ include Chef::ReservedNames::Win32::API::System if RUBY_PLATFORM =~ /mswin|mingw32|windows/
def create_env
obj = env_obj(@new_resource.key_name)
@@ -73,10 +72,8 @@ class Chef
SMTO_NOTIMEOUTIFNOTHUNG = 0x0008
def broadcast_env_change
- result = 0
flags = SMTO_BLOCK | SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG
- @send_message ||= Win32API.new('user32', 'SendMessageTimeout', 'LLLPLLP', 'L')
- @send_message.call(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 'Environment', flags, 5000, result)
+ SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, FFI::MemoryPointer.from_string('Environment').address, flags, 5000, nil)
end
end
end
diff --git a/lib/chef/win32/api/system.rb b/lib/chef/win32/api/system.rb
index 60f381aa5a..a58c0f38f4 100644
--- a/lib/chef/win32/api/system.rb
+++ b/lib/chef/win32/api/system.rb
@@ -186,6 +186,20 @@ int WINAPI GetSystemMetrics(
=end
safe_attach_function :GetSystemMetrics, [:int], :int
+=begin
+LRESULT WINAPI SendMessageTimeout(
+ _In_ HWND hWnd,
+ _In_ UINT Msg,
+ _In_ WPARAM wParam,
+ _In_ LPARAM lParam,
+ _In_ UINT fuFlags,
+ _In_ UINT uTimeout,
+ _Out_opt_ PDWORD_PTR lpdwResult
+);
+=end
+ safe_attach_function :SendMessageTimeoutW, [:HWND, :UINT, :WPARAM, :LPARAM, :UINT, :UINT, :PDWORD_PTR], :LRESULT
+ safe_attach_function :SendMessageTimeoutA, [:HWND, :UINT, :WPARAM, :LPARAM, :UINT, :UINT, :PDWORD_PTR], :LRESULT
+
end
end
end
diff --git a/lib/chef/win32/version.rb b/lib/chef/win32/version.rb
index 233e31fe76..d2138289f5 100644
--- a/lib/chef/win32/version.rb
+++ b/lib/chef/win32/version.rb
@@ -23,6 +23,10 @@ require 'wmi-lite/wmi'
class Chef
module ReservedNames::Win32
class Version
+ class << self
+ include Chef::ReservedNames::Win32::API::System
+ end
+
include Chef::ReservedNames::Win32::API::Macros
include Chef::ReservedNames::Win32::API::System
@@ -33,12 +37,12 @@ class Chef
private
def self.get_system_metrics(n_index)
- Win32API.new('user32', 'GetSystemMetrics', 'I', 'I').call(n_index)
+ GetSystemMetrics(n_index)
end
def self.method_name_from_marketing_name(marketing_name)
"#{marketing_name.gsub(/\s/, '_').gsub(/\./, '_').downcase}?"
- # "#{marketing_name.gsub(/\s/, '_').gsub(//, '_').downcase}?"
+ # "#{marketing_name.gsub(/\s/, '_').gsub(//, '_').downcase}?"
end
public