2013-04-22 15:08:59 -04:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
2013-04-22 16:19:50 -04:00
|
|
|
"bytes"
|
2013-05-14 18:37:35 -04:00
|
|
|
"github.com/dotcloud/docker/utils"
|
2013-04-22 15:08:59 -04:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
2013-05-14 18:37:35 -04:00
|
|
|
// FIXME: Move this to utils package
|
|
|
|
func getKernelVersion() (*utils.KernelVersionInfo, error) {
|
2013-04-22 15:08:59 -04:00
|
|
|
var (
|
|
|
|
uts syscall.Utsname
|
|
|
|
flavor string
|
|
|
|
kernel, major, minor int
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
if err := syscall.Uname(&uts); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
release := make([]byte, len(uts.Release))
|
|
|
|
|
|
|
|
i := 0
|
|
|
|
for _, c := range uts.Release {
|
|
|
|
release[i] = byte(c)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
|
2013-04-22 16:19:50 -04:00
|
|
|
// Remove the \x00 from the release for Atoi to parse correctly
|
|
|
|
release = release[:bytes.IndexByte(release, 0)]
|
|
|
|
|
2013-04-22 15:08:59 -04:00
|
|
|
tmp := strings.SplitN(string(release), "-", 2)
|
|
|
|
tmp2 := strings.SplitN(tmp[0], ".", 3)
|
|
|
|
|
|
|
|
if len(tmp2) > 0 {
|
|
|
|
kernel, err = strconv.Atoi(tmp2[0])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(tmp2) > 1 {
|
|
|
|
major, err = strconv.Atoi(tmp2[1])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(tmp2) > 2 {
|
|
|
|
minor, err = strconv.Atoi(tmp2[2])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(tmp) == 2 {
|
|
|
|
flavor = tmp[1]
|
|
|
|
} else {
|
|
|
|
flavor = ""
|
|
|
|
}
|
|
|
|
|
2013-05-14 18:37:35 -04:00
|
|
|
return &utils.KernelVersionInfo{
|
2013-04-22 15:08:59 -04:00
|
|
|
Kernel: kernel,
|
|
|
|
Major: major,
|
|
|
|
Minor: minor,
|
|
|
|
Flavor: flavor,
|
|
|
|
}, nil
|
|
|
|
}
|