detects running pid only of it doesnt contain grep
This commit is contained in:
parent
b69ed6fa08
commit
8d389aa3ad
@ -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 {
|
||||
|
@ -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
1
tools/pidof/testdata/psa_alpine_3.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
2566 root 0:00 grep .byteexec/wireguard-go w1nd50r
|
Loading…
Reference in New Issue
Block a user