detects running pid only of it doesnt contain grep
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Marvin Steadfast 2021-04-26 11:12:54 +02:00
parent b69ed6fa08
commit 8d389aa3ad
3 changed files with 11 additions and 2 deletions

View File

@ -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 {

View File

@ -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)

1
tools/pidof/testdata/psa_alpine_3.txt vendored Normal file
View File

@ -0,0 +1 @@
2566 root 0:00 grep .byteexec/wireguard-go w1nd50r