mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
8a5c13155e
This also fixes the GetOperatingSystem function in
pkg/parsers/operatingsystem which mistakenly truncated utsname.Machine
to the index of \0 in utsname.Sysname.
Fixes: 7aeb3efcb4
Cc: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
35 lines
1,002 B
Go
35 lines
1,002 B
Go
//go:build linux || freebsd || openbsd
|
|
// +build linux freebsd openbsd
|
|
|
|
// Package kernel provides helper function to get, parse and compare kernel
|
|
// versions for different platforms.
|
|
package kernel // import "github.com/docker/docker/pkg/parsers/kernel"
|
|
|
|
import (
|
|
"github.com/sirupsen/logrus"
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// GetKernelVersion gets the current kernel version.
|
|
func GetKernelVersion() (*VersionInfo, error) {
|
|
uts, err := uname()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Remove the \x00 from the release for Atoi to parse correctly
|
|
return ParseRelease(unix.ByteSliceToString(uts.Release[:]))
|
|
}
|
|
|
|
// CheckKernelVersion checks if current kernel is newer than (or equal to)
|
|
// the given version.
|
|
func CheckKernelVersion(k, major, minor int) bool {
|
|
if v, err := GetKernelVersion(); err != nil {
|
|
logrus.Warnf("error getting kernel version: %s", err)
|
|
} else {
|
|
if CompareKernelVersion(*v, VersionInfo{Kernel: k, Major: major, Minor: minor}) < 0 {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|