mirror of
https://github.com/shirou/gopsutil.git
synced 2025-05-02 22:17:08 +08:00
Merge pull request #739 from Lomanic/issue738
[host][linux] Fix #738 use uname syscall to get version in KernelVersion()
This commit is contained in:
commit
8a5bcfdb53
@ -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 {
|
||||||
@ -374,19 +375,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
|
||||||
}
|
}
|
||||||
|
return string(utsname.Release[:]), nil
|
||||||
if len(contents) > 0 {
|
|
||||||
version = contents[0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return version, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSlackwareVersion(contents []string) string {
|
func getSlackwareVersion(contents []string) string {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user