From 0810eee7bb2118707a222d47d3e203c922b87baf Mon Sep 17 00:00:00 2001 From: Patrick Pacher Date: Mon, 10 Oct 2022 18:08:09 +0200 Subject: [PATCH] Fix linter errors --- package-lock.json | 6 ------ process/process.go | 3 ++- process/tags/interpreter_unix.go | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 8 deletions(-) delete mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 4bec6c1f..00000000 --- a/package-lock.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "workspace", - "lockfileVersion": 2, - "requires": true, - "packages": {} -} diff --git a/process/process.go b/process/process.go index 47764f29..a3ff1333 100644 --- a/process/process.go +++ b/process/process.go @@ -68,6 +68,7 @@ type Process struct { ExecHashes map[string]string } +// GetTag returns the process tag with the given ID. func (p *Process) GetTag(tagID string) (profile.Tag, bool) { for _, t := range p.Tags { if t.Key == tagID { @@ -239,7 +240,7 @@ func loadProcess(ctx context.Context, pid int) (*Process, error) { if runtime.GOOS != "windows" { process.Cwd, err = pInfo.Cwd() if err != nil { - log.Warningf("process: failed to get Cwd: %w", err) + log.Warningf("process: failed to get Cwd: %s", err) } } diff --git a/process/tags/interpreter_unix.go b/process/tags/interpreter_unix.go index 6a01e405..0afc0357 100644 --- a/process/tags/interpreter_unix.go +++ b/process/tags/interpreter_unix.go @@ -86,7 +86,9 @@ func fileMustBeUTF8(path string) bool { return false } - defer f.Close() + defer func() { + _ = f.Close() + }() // read the first chunk of bytes buf := new(bytes.Buffer) @@ -108,12 +110,15 @@ func fileMustBeUTF8(path string) bool { return true } +// InterpHandler supports adding process tags based on well-known interpreter binaries. type InterpHandler struct{} +// Name returns "Interpreter" func (h *InterpHandler) Name() string { return "Interpreter" } +// TagDescriptions returns a set of tag descriptions that InterpHandler provides. func (h *InterpHandler) TagDescriptions() []process.TagDescription { l := make([]process.TagDescription, len(knownInterperters)) for idx, it := range knownInterperters { @@ -123,6 +128,8 @@ func (h *InterpHandler) TagDescriptions() []process.TagDescription { return l } +// CreateProfile creates a new profile for any process that has a tag created +// by InterpHandler. func (h *InterpHandler) CreateProfile(p *process.Process) *profile.Profile { for _, it := range knownInterperters { if tag, ok := p.GetTag(it.ID); ok { @@ -159,6 +166,8 @@ func (h *InterpHandler) CreateProfile(p *process.Process) *profile.Profile { return nil } +// AddTags inspects the process p and adds any interpreter tags that InterpHandler +// detects. func (h *InterpHandler) AddTags(p *process.Process) { // check if we have a matching interpreter var matched interpType @@ -208,6 +217,8 @@ func (h *InterpHandler) AddTags(p *process.Process) { Value: filePath, }) + p.MatchingPath = filePath + return } @@ -217,4 +228,6 @@ func (h *InterpHandler) AddTags(p *process.Process) { Key: matched.ID, Value: args[0], }) + + p.MatchingPath = args[0] }