[host][linux] Fix #738 use uname syscall to get version in KernelVersion()

pull/739/head
Lomanic 6 years ago
parent d80c43f9c9
commit 8c28c3ba17

@ -18,6 +18,7 @@ import (
"time" "time"
"github.com/shirou/gopsutil/internal/common" "github.com/shirou/gopsutil/internal/common"
"golang.org/x/sys/unix"
) )
type LSB struct { type LSB struct {
@ -369,19 +370,12 @@ func KernelVersion() (version string, err error) {
} }
func KernelVersionWithContext(ctx context.Context) (version string, err error) { func KernelVersionWithContext(ctx context.Context) (version string, err error) {
filename := common.HostProc("sys/kernel/osrelease") var utsname unix.Utsname
if common.PathExists(filename) { err = unix.Uname(&utsname)
contents, err := common.ReadLines(filename) if err != nil {
if err != nil { return "", err
return "", err
}
if len(contents) > 0 {
version = contents[0]
}
} }
return string(utsname.Release[:]), nil
return version, nil
} }
func getSlackwareVersion(contents []string) string { func getSlackwareVersion(contents []string) string {

Loading…
Cancel
Save