From b1d4b3a10155f724e783e601cef6ac69180b8b8a Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sun, 26 Nov 2017 19:50:56 +0800 Subject: [PATCH] update vendor and fix get --- .../internal/common/common_windows.go | 19 ++++++++++++++++++- vendor/vendor.json | 6 +++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/vendor/github.com/shirou/gopsutil/internal/common/common_windows.go b/vendor/github.com/shirou/gopsutil/internal/common/common_windows.go index 8e0177d..1dffe61 100644 --- a/vendor/github.com/shirou/gopsutil/internal/common/common_windows.go +++ b/vendor/github.com/shirou/gopsutil/internal/common/common_windows.go @@ -3,8 +3,10 @@ package common import ( + "context" "unsafe" + "github.com/StackExchange/wmi" "golang.org/x/sys/windows" ) @@ -49,7 +51,7 @@ var ( ModNt = windows.NewLazyDLL("ntdll.dll") ModPdh = windows.NewLazyDLL("pdh.dll") ModPsapi = windows.NewLazyDLL("psapi.dll") - + ProcGetSystemTimes = Modkernel32.NewProc("GetSystemTimes") ProcNtQuerySystemInformation = ModNt.NewProc("NtQuerySystemInformation") PdhOpenQuery = ModPdh.NewProc("PdhOpenQuery") @@ -110,3 +112,18 @@ func CreateCounter(query windows.Handle, pname, cname string) (*CounterInfo, err Counter: counter, }, nil } + +// WMIQueryWithContext - wraps wmi.Query with a timed-out context to avoid hanging +func WMIQueryWithContext(ctx context.Context, query string, dst interface{}, connectServerArgs ...interface{}) error { + errChan := make(chan error, 1) + go func() { + errChan <- wmi.Query(query, dst, connectServerArgs...) + }() + + select { + case <-ctx.Done(): + return ctx.Err() + case err := <-errChan: + return err + } +} diff --git a/vendor/vendor.json b/vendor/vendor.json index 952c76d..40e59e7 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -57,10 +57,10 @@ "revisionTime": "2017-11-12T16:40:41Z" }, { - "checksumSHA1": "p9EXxuL/vV13YRPfgTBA3B/68Vo=", + "checksumSHA1": "jWpwWWcywJPNhKTYxi4RXds+amQ=", "path": "github.com/shirou/gopsutil/internal/common", - "revision": "a8bc26299477e53c4ca89f7ec60160a74d4c0890", - "revisionTime": "2017-11-12T16:40:41Z" + "revision": "bfe3c2e8f406bf352bc8df81f98c752224867349", + "revisionTime": "2017-11-21T12:01:14Z" }, { "checksumSHA1": "UuwHornIODuEq7fYnsZwdVgERLk=",