Skip to content

Commit

Permalink
chore(crit): enable linting
Browse files Browse the repository at this point in the history
Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
  • Loading branch information
snprajwal committed Aug 11, 2022
1 parent 4a3d27b commit a76d73f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 23 deletions.
11 changes: 4 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
run:
skip-dirs:
- rpc
- stats
- crit

linters:
disable-all: false
presets:
- bugs
- performance
- unused
- format

linters-settings:
exhaustive:
default-signifies-exhaustive: true
52 changes: 41 additions & 11 deletions crit/decode-extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ func decodePipesData(
extraSize := p.GetBytes()

if noPayload {
f.Seek(int64(extraSize), 1)
_, err := f.Seek(int64(extraSize), 1)
if err != nil {
return "", err
}
return countBytes(int64(extraSize)), nil
}
extraBuf := make([]byte, extraSize)
Expand All @@ -49,7 +52,10 @@ func decodeSkQueues(
extraSize := p.GetLength()

if noPayload {
f.Seek(int64(extraSize), 1)
_, err := f.Seek(int64(extraSize), 1)
if err != nil {
return "", err
}
return countBytes(int64(extraSize)), nil
}
extraBuf := make([]byte, extraSize)
Expand Down Expand Up @@ -78,7 +84,10 @@ func decodeTcpStream(
outQLen := p.GetOutqLen()

if noPayload {
f.Seek(0, 2)
_, err := f.Seek(0, 2)
if err != nil {
return "", err
}
return countBytes(int64(inQLen + outQLen)), nil
}

Expand Down Expand Up @@ -111,7 +120,10 @@ func decodeBpfmapData(
extraSize := p.GetKeysBytes() + p.GetValuesBytes()

if noPayload {
f.Seek(int64(extraSize), 1)
_, err := f.Seek(int64(extraSize), 1)
if err != nil {
return "", err
}
return countBytes(int64(extraSize)), nil
}
extraBuf := make([]byte, extraSize)
Expand All @@ -137,7 +149,10 @@ func decodeIpcSem(
roundedSize := (extraSize/8 + 1) * 8

if noPayload {
f.Seek(roundedSize, 1)
_, err := f.Seek(roundedSize, 1)
if err != nil {
return "", err
}
return countBytes(extraSize), nil
}
extraPayload := []uint16{}
Expand All @@ -149,7 +164,10 @@ func decodeIpcSem(
}
extraPayload = append(extraPayload, binary.LittleEndian.Uint16(extraBuf))
}
f.Seek(roundedSize-extraSize, 1)
_, err := f.Seek(roundedSize-extraSize, 1)
if err != nil {
return "", err
}
extraJson, err := json.Marshal(extraPayload)
return string(extraJson), err
}
Expand All @@ -169,14 +187,20 @@ func decodeIpcShm(
roundedSize := (extraSize/4 + 1) * 4

if noPayload {
f.Seek(roundedSize, 1)
_, err := f.Seek(roundedSize, 1)
if err != nil {
return "", err
}
return countBytes(extraSize), nil
}
extraBuf := make([]byte, extraSize)
if _, err := f.Read(extraBuf); err != nil {
return "", err
}
f.Seek(roundedSize-extraSize, 1)
_, err := f.Seek(roundedSize-extraSize, 1)
if err != nil {
return "", err
}
return base64.StdEncoding.EncodeToString(extraBuf), nil
}

Expand All @@ -200,7 +224,7 @@ func decodeIpcMsg(
for i := 0; i < int(msgQNum); i++ {
n, err := f.Read(sizeBuf)
if n == 0 {
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
return "", err
Expand All @@ -219,7 +243,10 @@ func decodeIpcMsg(
roundedMsgSize := (msgSize/8 + 1) * 8

if noPayload {
f.Seek(roundedMsgSize, 1)
_, err = f.Seek(roundedMsgSize, 1)
if err != nil {
return "", err
}
totalSize += int64(extraSize) + msgSize
} else {
jsonMsg, err := protojson.Marshal(msg)
Expand All @@ -234,7 +261,10 @@ func decodeIpcMsg(
}
msgData := base64.StdEncoding.EncodeToString(msgDataBuf)
extraPayload = append(extraPayload, msgData)
f.Seek(roundedMsgSize-msgSize, 1)
_, err = f.Seek(roundedMsgSize-msgSize, 1)
if err != nil {
return "", err
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion crit/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package crit
import (
"encoding/base64"
"encoding/binary"
"errors"
"io"
"os"

Expand Down Expand Up @@ -149,7 +150,7 @@ func (img *CriuImage) decodeGhostFile(f *os.File, noPayload bool) error {
for {
n, err := f.Read(sizeBuf)
if n == 0 {
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
return err
Expand Down
6 changes: 3 additions & 3 deletions crit/explore.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (c *crit) ExploreFds() ([]*Fd, error) {
return nil, err
}

var fds []*Fd
fds := make([]*Fd, 0)
for _, entry := range psTreeImg.Entries {
process := entry.Message.(*images.PstreeEntry)
pId := process.GetPid()
Expand Down Expand Up @@ -176,7 +176,7 @@ func (c *crit) ExploreMems() ([]*MemMap, error) {
return vmaIdMap[shmId]
}

var memMaps []*MemMap
memMaps := make([]*MemMap, 0)
for _, entry := range psTreeImg.Entries {
process := entry.Message.(*images.PstreeEntry)
pId := process.GetPid()
Expand Down Expand Up @@ -293,7 +293,7 @@ func (c *crit) ExploreRss() ([]*RssMap, error) {
return nil, err
}

var rssMaps []*RssMap
rssMaps := make([]*RssMap, 0)
for _, entry := range psTreeImg.Entries {
process := entry.Message.(*images.PstreeEntry)
pId := process.GetPid()
Expand Down
2 changes: 1 addition & 1 deletion test/crit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func getImgs() ([]string, error) {
// external tools (ifaddr, route, tmpfs). As these
// images cannot be processed by CRIT, they are
// excluded from the tests.
var skipImgs = []string{
skipImgs := []string{
"pages-",
"pages-shmem-",
"iptables-",
Expand Down

0 comments on commit a76d73f

Please sign in to comment.