From 8c28c3ba17f001012f845de800922d559bec3595 Mon Sep 17 00:00:00 2001 From: Lomanic Date: Sat, 3 Aug 2019 18:36:36 +0200 Subject: [PATCH] [host][linux] Fix #738 use uname syscall to get version in KernelVersion() --- host/host_linux.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/host/host_linux.go b/host/host_linux.go index 02ff554..3d00f54 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -18,6 +18,7 @@ import ( "time" "github.com/shirou/gopsutil/internal/common" + "golang.org/x/sys/unix" ) type LSB struct { @@ -369,19 +370,12 @@ func KernelVersion() (version string, err error) { } func KernelVersionWithContext(ctx context.Context) (version string, err error) { - filename := common.HostProc("sys/kernel/osrelease") - if common.PathExists(filename) { - contents, err := common.ReadLines(filename) - if err != nil { - return "", err - } - - if len(contents) > 0 { - version = contents[0] - } + var utsname unix.Utsname + err = unix.Uname(&utsname) + if err != nil { + return "", err } - - return version, nil + return string(utsname.Release[:]), nil } func getSlackwareVersion(contents []string) string {