Skip to content

Commit

Permalink
merge branch 'pr-2781'
Browse files Browse the repository at this point in the history
Sebastiaan van Stijn (7):
  errcheck: utils
  errcheck: signals
  errcheck: tty
  errcheck: libcontainer
  errcheck: libcontainer/nsenter
  errcheck: libcontainer/configs
  errcheck: libcontainer/integration

LGTM: AkihiroSuda cyphar
Closes #2781
  • Loading branch information
cyphar committed May 25, 2021
2 parents e051128 + df0206a commit ed47810
Show file tree
Hide file tree
Showing 18 changed files with 191 additions and 176 deletions.
2 changes: 1 addition & 1 deletion libcontainer/configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func (c Command) Run(s *specs.State) error {
case err := <-errC:
return err
case <-timerCh:
cmd.Process.Kill()
_ = cmd.Process.Kill()
<-errC
return fmt.Errorf("hook ran past specified timeout of %.1fs", c.Timeout.Seconds())
}
Expand Down
7 changes: 5 additions & 2 deletions libcontainer/configs/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,15 @@ func TestFuncHookRun(t *testing.T) {

fHook := configs.NewFunctionHook(func(s *specs.State) error {
if !reflect.DeepEqual(state, s) {
t.Errorf("Expected state %+v to equal %+v", state, s)
return fmt.Errorf("expected state %+v to equal %+v", state, s)
}
return nil
})

fHook.Run(state)
err := fHook.Run(state)
if err != nil {
t.Fatal(err)
}
}

func TestCommandHookRun(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
if err != nil {
return err
}
defer unix.Unmount(root, unix.MNT_DETACH)
defer unix.Unmount(root, unix.MNT_DETACH) //nolint: errcheck
t := criurpc.CriuReqType_RESTORE
req := &criurpc.CriuReq{
Type: &t,
Expand Down Expand Up @@ -1665,7 +1665,7 @@ func (c *linuxContainer) criuSwrk(process *Process, req *criurpc.CriuReq, opts *
break
}

criuClientCon.CloseWrite()
_ = criuClientCon.CloseWrite()
// cmd.Wait() waits cmd.goroutines which are used for proxying file descriptors.
// Here we want to wait only the CRIU process.
criuProcessState, err = criuProcess.Wait()
Expand Down
6 changes: 5 additions & 1 deletion libcontainer/factory_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,11 @@ func New(root string, options ...func(*LinuxFactory) error) (Factory, error) {
Validator: validate.New(),
CriuPath: "criu",
}
Cgroupfs(l)

if err := Cgroupfs(l); err != nil {
return nil, err
}

for _, opt := range options {
if opt == nil {
continue
Expand Down
11 changes: 7 additions & 4 deletions libcontainer/factory_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,18 @@ func TestFactoryNewTmpfs(t *testing.T) {
if m.Source != "tmpfs" {
t.Fatalf("Source of root: %s, expected %s", m.Source, "tmpfs")
}
unix.Unmount(root, unix.MNT_DETACH)
err = unix.Unmount(root, unix.MNT_DETACH)
if err != nil {
t.Error("failed to unmount root:", err)
}
}

func TestFactoryLoadNotExists(t *testing.T) {
root, rerr := newTestRoot()
if rerr != nil {
t.Fatal(rerr)
}
defer os.RemoveAll(root)
defer os.RemoveAll(root) //nolint: errcheck
factory, err := New(root, Cgroupfs)
if err != nil {
t.Fatal(err)
Expand All @@ -153,7 +156,7 @@ func TestFactoryLoadContainer(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(root)
defer os.RemoveAll(root) //nolint: errcheck
// setup default container config and state for mocking
var (
id = "1"
Expand Down Expand Up @@ -219,7 +222,7 @@ func marshal(path string, v interface{}) error {
if err != nil {
return err
}
defer f.Close()
defer f.Close() //nolint: errcheck
return utils.WriteJSON(f, v)
}

Expand Down
31 changes: 15 additions & 16 deletions libcontainer/integration/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,28 @@ import (
"golang.org/x/sys/unix"
)

func showFile(t *testing.T, fname string) error {
func showFile(t *testing.T, fname string) {
t.Helper()
t.Logf("=== %s ===\n", fname)

f, err := os.Open(fname)
if err != nil {
t.Log(err)
return err
return
}
defer f.Close()
defer f.Close() //nolint: errcheck

scanner := bufio.NewScanner(f)
for scanner.Scan() {
t.Log(scanner.Text())
}

if err := scanner.Err(); err != nil {
return err
t.Log(err)
return
}

t.Logf("=== END ===\n")

return nil
}

func TestUsernsCheckpoint(t *testing.T) {
Expand Down Expand Up @@ -65,7 +64,7 @@ func testCheckpoint(t *testing.T, userns bool) {

root, err := newTestRoot()
ok(t, err)
defer os.RemoveAll(root)
defer remove(root)

rootfs, err := newRootfs()
ok(t, err)
Expand All @@ -80,7 +79,7 @@ func testCheckpoint(t *testing.T, userns bool) {

container, err := factory.Create("test", config)
ok(t, err)
defer container.Destroy()
defer destroyContainer(container)

stdinR, stdinW, err := os.Pipe()
ok(t, err)
Expand All @@ -97,8 +96,8 @@ func testCheckpoint(t *testing.T, userns bool) {
}

err = container.Run(&pconfig)
stdinR.Close()
defer stdinW.Close()
_ = stdinR.Close()
defer stdinW.Close() //nolint: errcheck
ok(t, err)

pid, err := pconfig.Pid()
Expand All @@ -109,7 +108,7 @@ func testCheckpoint(t *testing.T, userns bool) {

parentDir, err := ioutil.TempDir("", "criu-parent")
ok(t, err)
defer os.RemoveAll(parentDir)
defer remove(parentDir)

preDumpOpts := &libcontainer.CriuOpts{
ImagesDirectory: parentDir,
Expand All @@ -132,7 +131,7 @@ func testCheckpoint(t *testing.T, userns bool) {

imagesDir, err := ioutil.TempDir("", "criu")
ok(t, err)
defer os.RemoveAll(imagesDir)
defer remove(imagesDir)

checkpointOpts := &libcontainer.CriuOpts{
ImagesDirectory: imagesDir,
Expand All @@ -154,7 +153,7 @@ func testCheckpoint(t *testing.T, userns bool) {
t.Fatal("Unexpected state checkpoint: ", state)
}

stdinW.Close()
_ = stdinW.Close()
_, err = process.Wait()
ok(t, err)

Expand All @@ -174,8 +173,8 @@ func testCheckpoint(t *testing.T, userns bool) {
}

err = container.Restore(restoreProcessConfig, checkpointOpts)
restoreStdinR.Close()
defer restoreStdinW.Close()
_ = restoreStdinR.Close()
defer restoreStdinW.Close() //nolint: errcheck
if err != nil {
showFile(t, restoreLog)
t.Fatal(err)
Expand All @@ -196,7 +195,7 @@ func testCheckpoint(t *testing.T, userns bool) {
_, err = restoreStdinW.WriteString("Hello!")
ok(t, err)

restoreStdinW.Close()
_ = restoreStdinW.Close()
waitProcess(restoreProcessConfig, t)

output := restoreStdout.String()
Expand Down
Loading

0 comments on commit ed47810

Please sign in to comment.