pkg/idtools: remove execCmd() utility
The `execCmd()` utility was a basic wrapper around `exec.Command()`. Inlining it makes the code more transparent. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
6743bf3173
commit
1e88fe578e
|
@ -167,7 +167,7 @@ func callGetent(database, key string) (io.Reader, error) {
|
||||||
if getentCmd == "" {
|
if getentCmd == "" {
|
||||||
return nil, fmt.Errorf("unable to find getent command")
|
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 {
|
if err != nil {
|
||||||
exitCode, errC := getExitCode(err)
|
exitCode, errC := getExitCode(err)
|
||||||
if errC != nil {
|
if errC != nil {
|
||||||
|
|
|
@ -328,8 +328,8 @@ func compareTrees(left, right map[string]node) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func delUser(t *testing.T, name string) {
|
func delUser(t *testing.T, name string) {
|
||||||
_, err := execCmd("userdel", name)
|
out, err := exec.Command("userdel", name).CombinedOutput()
|
||||||
assert.Check(t, err)
|
assert.Check(t, err, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseSubidFileWithNewlinesAndComments(t *testing.T) {
|
func TestParseSubidFileWithNewlinesAndComments(t *testing.T) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package idtools // import "github.com/docker/docker/pkg/idtools"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -36,7 +37,7 @@ func AddNamespaceRangesUser(name string) (int, int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the system for the created uid and gid pair
|
// 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 {
|
if err != nil {
|
||||||
return -1, -1, fmt.Errorf("error trying to find uid/gid for new user %q: %v", name, err)
|
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")
|
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 fmt.Errorf("failed to add user with error: %v; output: %q", err, string(out))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -100,7 +101,8 @@ func createSubordinateRanges(name string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't find available subuid range: %v", err)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to add subuid range to user: %q; output: %s, err: %v", name, out, err)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("can't find available subgid range: %v", err)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to add subgid range to user: %q; output: %s, err: %v", name, out, err)
|
return fmt.Errorf("unable to add subgid range to user: %q; output: %s, err: %v", name, out, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
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()
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue