diff --git a/tools/pidof/pidof.go b/tools/pidof/pidof.go index 2700307..782629b 100644 --- a/tools/pidof/pidof.go +++ b/tools/pidof/pidof.go @@ -40,7 +40,7 @@ func Pidof(name string, cdr Commander) (int, error) { } for _, l := range strings.Split(string(p), "\n") { - if strings.Contains(l, name) { + if strings.Contains(l, name) && !strings.Contains(l, "grep") { // nolint:gocritic rePID, err := regexp.Compile(`(\d+)\s.+`) if err != nil { diff --git a/tools/pidof/pidof_test.go b/tools/pidof/pidof_test.go index 1e5a54a..cb44712 100644 --- a/tools/pidof/pidof_test.go +++ b/tools/pidof/pidof_test.go @@ -1,9 +1,10 @@ -// nolint:gochecknoglobals,paralleltest,goerr113 +// nolint:gochecknoglobals,paralleltest,goerr113,funlen package pidof_test import ( "embed" "fmt" + "log" "testing" "github.com/stretchr/testify/assert" @@ -52,9 +53,16 @@ func TestPidof(t *testing.T) { 2501, nil, }, + { + "/root/.byteexec/wireguard-go w1nd50r", + "psa_alpine_3.txt", + 0, + pidof.ErrPIDNotFound, + }, } for _, table := range tables { + log.Printf("testfile: %s", table.data) out, err := testdata.ReadFile("testdata/" + table.data) assert.NoError(err) diff --git a/tools/pidof/testdata/psa_alpine_3.txt b/tools/pidof/testdata/psa_alpine_3.txt new file mode 100644 index 0000000..ee5f87b --- /dev/null +++ b/tools/pidof/testdata/psa_alpine_3.txt @@ -0,0 +1 @@ + 2566 root 0:00 grep .byteexec/wireguard-go w1nd50r