Signed-off-by: Vincent Demeester <vincent@sbr.pm>
| ... | ... |
@@ -11,6 +11,7 @@ import ( |
| 11 | 11 |
"github.com/docker/docker/pkg/fileutils" |
| 12 | 12 |
"github.com/docker/docker/pkg/parsers/kernel" |
| 13 | 13 |
"github.com/docker/docker/pkg/parsers/operatingsystem" |
| 14 |
+ "github.com/docker/docker/pkg/platform" |
|
| 14 | 15 |
"github.com/docker/docker/pkg/sysinfo" |
| 15 | 16 |
"github.com/docker/docker/pkg/system" |
| 16 | 17 |
"github.com/docker/docker/registry" |
| ... | ... |
@@ -75,8 +76,8 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
|
| 75 | 75 |
KernelVersion: kernelVersion, |
| 76 | 76 |
OperatingSystem: operatingSystem, |
| 77 | 77 |
IndexServerAddress: registry.IndexServer, |
| 78 |
- OSType: runtime.GOOS, |
|
| 79 |
- Architecture: runtime.GOARCH, |
|
| 78 |
+ OSType: platform.OSType, |
|
| 79 |
+ Architecture: platform.Architecture, |
|
| 80 | 80 |
RegistryConfig: daemon.RegistryService.Config, |
| 81 | 81 |
InitSha1: dockerversion.InitSHA1, |
| 82 | 82 |
InitPath: initPath, |
| 49 | 49 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,15 @@ |
| 0 |
+package platform |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "os/exec" |
|
| 4 |
+) |
|
| 5 |
+ |
|
| 6 |
+// GetRuntimeArchitecture get the name of the current architecture (x86, x86_64, …) |
|
| 7 |
+func GetRuntimeArchitecture() (string, error) {
|
|
| 8 |
+ cmd := exec.Command("uname", "-m")
|
|
| 9 |
+ machine, err := cmd.Output() |
|
| 10 |
+ if err != nil {
|
|
| 11 |
+ return "", err |
|
| 12 |
+ } |
|
| 13 |
+ return string(machine), nil |
|
| 14 |
+} |
| 0 | 15 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,28 @@ |
| 0 |
+// Package platform provides helper function to get the runtime architecture |
|
| 1 |
+// for different platforms. |
|
| 2 |
+package platform |
|
| 3 |
+ |
|
| 4 |
+import ( |
|
| 5 |
+ "syscall" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+// GetRuntimeArchitecture get the name of the current architecture (x86, x86_64, …) |
|
| 9 |
+func GetRuntimeArchitecture() (string, error) {
|
|
| 10 |
+ utsname := &syscall.Utsname{}
|
|
| 11 |
+ if err := syscall.Uname(utsname); err != nil {
|
|
| 12 |
+ return "", err |
|
| 13 |
+ } |
|
| 14 |
+ return charsToString(utsname.Machine), nil |
|
| 15 |
+} |
|
| 16 |
+ |
|
| 17 |
+func charsToString(ca [65]int8) string {
|
|
| 18 |
+ s := make([]byte, len(ca)) |
|
| 19 |
+ var lens int |
|
| 20 |
+ for ; lens < len(ca); lens++ {
|
|
| 21 |
+ if ca[lens] == 0 {
|
|
| 22 |
+ break |
|
| 23 |
+ } |
|
| 24 |
+ s[lens] = uint8(ca[lens]) |
|
| 25 |
+ } |
|
| 26 |
+ return string(s[0:lens]) |
|
| 27 |
+} |
| 0 | 28 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,52 @@ |
| 0 |
+package platform |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "fmt" |
|
| 4 |
+ "syscall" |
|
| 5 |
+ "unsafe" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+var ( |
|
| 9 |
+ modkernel32 = syscall.NewLazyDLL("kernel32.dll")
|
|
| 10 |
+ procGetSystemInfo = modkernel32.NewProc("GetSystemInfo")
|
|
| 11 |
+) |
|
| 12 |
+ |
|
| 13 |
+// see http://msdn.microsoft.com/en-us/library/windows/desktop/ms724958(v=vs.85).aspx |
|
| 14 |
+type systeminfo struct {
|
|
| 15 |
+ wProcessorArchitecture uint16 |
|
| 16 |
+ wReserved uint16 |
|
| 17 |
+ dwPageSize uint32 |
|
| 18 |
+ lpMinimumApplicationAddress uintptr |
|
| 19 |
+ lpMaximumApplicationAddress uintptr |
|
| 20 |
+ dwActiveProcessorMask uintptr |
|
| 21 |
+ dwNumberOfProcessors uint32 |
|
| 22 |
+ dwProcessorType uint32 |
|
| 23 |
+ dwAllocationGranularity uint32 |
|
| 24 |
+ wProcessorLevel uint16 |
|
| 25 |
+ wProcessorRevision uint16 |
|
| 26 |
+} |
|
| 27 |
+ |
|
| 28 |
+// Constants |
|
| 29 |
+const ( |
|
| 30 |
+ ProcessorArchitecture64 = 9 // PROCESSOR_ARCHITECTURE_AMD64 |
|
| 31 |
+ ProcessorArchitectureIA64 = 6 // PROCESSOR_ARCHITECTURE_IA64 |
|
| 32 |
+ ProcessorArchitecture32 = 0 // PROCESSOR_ARCHITECTURE_INTEL |
|
| 33 |
+ ProcessorArchitectureArm = 5 // PROCESSOR_ARCHITECTURE_ARM |
|
| 34 |
+) |
|
| 35 |
+ |
|
| 36 |
+var sysinfo systeminfo |
|
| 37 |
+ |
|
| 38 |
+// GetRuntimeArchitecture get the name of the current architecture (x86, x86_64, …) |
|
| 39 |
+func GetRuntimeArchitecture() (string, error) {
|
|
| 40 |
+ syscall.Syscall(procGetSystemInfo.Addr(), 1, uintptr(unsafe.Pointer(&sysinfo)), 0, 0) |
|
| 41 |
+ switch sysinfo.wProcessorArchitecture {
|
|
| 42 |
+ case ProcessorArchitecture64, ProcessorArchitectureIA64: |
|
| 43 |
+ return "x86_64", nil |
|
| 44 |
+ case ProcessorArchitecture32: |
|
| 45 |
+ return "i686", nil |
|
| 46 |
+ case ProcessorArchitectureArm: |
|
| 47 |
+ return "arm", nil |
|
| 48 |
+ default: |
|
| 49 |
+ return "", fmt.Errorf("Unknown processor architecture")
|
|
| 50 |
+ } |
|
| 51 |
+} |
| 0 | 52 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,23 @@ |
| 0 |
+package platform |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "runtime" |
|
| 4 |
+ |
|
| 5 |
+ "github.com/Sirupsen/logrus" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+var ( |
|
| 9 |
+ // Architecture holds the runtime architecture of the process. |
|
| 10 |
+ Architecture string |
|
| 11 |
+ // OSType holds the runtime operating system type (Linux, …) of the process. |
|
| 12 |
+ OSType string |
|
| 13 |
+) |
|
| 14 |
+ |
|
| 15 |
+func init() {
|
|
| 16 |
+ var err error |
|
| 17 |
+ Architecture, err = GetRuntimeArchitecture() |
|
| 18 |
+ if err != nil {
|
|
| 19 |
+ logrus.Errorf("Could no read system architecture info: %v", err)
|
|
| 20 |
+ } |
|
| 21 |
+ OSType = runtime.GOOS |
|
| 22 |
+} |