diff --git a/pkg/idtools/idtools_unix.go b/pkg/idtools/idtools_unix.go index 7d31c69dae..72e9c08a10 100644 --- a/pkg/idtools/idtools_unix.go +++ b/pkg/idtools/idtools_unix.go @@ -167,7 +167,7 @@ func callGetent(database, key string) (io.Reader, error) { if getentCmd == "" { return nil, fmt.Errorf("unable to find getent command") } - out, err := execCmd(getentCmd, database, key) + out, err := exec.Command(getentCmd, database, key).CombinedOutput() if err != nil { exitCode, errC := getExitCode(err) if errC != nil { diff --git a/pkg/idtools/idtools_unix_test.go b/pkg/idtools/idtools_unix_test.go index 1e65e2af08..5a4acc25d1 100644 --- a/pkg/idtools/idtools_unix_test.go +++ b/pkg/idtools/idtools_unix_test.go @@ -328,8 +328,8 @@ func compareTrees(left, right map[string]node) error { } func delUser(t *testing.T, name string) { - _, err := execCmd("userdel", name) - assert.Check(t, err) + out, err := exec.Command("userdel", name).CombinedOutput() + assert.Check(t, err, out) } func TestParseSubidFileWithNewlinesAndComments(t *testing.T) { diff --git a/pkg/idtools/usergroupadd_linux.go b/pkg/idtools/usergroupadd_linux.go index 24bb86c13b..f0c075e20f 100644 --- a/pkg/idtools/usergroupadd_linux.go +++ b/pkg/idtools/usergroupadd_linux.go @@ -2,6 +2,7 @@ package idtools // import "github.com/docker/docker/pkg/idtools" import ( "fmt" + "os/exec" "regexp" "sort" "strconv" @@ -36,7 +37,7 @@ func AddNamespaceRangesUser(name string) (int, int, error) { } // Query the system for the created uid and gid pair - out, err := execCmd("id", name) + out, err := exec.Command("id", name).CombinedOutput() if err != nil { return -1, -1, fmt.Errorf("error trying to find uid/gid for new user %q: %v", name, err) } @@ -81,7 +82,7 @@ func addUser(name string) error { return fmt.Errorf("cannot add user; no useradd/adduser binary found") } - if out, err := execCmd(userCommand, args...); err != nil { + if out, err := exec.Command(userCommand, args...).CombinedOutput(); err != nil { return fmt.Errorf("failed to add user with error: %v; output: %q", err, string(out)) } return nil @@ -100,7 +101,8 @@ func createSubordinateRanges(name string) error { if err != nil { return fmt.Errorf("can't find available subuid range: %v", err) } - out, err := execCmd("usermod", "-v", fmt.Sprintf("%d-%d", startID, startID+defaultRangeLen-1), name) + idRange := fmt.Sprintf("%d-%d", startID, startID+defaultRangeLen-1) + out, err := exec.Command("usermod", "-v", idRange, name).CombinedOutput() if err != nil { return fmt.Errorf("unable to add subuid range to user: %q; output: %s, err: %v", name, out, err) } @@ -116,7 +118,8 @@ func createSubordinateRanges(name string) error { if err != nil { return fmt.Errorf("can't find available subgid range: %v", err) } - out, err := execCmd("usermod", "-w", fmt.Sprintf("%d-%d", startID, startID+defaultRangeLen-1), name) + idRange := fmt.Sprintf("%d-%d", startID, startID+defaultRangeLen-1) + out, err := exec.Command("usermod", "-w", idRange, name).CombinedOutput() if err != nil { return fmt.Errorf("unable to add subgid range to user: %q; output: %s, err: %v", name, out, err) } diff --git a/pkg/idtools/utils_unix.go b/pkg/idtools/utils_unix.go index 540672af5a..05cc696365 100644 --- a/pkg/idtools/utils_unix.go +++ b/pkg/idtools/utils_unix.go @@ -25,8 +25,3 @@ func resolveBinary(binname string) (string, error) { } return "", fmt.Errorf("Binary %q does not resolve to a binary of that name in $PATH (%q)", binname, resolvedPath) } - -func execCmd(cmd string, arg ...string) ([]byte, error) { - execCmd := exec.Command(cmd, arg...) - return execCmd.CombinedOutput() -}