wintun: simplify checking reboot requirement

We never checked checkReboot() reported error anyway.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2019-08-02 15:37:08 +02:00
parent 73698066d1
commit f5e54932e6

View File

@ -290,10 +290,7 @@ func CreateInterface(description string, requestedGUID *windows.GUID) (wintun *W
if devInfoList.SetClassInstallParams(deviceData, &removeDeviceParams.ClassInstallHeader, uint32(unsafe.Sizeof(removeDeviceParams))) == nil { if devInfoList.SetClassInstallParams(deviceData, &removeDeviceParams.ClassInstallHeader, uint32(unsafe.Sizeof(removeDeviceParams))) == nil {
// Call appropriate class installer. // Call appropriate class installer.
if devInfoList.CallClassInstaller(setupapi.DIF_REMOVE, deviceData) == nil { if devInfoList.CallClassInstaller(setupapi.DIF_REMOVE, deviceData) == nil {
// Check if a system reboot is required. (Ignore errors) rebootRequired = rebootRequired || checkReboot(devInfoList, deviceData)
if ret, _ := checkReboot(devInfoList, deviceData); ret {
rebootRequired = true
}
} }
} }
@ -307,11 +304,7 @@ func CreateInterface(description string, requestedGUID *windows.GUID) (wintun *W
err = fmt.Errorf("SetupDiCallClassInstaller(DIF_INSTALLDEVICE) failed: %v", err) err = fmt.Errorf("SetupDiCallClassInstaller(DIF_INSTALLDEVICE) failed: %v", err)
return return
} }
rebootRequired = checkReboot(devInfoList, deviceData)
// Check if a system reboot is required. (Ignore errors)
if ret, _ := checkReboot(devInfoList, deviceData); ret {
rebootRequired = true
}
// 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
@ -456,9 +449,7 @@ func (wintun *Wintun) DeleteInterface() (rebootRequired bool, err error) {
return false, fmt.Errorf("SetupDiCallClassInstaller failed: %v", err) return false, fmt.Errorf("SetupDiCallClassInstaller failed: %v", err)
} }
// Check if a system reboot is required. (Ignore errors) return checkReboot(devInfoList, deviceData), nil
rebootRequired, _ = checkReboot(devInfoList, deviceData)
return rebootRequired, nil
} }
// DeleteAllInterfaces deletes all Wintun interfaces, and returns which // DeleteAllInterfaces deletes all Wintun interfaces, and returns which
@ -529,22 +520,20 @@ func DeleteAllInterfaces() (deviceInstancesDeleted []uint32, rebootRequired bool
errors = append(errors, err) errors = append(errors, err)
continue continue
} }
if !rebootRequired { rebootRequired = rebootRequired || checkReboot(devInfoList, deviceData)
rebootRequired, _ = checkReboot(devInfoList, deviceData)
}
deviceInstancesDeleted = append(deviceInstancesDeleted, inst) deviceInstancesDeleted = append(deviceInstancesDeleted, inst)
} }
return return
} }
// checkReboot checks device install parameters if a system reboot is required. // checkReboot checks device install parameters if a system reboot is required.
func checkReboot(deviceInfoSet setupapi.DevInfo, deviceInfoData *setupapi.DevInfoData) (bool, error) { func checkReboot(deviceInfoSet setupapi.DevInfo, deviceInfoData *setupapi.DevInfoData) bool {
devInstallParams, err := deviceInfoSet.DeviceInstallParams(deviceInfoData) devInstallParams, err := deviceInfoSet.DeviceInstallParams(deviceInfoData)
if err != nil { if err != nil {
return false, err return false
} }
return (devInstallParams.Flags & (setupapi.DI_NEEDREBOOT | setupapi.DI_NEEDRESTART)) != 0, nil return (devInstallParams.Flags & (setupapi.DI_NEEDREBOOT | setupapi.DI_NEEDRESTART)) != 0
} }
// setQuietInstall sets device install parameters for a quiet installation // setQuietInstall sets device install parameters for a quiet installation