Skip to content

Commit 0c0ec3f

Browse files
authored
Merge pull request #3302 from kolyshkin/ci-unparam
Enable unparam linter; fix/mute existing warnings
2 parents 6ff0420 + 02475d9 commit 0c0ec3f

13 files changed

+45
-56
lines changed

.golangci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ linters:
99
- gofumpt
1010
- errorlint
1111
- unconvert
12+
- unparam

checkpoint.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ checkpointed.`,
8080
func prepareImagePaths(context *cli.Context) (string, string, error) {
8181
imagePath := context.String("image-path")
8282
if imagePath == "" {
83-
imagePath = getDefaultImagePath(context)
83+
imagePath = getDefaultImagePath()
8484
}
8585

8686
if err := os.MkdirAll(imagePath, 0o600); err != nil {

libcontainer/cgroups/devices/devices_emulator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func parseLine(line string) (*deviceRule, error) {
139139
return &rule, nil
140140
}
141141

142-
func (e *Emulator) addRule(rule deviceRule) error {
142+
func (e *Emulator) addRule(rule deviceRule) error { //nolint:unparam
143143
if e.rules == nil {
144144
e.rules = make(map[deviceMeta]devices.Permissions)
145145
}

libcontainer/cgroups/ebpf/devicefilter/devicefilter.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ func DeviceFilter(rules []*devices.Rule) (asm.Instructions, string, error) {
6565
return nil, "", err
6666
}
6767
}
68-
insts, err := p.finalize()
69-
return insts, license, err
68+
return p.finalize(), license, nil
7069
}
7170

7271
type program struct {
@@ -181,7 +180,7 @@ func (p *program) appendRule(rule *devices.Rule) error {
181180
return nil
182181
}
183182

184-
func (p *program) finalize() (asm.Instructions, error) {
183+
func (p *program) finalize() asm.Instructions {
185184
var v int32
186185
if p.defaultAllow {
187186
v = 1
@@ -193,7 +192,7 @@ func (p *program) finalize() (asm.Instructions, error) {
193192
asm.Return(),
194193
)
195194
p.blockID = -1
196-
return p.insts, nil
195+
return p.insts
197196
}
198197

199198
func acceptBlock(accept bool) asm.Instructions {

libcontainer/cgroups/fs/blkio_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ type blkioStatFailureTestCase struct {
164164
filename string
165165
}
166166

167-
func appendBlkioStatEntry(blkioStatEntries *[]cgroups.BlkioStatEntry, major, minor, value uint64, op string) {
167+
func appendBlkioStatEntry(blkioStatEntries *[]cgroups.BlkioStatEntry, major, minor, value uint64, op string) { //nolint:unparam
168168
*blkioStatEntries = append(*blkioStatEntries, cgroups.BlkioStatEntry{Major: major, Minor: minor, Value: value, Op: op})
169169
}
170170

libcontainer/factory_linux.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func (l *LinuxFactory) Load(id string) (Container, error) {
231231
if err != nil {
232232
return nil, err
233233
}
234-
state, err := l.loadState(containerRoot, id)
234+
state, err := l.loadState(containerRoot)
235235
if err != nil {
236236
return nil, err
237237
}
@@ -351,7 +351,7 @@ func (l *LinuxFactory) StartInitialization() (err error) {
351351
return i.Init()
352352
}
353353

354-
func (l *LinuxFactory) loadState(root, id string) (*State, error) {
354+
func (l *LinuxFactory) loadState(root string) (*State, error) {
355355
stateFilePath, err := securejoin.SecureJoin(root, stateFilename)
356356
if err != nil {
357357
return nil, err

libcontainer/init_linux.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ func setupUser(config *initConfig) error {
360360

361361
// Before we change to the container's user make sure that the processes
362362
// STDIO is correctly owned by the user that we are switching to.
363-
if err := fixStdioPermissions(config, execUser); err != nil {
363+
if err := fixStdioPermissions(execUser); err != nil {
364364
return err
365365
}
366366

@@ -401,7 +401,7 @@ func setupUser(config *initConfig) error {
401401
// fixStdioPermissions fixes the permissions of PID 1's STDIO within the container to the specified user.
402402
// The ownership needs to match because it is created outside of the container and needs to be
403403
// localized.
404-
func fixStdioPermissions(config *initConfig, u *user.ExecUser) error {
404+
func fixStdioPermissions(u *user.ExecUser) error {
405405
var null unix.Stat_t
406406
if err := unix.Stat("/dev/null", &null); err != nil {
407407
return &os.PathError{Op: "stat", Path: "/dev/null", Err: err}

libcontainer/integration/exec_test.go

+19-19
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func testExecPS(t *testing.T, userns bool) {
4040
}
4141
config := newTemplateConfig(t, &tParam{userns: userns})
4242

43-
buffers, exitCode, err := runContainer(t, config, "", "ps", "-o", "pid,user,comm")
43+
buffers, exitCode, err := runContainer(t, config, "ps", "-o", "pid,user,comm")
4444
if err != nil {
4545
t.Fatalf("%s: %s", buffers, err)
4646
}
@@ -67,7 +67,7 @@ func TestIPCPrivate(t *testing.T) {
6767
ok(t, err)
6868

6969
config := newTemplateConfig(t, nil)
70-
buffers, exitCode, err := runContainer(t, config, "", "readlink", "/proc/self/ns/ipc")
70+
buffers, exitCode, err := runContainer(t, config, "readlink", "/proc/self/ns/ipc")
7171
ok(t, err)
7272

7373
if exitCode != 0 {
@@ -89,7 +89,7 @@ func TestIPCHost(t *testing.T) {
8989

9090
config := newTemplateConfig(t, nil)
9191
config.Namespaces.Remove(configs.NEWIPC)
92-
buffers, exitCode, err := runContainer(t, config, "", "readlink", "/proc/self/ns/ipc")
92+
buffers, exitCode, err := runContainer(t, config, "readlink", "/proc/self/ns/ipc")
9393
ok(t, err)
9494

9595
if exitCode != 0 {
@@ -112,7 +112,7 @@ func TestIPCJoinPath(t *testing.T) {
112112
config := newTemplateConfig(t, nil)
113113
config.Namespaces.Add(configs.NEWIPC, "/proc/1/ns/ipc")
114114

115-
buffers, exitCode, err := runContainer(t, config, "", "readlink", "/proc/self/ns/ipc")
115+
buffers, exitCode, err := runContainer(t, config, "readlink", "/proc/self/ns/ipc")
116116
ok(t, err)
117117

118118
if exitCode != 0 {
@@ -132,7 +132,7 @@ func TestIPCBadPath(t *testing.T) {
132132
config := newTemplateConfig(t, nil)
133133
config.Namespaces.Add(configs.NEWIPC, "/proc/1/ns/ipcc")
134134

135-
if _, _, err := runContainer(t, config, "", "true"); err == nil {
135+
if _, _, err := runContainer(t, config, "true"); err == nil {
136136
t.Fatal("container succeeded with bad ipc path")
137137
}
138138
}
@@ -163,7 +163,7 @@ func testRlimit(t *testing.T, userns bool) {
163163
Cur: 1024,
164164
}))
165165

166-
out, _, err := runContainer(t, config, "", "/bin/sh", "-c", "ulimit -n")
166+
out, _, err := runContainer(t, config, "/bin/sh", "-c", "ulimit -n")
167167
ok(t, err)
168168
if limit := strings.TrimSpace(out.Stdout.String()); limit != "1025" {
169169
t.Fatalf("expected rlimit to be 1025, got %s", limit)
@@ -537,7 +537,7 @@ func testCpuShares(t *testing.T, systemd bool) {
537537
config := newTemplateConfig(t, &tParam{systemd: systemd})
538538
config.Cgroups.Resources.CpuShares = 1
539539

540-
if _, _, err := runContainer(t, config, "", "ps"); err == nil {
540+
if _, _, err := runContainer(t, config, "ps"); err == nil {
541541
t.Fatalf("runContainer should failed with invalid CpuShares")
542542
}
543543
}
@@ -562,7 +562,7 @@ func testPids(t *testing.T, systemd bool) {
562562
config.Cgroups.Resources.PidsLimit = -1
563563

564564
// Running multiple processes.
565-
_, ret, err := runContainer(t, config, "", "/bin/sh", "-c", "/bin/true | /bin/true | /bin/true | /bin/true")
565+
_, ret, err := runContainer(t, config, "/bin/sh", "-c", "/bin/true | /bin/true | /bin/true | /bin/true")
566566
ok(t, err)
567567

568568
if ret != 0 {
@@ -572,7 +572,7 @@ func testPids(t *testing.T, systemd bool) {
572572
// Enforce a permissive limit. This needs to be fairly hand-wavey due to the
573573
// issues with running Go binaries with pids restrictions (see below).
574574
config.Cgroups.Resources.PidsLimit = 64
575-
_, ret, err = runContainer(t, config, "", "/bin/sh", "-c", `
575+
_, ret, err = runContainer(t, config, "/bin/sh", "-c", `
576576
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
577577
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
578578
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
@@ -586,7 +586,7 @@ func testPids(t *testing.T, systemd bool) {
586586
// Enforce a restrictive limit. 64 * /bin/true + 1 * shell should cause this
587587
// to fail reliability.
588588
config.Cgroups.Resources.PidsLimit = 64
589-
out, _, err := runContainer(t, config, "", "/bin/sh", "-c", `
589+
out, _, err := runContainer(t, config, "/bin/sh", "-c", `
590590
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
591591
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
592592
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
@@ -632,7 +632,7 @@ func testCgroupResourcesUnifiedErrorOnV1(t *testing.T, systemd bool) {
632632
config.Cgroups.Resources.Unified = map[string]string{
633633
"memory.min": "10240",
634634
}
635-
_, _, err := runContainer(t, config, "", "true")
635+
_, _, err := runContainer(t, config, "true")
636636
if !strings.Contains(err.Error(), cgroups.ErrV1NoUnified.Error()) {
637637
t.Fatalf("expected error to contain %v, got %v", cgroups.ErrV1NoUnified, err)
638638
}
@@ -716,7 +716,7 @@ func testCgroupResourcesUnified(t *testing.T, systemd bool) {
716716

717717
for _, tc := range testCases {
718718
config.Cgroups.Resources.Unified = tc.cfg
719-
buffers, ret, err := runContainer(t, config, "", tc.cmd...)
719+
buffers, ret, err := runContainer(t, config, tc.cmd...)
720720
if tc.expError != "" {
721721
if err == nil {
722722
t.Errorf("case %q failed: expected error, got nil", tc.name)
@@ -934,7 +934,7 @@ func TestMountCgroupRO(t *testing.T) {
934934
return
935935
}
936936
config := newTemplateConfig(t, nil)
937-
buffers, exitCode, err := runContainer(t, config, "", "mount")
937+
buffers, exitCode, err := runContainer(t, config, "mount")
938938
if err != nil {
939939
t.Fatalf("%s: %s", buffers, err)
940940
}
@@ -981,7 +981,7 @@ func TestMountCgroupRW(t *testing.T) {
981981
}
982982
}
983983

984-
buffers, exitCode, err := runContainer(t, config, "", "mount")
984+
buffers, exitCode, err := runContainer(t, config, "mount")
985985
if err != nil {
986986
t.Fatalf("%s: %s", buffers, err)
987987
}
@@ -1198,7 +1198,7 @@ func TestSTDIOPermissions(t *testing.T) {
11981198
}
11991199

12001200
config := newTemplateConfig(t, nil)
1201-
buffers, exitCode, err := runContainer(t, config, "", "sh", "-c", "echo hi > /dev/stderr")
1201+
buffers, exitCode, err := runContainer(t, config, "sh", "-c", "echo hi > /dev/stderr")
12021202
ok(t, err)
12031203
if exitCode != 0 {
12041204
t.Fatalf("exit code not 0. code %d stderr %q", exitCode, buffers.Stderr)
@@ -1446,7 +1446,7 @@ func TestPIDHost(t *testing.T) {
14461446

14471447
config := newTemplateConfig(t, nil)
14481448
config.Namespaces.Remove(configs.NEWPID)
1449-
buffers, exitCode, err := runContainer(t, config, "", "readlink", "/proc/self/ns/pid")
1449+
buffers, exitCode, err := runContainer(t, config, "readlink", "/proc/self/ns/pid")
14501450
ok(t, err)
14511451

14521452
if exitCode != 0 {
@@ -1740,7 +1740,7 @@ func TestCGROUPPrivate(t *testing.T) {
17401740

17411741
config := newTemplateConfig(t, nil)
17421742
config.Namespaces.Add(configs.NEWCGROUP, "")
1743-
buffers, exitCode, err := runContainer(t, config, "", "readlink", "/proc/self/ns/cgroup")
1743+
buffers, exitCode, err := runContainer(t, config, "readlink", "/proc/self/ns/cgroup")
17441744
ok(t, err)
17451745

17461746
if exitCode != 0 {
@@ -1764,7 +1764,7 @@ func TestCGROUPHost(t *testing.T) {
17641764
ok(t, err)
17651765

17661766
config := newTemplateConfig(t, nil)
1767-
buffers, exitCode, err := runContainer(t, config, "", "readlink", "/proc/self/ns/cgroup")
1767+
buffers, exitCode, err := runContainer(t, config, "readlink", "/proc/self/ns/cgroup")
17681768
ok(t, err)
17691769

17701770
if exitCode != 0 {
@@ -1801,7 +1801,7 @@ func testFdLeaks(t *testing.T, systemd bool) {
18011801
ok(t, err)
18021802

18031803
config := newTemplateConfig(t, &tParam{systemd: systemd})
1804-
buffers, exitCode, err := runContainer(t, config, "", "true")
1804+
buffers, exitCode, err := runContainer(t, config, "true")
18051805
ok(t, err)
18061806

18071807
if exitCode != 0 {

libcontainer/integration/seccomp_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func TestSeccompPermitWriteMultipleConditions(t *testing.T) {
282282
},
283283
}
284284

285-
buffers, exitCode, err := runContainer(t, config, "", "ls", "/")
285+
buffers, exitCode, err := runContainer(t, config, "ls", "/")
286286
if err != nil {
287287
t.Fatalf("%s: %s", buffers, err)
288288
}
@@ -331,7 +331,7 @@ func TestSeccompDenyWriteMultipleConditions(t *testing.T) {
331331
},
332332
}
333333

334-
buffers, exitCode, err := runContainer(t, config, "", "ls", "/does_not_exist")
334+
buffers, exitCode, err := runContainer(t, config, "ls", "/does_not_exist")
335335
if err == nil {
336336
t.Fatalf("Expecting error return, instead got 0")
337337
}
@@ -375,7 +375,7 @@ func TestSeccompMultipleConditionSameArgDeniesStdout(t *testing.T) {
375375
},
376376
}
377377

378-
buffers, exitCode, err := runContainer(t, config, "", "ls", "/")
378+
buffers, exitCode, err := runContainer(t, config, "ls", "/")
379379
if err != nil {
380380
t.Fatalf("%s: %s", buffers, err)
381381
}
@@ -417,7 +417,7 @@ func TestSeccompMultipleConditionSameArgDeniesStderr(t *testing.T) {
417417
},
418418
}
419419

420-
buffers, exitCode, err := runContainer(t, config, "", "ls", "/does_not_exist")
420+
buffers, exitCode, err := runContainer(t, config, "ls", "/does_not_exist")
421421
if err == nil {
422422
t.Fatalf("Expecting error return, instead got 0")
423423
}

libcontainer/integration/utils_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func newContainer(t *testing.T, config *configs.Config) (libcontainer.Container,
180180
//
181181
// buffers are returned containing the STDOUT and STDERR output for the run
182182
// along with the exit code and any go error
183-
func runContainer(t *testing.T, config *configs.Config, console string, args ...string) (buffers *stdBuffers, exitCode int, err error) {
183+
func runContainer(t *testing.T, config *configs.Config, args ...string) (buffers *stdBuffers, exitCode int, err error) {
184184
container, err := newContainer(t, config)
185185
if err != nil {
186186
return nil, -1, err

notify_socket.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (s *notifySocket) Close() error {
4343

4444
// If systemd is supporting sd_notify protocol, this function will add support
4545
// for sd_notify protocol from within the container.
46-
func (s *notifySocket) setupSpec(context *cli.Context, spec *specs.Spec) error {
46+
func (s *notifySocket) setupSpec(spec *specs.Spec) {
4747
pathInContainer := filepath.Join("/run/notify", path.Base(s.socketPath))
4848
mount := specs.Mount{
4949
Destination: path.Dir(pathInContainer),
@@ -52,7 +52,6 @@ func (s *notifySocket) setupSpec(context *cli.Context, spec *specs.Spec) error {
5252
}
5353
spec.Mounts = append(spec.Mounts, mount)
5454
spec.Process.Env = append(spec.Process.Env, "NOTIFY_SOCKET="+pathInContainer)
55-
return nil
5655
}
5756

5857
func (s *notifySocket) bindSocket() error {

tty.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ func setupProcessPipes(p *libcontainer.Process, rootuid, rootgid int) (*tty, err
6363
return t, nil
6464
}
6565

66-
func inheritStdio(process *libcontainer.Process) error {
66+
func inheritStdio(process *libcontainer.Process) {
6767
process.Stdin = os.Stdin
6868
process.Stdout = os.Stdout
6969
process.Stderr = os.Stderr
70-
return nil
7170
}
7271

7372
func (t *tty) initHostConsole() error {
@@ -100,7 +99,7 @@ func (t *tty) initHostConsole() error {
10099
return nil
101100
}
102101

103-
func (t *tty) recvtty(process *libcontainer.Process, socket *os.File) (Err error) {
102+
func (t *tty) recvtty(socket *os.File) (Err error) {
104103
f, err := utils.RecvFd(socket)
105104
if err != nil {
106105
return err
@@ -160,16 +159,15 @@ func (t *tty) waitConsole() error {
160159

161160
// ClosePostStart closes any fds that are provided to the container and dup2'd
162161
// so that we no longer have copy in our process.
163-
func (t *tty) ClosePostStart() error {
162+
func (t *tty) ClosePostStart() {
164163
for _, c := range t.postStart {
165164
_ = c.Close()
166165
}
167-
return nil
168166
}
169167

170168
// Close closes all open fds for the tty and/or restores the original
171169
// stdin state to what it was prior to the container execution
172-
func (t *tty) Close() error {
170+
func (t *tty) Close() {
173171
// ensure that our side of the fds are always closed
174172
for _, c := range t.postStart {
175173
_ = c.Close()
@@ -186,7 +184,6 @@ func (t *tty) Close() error {
186184
if t.hostConsole != nil {
187185
_ = t.hostConsole.Reset()
188186
}
189-
return nil
190187
}
191188

192189
func (t *tty) resize() error {

0 commit comments

Comments
 (0)