wintun: poll for device key

It's actually pretty hard to guess where it is.
This commit is contained in:
Jason A. Donenfeld 2019-05-10 17:34:03 +02:00
parent f9dcfccbb7
commit 1bf1dadf15

View file

@ -294,13 +294,16 @@ func CreateInterface(description string, hwndParent uintptr) (*Wintun, bool, err
// DIF_INSTALLDEVICE returns almost immediately, while the device installation // DIF_INSTALLDEVICE returns almost immediately, while the device installation
// continues in the background. It might take a while, before all registry // continues in the background. It might take a while, before all registry
// keys and values are populated. // keys and values are populated.
const pollTimeout = time.Millisecond * 50
// Wait for device registry key to emerge and populate. for i := 0; i < int(waitForRegistryTimeout/pollTimeout); i++ {
key, err = registryEx.OpenKeyWait( if i != 0 {
registry.LOCAL_MACHINE, time.Sleep(pollTimeout)
fmt.Sprintf("SYSTEM\\CurrentControlSet\\Control\\Class\\%v\\%04d", guid.ToString(&deviceClassNetGUID), deviceData.DevInst), }
registry.QUERY_VALUE|registryEx.KEY_NOTIFY, key, err = devInfoList.OpenDevRegKey(deviceData, setupapi.DICS_FLAG_GLOBAL, 0, setupapi.DIREG_DRV, registry.QUERY_VALUE|registryEx.KEY_NOTIFY)
waitForRegistryTimeout) if err == nil {
break
}
}
if err == nil { if err == nil {
_, err = registryEx.GetStringValueWait(key, "NetCfgInstanceId", waitForRegistryTimeout) _, err = registryEx.GetStringValueWait(key, "NetCfgInstanceId", waitForRegistryTimeout)
if err == nil { if err == nil {
@ -311,8 +314,6 @@ func CreateInterface(description string, hwndParent uintptr) (*Wintun, bool, err
} }
key.Close() key.Close()
} }
// Clear error and let makeWintun() open the key using SetupAPI's devInfoList.OpenDevRegKey().
err = nil
} }
if err == nil { if err == nil {