Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing some lint issues #2631

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion contrib/cmd/recvtty/recvtty.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ func handleSingle(path string, noStdin bool) error {
if err != nil {
return err
}
console.ClearONLCR(c.Fd())
if err := console.ClearONLCR(c.Fd()); err != nil {
return err
}

// Copy from our stdio to the master fd.
quitChan := make(chan struct{})
Expand Down
1 change: 0 additions & 1 deletion libcontainer/cgroups/systemd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ func systemdVersion(conn *systemdDbus.Conn) (int, error) {
}

version, versionErr = systemdVersionAtoi(verStr)
return
})

return version, versionErr
Expand Down
2 changes: 1 addition & 1 deletion libcontainer/configs/validate/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func checkHostNs(sysctlConfig string, path string) error {
return fmt.Errorf("could not check that %q is a symlink: %v", path, err)
}

if symLink == false {
if !symLink {
// The provided namespace is not a symbolic link,
// it is not the host namespace.
return nil
Expand Down
4 changes: 3 additions & 1 deletion libcontainer/configs/validate/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func TestValidate(t *testing.T) {

func TestValidateWithInvalidRootfs(t *testing.T) {
dir := "rootfs"
os.Symlink("/var", dir)
if err := os.Symlink("/var", dir); err != nil {
t.Fatal(err)
}
defer os.Remove(dir)

config := &configs.Config{
Expand Down
2 changes: 1 addition & 1 deletion libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ func (c *linuxContainer) criuSwrk(process *Process, req *criurpc.CriuReq, opts *

buf := make([]byte, 10*4096)
oob := make([]byte, 4096)
for true {
for {
n, oobn, _, _, err := criuClientCon.ReadMsgUnix(buf, oob)
if req.Opts != nil && req.Opts.StatusFd != nil {
// Close status_fd as soon as we got something back from criu,
Expand Down
4 changes: 2 additions & 2 deletions libcontainer/integration/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func testCheckpoint(t *testing.T, userns bool) {
t.Fatal(err)
}

process, err = os.FindProcess(pid)
_, err = os.FindProcess(pid)
if err != nil {
t.Fatal(err)
}
Expand All @@ -255,7 +255,7 @@ func testCheckpoint(t *testing.T, userns bool) {
t.Fatal(s.String(), pid)
}

output := string(stdout.Bytes())
output := stdout.String()
if !strings.Contains(output, "Hello!") {
t.Fatal("Did not restore the pipe correctly:", output)
}
Expand Down
12 changes: 6 additions & 6 deletions libcontainer/integration/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ func TestEnter(t *testing.T) {
waitProcess(&pconfig, t)

// Check that both processes live in the same pidns
pidns := string(stdout.Bytes())
pidns := stdout.String()
ok(t, err)

pidns2 := string(stdout2.Bytes())
pidns2 := stdout2.String()
ok(t, err)

if pidns != pidns2 {
Expand Down Expand Up @@ -325,7 +325,7 @@ func TestProcessEnv(t *testing.T) {
// Wait for process
waitProcess(&pconfig, t)

outputEnv := string(stdout.Bytes())
outputEnv := stdout.String()

// Check that the environment has the key/value pair we added
if !strings.Contains(outputEnv, "FOO=BAR") {
Expand Down Expand Up @@ -964,7 +964,7 @@ func TestPassExtraFiles(t *testing.T) {

waitProcess(&process, t)

out := string(stdout.Bytes())
out := stdout.String()
// fd 5 is the directory handle for /proc/$$/fd
if out != "0 1 2 3 4 5" {
t.Fatalf("expected to have the file descriptors '0 1 2 3 4 5' passed to init, got '%s'", out)
Expand Down Expand Up @@ -1501,7 +1501,7 @@ func TestRootfsPropagationSlaveMount(t *testing.T) {
mountPropagated = false
dir2cont = filepath.Join(dir1cont, filepath.Base(dir2host))

propagationInfo := string(stdout2.Bytes())
propagationInfo := stdout2.String()
lines := strings.Split(propagationInfo, "\n")
for _, l := range lines {
linefields := strings.Split(l, " ")
Expand Down Expand Up @@ -1892,7 +1892,7 @@ func TestTmpfsCopyUp(t *testing.T) {
// Wait for process
waitProcess(&pconfig, t)

outputLs := string(stdout.Bytes())
outputLs := stdout.String()

// Check that the ls output has /etc/passwd
if !strings.Contains(outputLs, "/etc/passwd") {
Expand Down
1 change: 0 additions & 1 deletion libcontainer/nsenter/nsenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ func init() {
if strings.HasPrefix(os.Args[0], "nsenter-") {
os.Exit(0)
}
return
}

func newPipe() (parent *os.File, child *os.File, err error) {
Expand Down
6 changes: 3 additions & 3 deletions libcontainer/seccomp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var archs = map[string]string{
// Attempting to convert a string that is not a valid operator results in an
// error.
func ConvertStringToOperator(in string) (configs.Operator, error) {
if op, ok := operators[in]; ok == true {
if op, ok := operators[in]; ok {
return op, nil
}
return 0, fmt.Errorf("string %s is not a valid operator for seccomp", in)
Expand All @@ -62,15 +62,15 @@ func ConvertStringToOperator(in string) (configs.Operator, error) {
// Attempting to convert a string that is not a valid action results in an
// error.
func ConvertStringToAction(in string) (configs.Action, error) {
if act, ok := actions[in]; ok == true {
if act, ok := actions[in]; ok {
return act, nil
}
return 0, fmt.Errorf("string %s is not a valid action for seccomp", in)
}

// ConvertStringToArch converts a string into a Seccomp comparison arch.
func ConvertStringToArch(in string) (string, error) {
if arch, ok := archs[in]; ok == true {
if arch, ok := archs[in]; ok {
return arch, nil
}
return "", fmt.Errorf("string %s is not a valid arch for seccomp", in)
Expand Down
4 changes: 2 additions & 2 deletions libcontainer/user/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ this is just some garbage data
t.Errorf("Parse(%#v) has error %v", test, err)
continue
}
sort.Sort(sort.IntSlice(gids))
sort.Ints(gids)
if !reflect.DeepEqual(gids, test.expected) {
t.Errorf("Gids(%v), expect %v from groups %v", gids, test.expected, test.groups)
}
Expand Down Expand Up @@ -499,7 +499,7 @@ func TestGetAdditionalGroupsNumeric(t *testing.T) {
t.Errorf("Parse(%#v) has error %v", test, err)
continue
}
sort.Sort(sort.IntSlice(gids))
sort.Ints(gids)
if !reflect.DeepEqual(gids, test.expected) {
t.Errorf("Gids(%v), expect %v from groups %v", gids, test.expected, test.groups)
}
Expand Down
8 changes: 6 additions & 2 deletions libcontainer/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ func TestSearchLabels(t *testing.T) {

func TestResolveRootfs(t *testing.T) {
dir := "rootfs"
os.Mkdir(dir, 0600)
if err := os.Mkdir(dir, 0600); err != nil {
t.Fatal(err)
}
defer os.Remove(dir)

path, err := ResolveRootfs(dir)
Expand All @@ -51,7 +53,9 @@ func TestResolveRootfs(t *testing.T) {
func TestResolveRootfsWithSymlink(t *testing.T) {
dir := "rootfs"
tmpDir, _ := filepath.EvalSymlinks(os.TempDir())
os.Symlink(tmpDir, dir)
if err := os.Symlink(tmpDir, dir); err != nil {
t.Fatal(err)
}
defer os.Remove(dir)

path, err := ResolveRootfs(dir)
Expand Down
5 changes: 4 additions & 1 deletion notify_socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ func (n *notifySocket) run(pid1 int) error {

// now we can inform systemd to use pid1 as the pid to monitor
newPid := "MAINPID=" + strconv.Itoa(pid1)
client.Write([]byte(newPid + "\n"))
_, err := client.Write([]byte(newPid + "\n"))
if err != nil {
return err
}
return nil
}
}
Expand Down
5 changes: 4 additions & 1 deletion tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ func (t *tty) recvtty(process *libcontainer.Process, socket *os.File) (Err error
if err != nil {
return err
}
console.ClearONLCR(cons.Fd())
err = console.ClearONLCR(cons.Fd())
if err != nil {
return err
}
epoller, err := console.NewEpoller()
if err != nil {
return err
Expand Down