mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-10 15:06:36 +00:00
Address GitHub feedback
- Defer registry close calls - Ensure size parameter in GetComputerName is properly specified - Clean up some comments to ensure correctness Signed-off-by: Ben Ridley <benridley29@gmail.com>
This commit is contained in:
@@ -148,12 +148,12 @@ func GetSystemInfo() SystemInfo {
|
||||
}
|
||||
|
||||
// GetComputerName wraps the GetComputerNameW function in a more Go-like way
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcomputernamew
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getcomputernameexw
|
||||
func GetComputerName(f WinComputerNameFormat) (string, error) {
|
||||
// 1kb buffer to accept computer name. This should be more than enough as the maximum size
|
||||
// returned is the max length of a DNS name, which this author believes is 253 characters.
|
||||
size := 1024
|
||||
var buffer [4096]uint16
|
||||
var buffer [1024]uint16
|
||||
r1, _, err := procGetComputerNameExW.Call(uintptr(f), uintptr(unsafe.Pointer(&buffer)), uintptr(unsafe.Pointer(&size)))
|
||||
if r1 == 0 {
|
||||
return "", err
|
||||
|
||||
Reference in New Issue
Block a user