diff options
| author | William Van Hevelingen <wvan13@gmail.com> | 2010-08-19 01:41:13 -0700 |
|---|---|---|
| committer | William Van Hevelingen <wvan13@gmail.com> | 2010-08-19 01:43:52 -0700 |
| commit | 9c9cabd7ecb458643447d60d56e2fefe947f23c2 (patch) | |
| tree | 3e57b585ecd573d95b145102fb76e18c3b76e963 /lib | |
| parent | b6c0a6b717e85cae813275b9feaeb409b8701c5b (diff) | |
| download | facter-9c9cabd7ecb458643447d60d56e2fefe947f23c2.tar.gz facter-9c9cabd7ecb458643447d60d56e2fefe947f23c2.tar.xz facter-9c9cabd7ecb458643447d60d56e2fefe947f23c2.zip | |
Better fix for Bug 4569: Uptime Fact is incorrect on Windows
Patch removes reliance on clock ticks and instead queries for last boot time and subtracts from Time.now
Signed-off-by: William Van Hevelingen <wvan13@gmail.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/facter/util/uptime.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/facter/util/uptime.rb b/lib/facter/util/uptime.rb index b62d7e9..6c60ace 100644 --- a/lib/facter/util/uptime.rb +++ b/lib/facter/util/uptime.rb @@ -8,9 +8,12 @@ module Facter::Util::Uptime end def self.get_uptime_seconds_win - require 'Win32API' - getTickCount = Win32API.new("kernel32", "GetTickCount", nil, 'L') - (getTickCount.call() / 1000.0).to_i + require 'win32ole' + wmi = WIN32OLE.connect("winmgmts://") + query = wmi.ExecQuery("select * from Win32_OperatingSystem") + last_boot = "" + query.each { |x| last_boot = x.LastBootupTime} + self.compute_uptime(Time.parse(last_boot.split('.').first)) end private |
