Skip to content

Commit 871994c

Browse files
authored
Merge pull request moby#39849 from tklauser/uname-unix-no-exec
Use unix.Uname instead of shelling out to uname on darwin/freebsd
2 parents 553df77 + 7aeb3ef commit 871994c

File tree

3 files changed

+13
-31
lines changed

3 files changed

+13
-31
lines changed

pkg/parsers/operatingsystem/operatingsystem_unix.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
package operatingsystem // import "github.com/docker/docker/pkg/parsers/operatingsystem"
44

55
import (
6+
"bytes"
67
"errors"
7-
"os/exec"
8-
"strings"
8+
9+
"golang.org/x/sys/unix"
910
)
1011

1112
// GetOperatingSystem gets the name of the current operating system.
1213
func GetOperatingSystem() (string, error) {
13-
cmd := exec.Command("uname", "-s")
14-
osName, err := cmd.Output()
15-
if err != nil {
14+
utsname := &unix.Utsname{}
15+
if err := unix.Uname(utsname); err != nil {
1616
return "", err
1717
}
18-
return strings.TrimSpace(string(osName)), nil
18+
return string(utsname.Machine[:bytes.IndexByte(utsname.Sysname[:], 0)]), nil
1919
}
2020

2121
// GetOperatingSystemVersion gets the version of the current operating system, as a string.

pkg/platform/architecture_linux.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

pkg/platform/architecture_unix.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
// +build freebsd darwin
1+
// +build !windows
22

33
// Package platform provides helper function to get the runtime architecture
44
// for different platforms.
55
package platform // import "github.com/docker/docker/pkg/platform"
66

77
import (
8-
"os/exec"
9-
"strings"
8+
"bytes"
9+
10+
"golang.org/x/sys/unix"
1011
)
1112

1213
// runtimeArchitecture gets the name of the current architecture (x86, x86_64, i86pc, sun4v, ...)
1314
func runtimeArchitecture() (string, error) {
14-
cmd := exec.Command("/usr/bin/uname", "-m")
15-
machine, err := cmd.Output()
16-
if err != nil {
15+
utsname := &unix.Utsname{}
16+
if err := unix.Uname(utsname); err != nil {
1717
return "", err
1818
}
19-
return strings.TrimSpace(string(machine)), nil
19+
return string(utsname.Machine[:bytes.IndexByte(utsname.Machine[:], 0)]), nil
2020
}

0 commit comments

Comments
 (0)