-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel_unix.go
33 lines (28 loc) · 889 Bytes
/
kernel_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//go:build linux || freebsd || openbsd
// +build linux freebsd openbsd
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
}