]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
Simplify reading NetCfgInstanceId from registry
authorSimon Rozman <simon@rozman.si>
Mon, 4 Mar 2019 12:25:18 +0000 (13:25 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Mon, 4 Mar 2019 15:37:11 +0000 (16:37 +0100)
As querying non-existing registry value and reading non-existing
registry string value both return ERROR_FILE_NOT_FOUND, we can
use later only.

Signed-off-by: Simon Rozman <simon@rozman.si>
tun/wintun/wintun_windows.go

index 875ca3541c9ba614a1de6874f7726b7dc6abb0ad..bb449633a428bf6c1047eff29e27b3442a6602ec 100644 (file)
@@ -386,8 +386,8 @@ func getInterfaceId(deviceInfoSet setupapi.DevInfo, deviceInfoData *setupapi.Dev
        defer key.Close()
 
        for {
-               // Query the NetCfgInstanceId value. Using get_reg_string() right on might clutter the output with error messages while the registry is still being populated.
-               _, _, err = key.GetValue("NetCfgInstanceId", nil)
+               // Read the NetCfgInstanceId value.
+               value, err := getRegStringValue(key, "NetCfgInstanceId")
                if err != nil {
                        if errWin, ok := err.(syscall.Errno); ok && errWin == windows.ERROR_FILE_NOT_FOUND {
                                numAttempts--
@@ -399,12 +399,6 @@ func getInterfaceId(deviceInfoSet setupapi.DevInfo, deviceInfoData *setupapi.Dev
                                }
                        }
 
-                       return nil, errors.New("RegQueryValueEx(\"NetCfgInstanceId\") failed: " + err.Error())
-               }
-
-               // Read the NetCfgInstanceId value now.
-               value, err := getRegStringValue(key, "NetCfgInstanceId")
-               if err != nil {
                        return nil, errors.New("RegQueryStringValue(\"NetCfgInstanceId\") failed: " + err.Error())
                }