From 738b966ed1f511d4ec9c9a9a2b3f7a8e204e6952 Mon Sep 17 00:00:00 2001 From: Lomanic Date: Sat, 29 Dec 2018 13:38:21 +0100 Subject: [PATCH] [host][darwin] Use unix.Sysctl to get kernel version and platform name --- host/host_darwin.go | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/host/host_darwin.go b/host/host_darwin.go index 8241fc0..5cf22b7 100644 --- a/host/host_darwin.go +++ b/host/host_darwin.go @@ -18,6 +18,7 @@ import ( "github.com/shirou/gopsutil/internal/common" "github.com/shirou/gopsutil/process" + "golang.org/x/sys/unix" ) // from utmpx.h @@ -180,17 +181,13 @@ func PlatformInformationWithContext(ctx context.Context) (string, string, string if err != nil { return "", "", "", err } - uname, err := exec.LookPath("uname") - if err != nil { - return "", "", "", err - } - out, err := invoke.CommandWithContext(ctx, uname, "-s") + p, err := unix.Sysctl("kern.ostype") if err == nil { - platform = strings.ToLower(strings.TrimSpace(string(out))) + platform = strings.ToLower(p) } - out, err = invoke.CommandWithContext(ctx, sw_vers, "-productVersion") + out, err := invoke.CommandWithContext(ctx, sw_vers, "-productVersion") if err == nil { pver = strings.ToLower(strings.TrimSpace(string(out))) } @@ -211,16 +208,8 @@ func KernelVersion() (string, error) { } func KernelVersionWithContext(ctx context.Context) (string, error) { - uname, err := exec.LookPath("uname") - if err != nil { - return "", err - } - out, err := invoke.CommandWithContext(ctx, uname, "-r") - if err != nil { - return "", err - } - version := strings.ToLower(strings.TrimSpace(string(out))) - return version, err + version, err := unix.Sysctl("kern.osrelease") + return strings.ToLower(version), err } func SensorsTemperatures() ([]TemperatureStat, error) {