Skip to content

Commit ed47810

Browse files
committed
merge branch 'pr-2781'
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
2 parents e051128 + df0206a commit ed47810

18 files changed

+191
-176
lines changed

libcontainer/configs/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func (c Command) Run(s *specs.State) error {
387387
case err := <-errC:
388388
return err
389389
case <-timerCh:
390-
cmd.Process.Kill()
390+
_ = cmd.Process.Kill()
391391
<-errC
392392
return fmt.Errorf("hook ran past specified timeout of %.1fs", c.Timeout.Seconds())
393393
}

libcontainer/configs/config_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,15 @@ func TestFuncHookRun(t *testing.T) {
145145

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

153-
fHook.Run(state)
153+
err := fHook.Run(state)
154+
if err != nil {
155+
t.Fatal(err)
156+
}
154157
}
155158

156159
func TestCommandHookRun(t *testing.T) {

libcontainer/container_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
13521352
if err != nil {
13531353
return err
13541354
}
1355-
defer unix.Unmount(root, unix.MNT_DETACH)
1355+
defer unix.Unmount(root, unix.MNT_DETACH) //nolint: errcheck
13561356
t := criurpc.CriuReqType_RESTORE
13571357
req := &criurpc.CriuReq{
13581358
Type: &t,
@@ -1665,7 +1665,7 @@ func (c *linuxContainer) criuSwrk(process *Process, req *criurpc.CriuReq, opts *
16651665
break
16661666
}
16671667

1668-
criuClientCon.CloseWrite()
1668+
_ = criuClientCon.CloseWrite()
16691669
// cmd.Wait() waits cmd.goroutines which are used for proxying file descriptors.
16701670
// Here we want to wait only the CRIU process.
16711671
criuProcessState, err = criuProcess.Wait()

libcontainer/factory_linux.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,11 @@ func New(root string, options ...func(*LinuxFactory) error) (Factory, error) {
196196
Validator: validate.New(),
197197
CriuPath: "criu",
198198
}
199-
Cgroupfs(l)
199+
200+
if err := Cgroupfs(l); err != nil {
201+
return nil, err
202+
}
203+
200204
for _, opt := range options {
201205
if opt == nil {
202206
continue

libcontainer/factory_linux_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,18 @@ func TestFactoryNewTmpfs(t *testing.T) {
122122
if m.Source != "tmpfs" {
123123
t.Fatalf("Source of root: %s, expected %s", m.Source, "tmpfs")
124124
}
125-
unix.Unmount(root, unix.MNT_DETACH)
125+
err = unix.Unmount(root, unix.MNT_DETACH)
126+
if err != nil {
127+
t.Error("failed to unmount root:", err)
128+
}
126129
}
127130

128131
func TestFactoryLoadNotExists(t *testing.T) {
129132
root, rerr := newTestRoot()
130133
if rerr != nil {
131134
t.Fatal(rerr)
132135
}
133-
defer os.RemoveAll(root)
136+
defer os.RemoveAll(root) //nolint: errcheck
134137
factory, err := New(root, Cgroupfs)
135138
if err != nil {
136139
t.Fatal(err)
@@ -153,7 +156,7 @@ func TestFactoryLoadContainer(t *testing.T) {
153156
if err != nil {
154157
t.Fatal(err)
155158
}
156-
defer os.RemoveAll(root)
159+
defer os.RemoveAll(root) //nolint: errcheck
157160
// setup default container config and state for mocking
158161
var (
159162
id = "1"
@@ -219,7 +222,7 @@ func marshal(path string, v interface{}) error {
219222
if err != nil {
220223
return err
221224
}
222-
defer f.Close()
225+
defer f.Close() //nolint: errcheck
223226
return utils.WriteJSON(f, v)
224227
}
225228

libcontainer/integration/checkpoint_test.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,28 @@ import (
1414
"golang.org/x/sys/unix"
1515
)
1616

17-
func showFile(t *testing.T, fname string) error {
17+
func showFile(t *testing.T, fname string) {
1818
t.Helper()
1919
t.Logf("=== %s ===\n", fname)
2020

2121
f, err := os.Open(fname)
2222
if err != nil {
2323
t.Log(err)
24-
return err
24+
return
2525
}
26-
defer f.Close()
26+
defer f.Close() //nolint: errcheck
2727

2828
scanner := bufio.NewScanner(f)
2929
for scanner.Scan() {
3030
t.Log(scanner.Text())
3131
}
3232

3333
if err := scanner.Err(); err != nil {
34-
return err
34+
t.Log(err)
35+
return
3536
}
3637

3738
t.Logf("=== END ===\n")
38-
39-
return nil
4039
}
4140

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

6665
root, err := newTestRoot()
6766
ok(t, err)
68-
defer os.RemoveAll(root)
67+
defer remove(root)
6968

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

8180
container, err := factory.Create("test", config)
8281
ok(t, err)
83-
defer container.Destroy()
82+
defer destroyContainer(container)
8483

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

9998
err = container.Run(&pconfig)
100-
stdinR.Close()
101-
defer stdinW.Close()
99+
_ = stdinR.Close()
100+
defer stdinW.Close() //nolint: errcheck
102101
ok(t, err)
103102

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

110109
parentDir, err := ioutil.TempDir("", "criu-parent")
111110
ok(t, err)
112-
defer os.RemoveAll(parentDir)
111+
defer remove(parentDir)
113112

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

133132
imagesDir, err := ioutil.TempDir("", "criu")
134133
ok(t, err)
135-
defer os.RemoveAll(imagesDir)
134+
defer remove(imagesDir)
136135

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

157-
stdinW.Close()
156+
_ = stdinW.Close()
158157
_, err = process.Wait()
159158
ok(t, err)
160159

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

176175
err = container.Restore(restoreProcessConfig, checkpointOpts)
177-
restoreStdinR.Close()
178-
defer restoreStdinW.Close()
176+
_ = restoreStdinR.Close()
177+
defer restoreStdinW.Close() //nolint: errcheck
179178
if err != nil {
180179
showFile(t, restoreLog)
181180
t.Fatal(err)
@@ -196,7 +195,7 @@ func testCheckpoint(t *testing.T, userns bool) {
196195
_, err = restoreStdinW.WriteString("Hello!")
197196
ok(t, err)
198197

199-
restoreStdinW.Close()
198+
_ = restoreStdinW.Close()
200199
waitProcess(restoreProcessConfig, t)
201200

202201
output := restoreStdout.String()

0 commit comments

Comments
 (0)