Skip to content

Commit

Permalink
Fix simplification linter errors
Browse files Browse the repository at this point in the history
Signed-off-by: Amir Mohamad Ehsandar <[email protected]>
  • Loading branch information
ehsundar committed Oct 15, 2020
1 parent fe1e7bd commit 81a080f
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 31 deletions.
2 changes: 2 additions & 0 deletions libcontainer/cgroups/ebpf/ebpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ func LoadAttachCgroupDeviceFilter(insts asm.Instructions, license string, dirFD
if err != nil {
return nilCloser, err
}
//nolint:staticcheck
if err := prog.Attach(dirFD, ebpf.AttachCGroupDevice, unix.BPF_F_ALLOW_MULTI); err != nil {
return nilCloser, errors.Wrap(err, "failed to call BPF_PROG_ATTACH (BPF_CGROUP_DEVICE, BPF_F_ALLOW_MULTI)")
}
closer := func() error {
//nolint:staticcheck
if err := prog.Detach(dirFD, ebpf.AttachCGroupDevice, unix.BPF_F_ALLOW_MULTI); err != nil {
return errors.Wrap(err, "failed to call BPF_PROG_DETACH (BPF_CGROUP_DEVICE, BPF_F_ALLOW_MULTI)")
}
Expand Down
6 changes: 3 additions & 3 deletions libcontainer/cgroups/fs/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ func (s *NameGroup) Name() string {
return s.GroupName
}

func (s *NameGroup) Apply(path string, d *cgroupData) error {
func (s *NameGroup) Apply(path string, d *cgroupData) (err error) {
if s.Join {
// ignore errors if the named cgroup does not exist
join(path, d.pid)
err = join(path, d.pid)
}
return nil
return
}

func (s *NameGroup) Set(path string, cgroup *configs.Cgroup) error {
Expand Down
4 changes: 2 additions & 2 deletions libcontainer/cgroups/systemd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,11 @@ func startUnit(dbusConnection *systemdDbus.Conn, unitName string, properties []s
close(statusChan)
// Please refer to https://godoc.org/github.com/coreos/go-systemd/dbus#Conn.StartUnit
if s != "done" {
dbusConnection.ResetFailedUnit(unitName)
_ = dbusConnection.ResetFailedUnit(unitName)
return errors.Errorf("error creating systemd unit `%s`: got `%s`", unitName, s)
}
case <-timeout.C:
dbusConnection.ResetFailedUnit(unitName)
_ = dbusConnection.ResetFailedUnit(unitName)
return errors.New("Timeout waiting for systemd to create " + unitName)
}
} else if !isUnitExists(err) {
Expand Down
2 changes: 1 addition & 1 deletion libcontainer/cgroups/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func RemovePaths(paths map[string]string) (err error) {
}
}
if len(paths) == 0 {
//nolint:ineffassign // done to help garbage collecting: opencontainers/runc#2506
//nolint:staticcheck,ineffassign // done to help garbage collecting: opencontainers/runc#2506
paths = make(map[string]string)
return nil
}
Expand Down
37 changes: 20 additions & 17 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,7 @@ var criuFeatures *criurpc.CriuFeatures

func (c *linuxContainer) checkCriuFeatures(criuOpts *CriuOpts, rpcOpts *criurpc.CriuOpts, criuFeat *criurpc.CriuFeatures) error {

var t criurpc.CriuReqType
t = criurpc.CriuReqType_FEATURE_CHECK
var t criurpc.CriuReqType = criurpc.CriuReqType_FEATURE_CHECK

// make sure the features we are looking for are really not from
// some previous check
Expand Down Expand Up @@ -764,10 +763,7 @@ func (c *linuxContainer) checkCriuVersion(minVersion int) error {
const descriptorsFilename = "descriptors.json"

func (c *linuxContainer) addCriuDumpMount(req *criurpc.CriuReq, m *configs.Mount) {
mountDest := m.Destination
if strings.HasPrefix(mountDest, c.config.Rootfs) {
mountDest = mountDest[len(c.config.Rootfs):]
}
mountDest := strings.TrimPrefix(m.Destination, c.config.Rootfs)

extMnt := &criurpc.ExtMountMap{
Key: proto.String(mountDest),
Expand Down Expand Up @@ -1108,10 +1104,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error {
}

func (c *linuxContainer) addCriuRestoreMount(req *criurpc.CriuReq, m *configs.Mount) {
mountDest := m.Destination
if strings.HasPrefix(mountDest, c.config.Rootfs) {
mountDest = mountDest[len(c.config.Rootfs):]
}
mountDest := strings.TrimPrefix(m.Destination, c.config.Rootfs)

extMnt := &criurpc.ExtMountMap{
Key: proto.String(mountDest),
Expand Down Expand Up @@ -1216,7 +1209,7 @@ func (c *linuxContainer) prepareCriuRestoreMounts(mounts []*configs.Mount) error
return nil
}

func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) (err error) {
c.m.Lock()
defer c.m.Unlock()

Expand All @@ -1243,15 +1236,20 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
if err != nil {
return err
}
defer workDir.Close()
defer func() {
err = workDir.Close()
}()

if criuOpts.ImagesDirectory == "" {
return errors.New("invalid directory to restore checkpoint")
}
imageDir, err := os.Open(criuOpts.ImagesDirectory)
if err != nil {
return err
}
defer imageDir.Close()
defer func() {
err = imageDir.Close()
}()
// CRIU has a few requirements for a root directory:
// * it must be a mount point
// * its parent must not be overmounted
Expand All @@ -1261,7 +1259,9 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
if err := os.Mkdir(root, 0755); err != nil {
return err
}
defer os.Remove(root)
defer func() {
err = os.Remove(root)
}()
root, err = filepath.EvalSymlinks(root)
if err != nil {
return err
Expand All @@ -1270,7 +1270,9 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
if err != nil {
return err
}
defer unix.Unmount(root, unix.MNT_DETACH)
defer func() {
err = unix.Unmount(root, unix.MNT_DETACH)
}()
t := criurpc.CriuReqType_RESTORE
req := &criurpc.CriuReq{
Type: &t,
Expand Down Expand Up @@ -1378,7 +1380,7 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {

// Now that CRIU is done let's close all opened FDs CRIU needed.
for _, fd := range extraFiles {
fd.Close()
_ = fd.Close()
}

return err
Expand Down Expand Up @@ -1592,7 +1594,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 Expand Up @@ -1780,6 +1782,7 @@ func (c *linuxContainer) saveState(s *State) (retErr error) {
return os.Rename(tmpFile.Name(), stateFilePath)
}

//nolint:unused
func (c *linuxContainer) deleteState() error {
return os.Remove(filepath.Join(c.root, stateFilename))
}
Expand Down
9 changes: 4 additions & 5 deletions libcontainer/integration/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func TestProcessEmptyCaps(t *testing.T) {
// Wait for process
waitProcess(&pconfig, t)

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

lines := strings.Split(outputStatus, "\n")

Expand Down Expand Up @@ -423,7 +423,7 @@ func TestProcessCaps(t *testing.T) {
// Wait for process
waitProcess(&pconfig, t)

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

lines := strings.Split(outputStatus, "\n")

Expand All @@ -449,8 +449,7 @@ func TestProcessCaps(t *testing.T) {
}

var netAdminMask uint64
var netAdminBit uint
netAdminBit = 12 // from capability.h
var netAdminBit = uint(12) // from capability.h
netAdminMask = 1 << netAdminBit
if effectiveCaps&netAdminMask != netAdminMask {
t.Fatal("CAP_NET_ADMIN is not set as expected")
Expand Down Expand Up @@ -487,7 +486,7 @@ func TestAdditionalGroups(t *testing.T) {
// Wait for process
waitProcess(&pconfig, t)

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

// Check that the groups output has the groups that we specified
if !strings.Contains(outputGroups, "audio") {
Expand Down
4 changes: 3 additions & 1 deletion libcontainer/intelrdt/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ type monFeatures struct {

func getMonFeatures(intelRdtRoot string) (monFeatures, error) {
file, err := os.Open(filepath.Join(intelRdtRoot, "info", "L3_MON", "mon_features"))
defer file.Close()
defer func() {
_ = file.Close()
}()
if err != nil {
return monFeatures{}, err
}
Expand Down
10 changes: 8 additions & 2 deletions libcontainer/system/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,14 @@ func parseStat(data string) (stat Stat_t, err error) {
// one (PID) and two (Name) in the paren-split.
parts = strings.Split(data[i+2:], " ")
var state int
fmt.Sscanf(parts[3-3], "%c", &state)

if _, err = fmt.Sscanf(parts[3-3], "%c", &state); err != nil {
return Stat_t{}, err
}
stat.State = State(state)
fmt.Sscanf(parts[22-3], "%d", &stat.StartTime)

if _, err = fmt.Sscanf(parts[22-3], "%d", &stat.StartTime); err != nil {
return Stat_t{}, err
}
return stat, nil
}

0 comments on commit 81a080f

Please sign in to comment.