update vendor and fix get

This commit is contained in:
vcaesar 2017-11-26 19:50:56 +08:00
parent 82195e5af5
commit b1d4b3a101
2 changed files with 21 additions and 4 deletions

View File

@ -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
}
}

6
vendor/vendor.json vendored
View File

@ -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=",