2021-08-23 09:14:53 -04:00
|
|
|
//go:build linux || freebsd || openbsd
|
2017-11-01 19:37:53 -04:00
|
|
|
// +build linux freebsd openbsd
|
2016-05-06 06:03:01 -04:00
|
|
|
|
|
|
|
// Package kernel provides helper function to get, parse and compare kernel
|
|
|
|
// versions for different platforms.
|
2018-02-05 16:05:59 -05:00
|
|
|
package kernel // import "github.com/docker/docker/pkg/parsers/kernel"
|
2016-05-06 06:03:01 -04:00
|
|
|
|
|
|
|
import (
|
2017-07-26 17:42:13 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2022-05-18 17:37:40 -04:00
|
|
|
"golang.org/x/sys/unix"
|
2016-05-06 06:03:01 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
2022-05-18 17:37:40 -04:00
|
|
|
return ParseRelease(unix.ByteSliceToString(uts.Release[:]))
|
2016-05-06 06:03:01 -04:00
|
|
|
}
|
2016-08-02 01:17:20 -04:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|