1// +build !windows 2 3package daemon // import "github.com/docker/docker/daemon" 4 5import ( 6 "context" 7 "os/exec" 8 "strings" 9 10 "github.com/docker/docker/api/types" 11 "github.com/docker/docker/dockerversion" 12 "github.com/docker/docker/pkg/sysinfo" 13 "github.com/pkg/errors" 14 "github.com/sirupsen/logrus" 15) 16 17// FillPlatformInfo fills the platform related info. 18func (daemon *Daemon) FillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo) { 19 v.MemoryLimit = sysInfo.MemoryLimit 20 v.SwapLimit = sysInfo.SwapLimit 21 v.KernelMemory = sysInfo.KernelMemory 22 v.OomKillDisable = sysInfo.OomKillDisable 23 v.CPUCfsPeriod = sysInfo.CPUCfsPeriod 24 v.CPUCfsQuota = sysInfo.CPUCfsQuota 25 v.CPUShares = sysInfo.CPUShares 26 v.CPUSet = sysInfo.Cpuset 27 v.Runtimes = daemon.configStore.GetAllRuntimes() 28 v.DefaultRuntime = daemon.configStore.GetDefaultRuntimeName() 29 v.InitBinary = daemon.configStore.GetInitPath() 30 31 v.RuncCommit.Expected = dockerversion.RuncCommitID 32 defaultRuntimeBinary := daemon.configStore.GetRuntime(v.DefaultRuntime).Path 33 if rv, err := exec.Command(defaultRuntimeBinary, "--version").Output(); err == nil { 34 parts := strings.Split(strings.TrimSpace(string(rv)), "\n") 35 if len(parts) == 3 { 36 parts = strings.Split(parts[1], ": ") 37 if len(parts) == 2 { 38 v.RuncCommit.ID = strings.TrimSpace(parts[1]) 39 } 40 } 41 42 if v.RuncCommit.ID == "" { 43 logrus.Warnf("failed to retrieve %s version: unknown output format: %s", defaultRuntimeBinary, string(rv)) 44 v.RuncCommit.ID = "N/A" 45 } 46 } else { 47 logrus.Warnf("failed to retrieve %s version: %v", defaultRuntimeBinary, err) 48 v.RuncCommit.ID = "N/A" 49 } 50 51 v.ContainerdCommit.Expected = dockerversion.ContainerdCommitID 52 if rv, err := daemon.containerd.Version(context.Background()); err == nil { 53 v.ContainerdCommit.ID = rv.Revision 54 } else { 55 logrus.Warnf("failed to retrieve containerd version: %v", err) 56 v.ContainerdCommit.ID = "N/A" 57 } 58 59 defaultInitBinary := daemon.configStore.GetInitPath() 60 if rv, err := exec.Command(defaultInitBinary, "--version").Output(); err == nil { 61 ver, err := parseInitVersion(string(rv)) 62 63 if err != nil { 64 logrus.Warnf("failed to retrieve %s version: %s", defaultInitBinary, err) 65 } 66 v.InitCommit = ver 67 } else { 68 logrus.Warnf("failed to retrieve %s version: %s", defaultInitBinary, err) 69 v.InitCommit.ID = "N/A" 70 } 71} 72 73// parseInitVersion parses a Tini version string, and extracts the version. 74func parseInitVersion(v string) (types.Commit, error) { 75 version := types.Commit{ID: "", Expected: dockerversion.InitCommitID} 76 parts := strings.Split(strings.TrimSpace(v), " - ") 77 78 if len(parts) >= 2 { 79 gitParts := strings.Split(parts[1], ".") 80 if len(gitParts) == 2 && gitParts[0] == "git" { 81 version.ID = gitParts[1] 82 version.Expected = dockerversion.InitCommitID[0:len(version.ID)] 83 } 84 } 85 if version.ID == "" && strings.HasPrefix(parts[0], "tini version ") { 86 version.ID = "v" + strings.TrimPrefix(parts[0], "tini version ") 87 } 88 if version.ID == "" { 89 version.ID = "N/A" 90 return version, errors.Errorf("unknown output format: %s", v) 91 } 92 return version, nil 93} 94