Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions channel/local_unixs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ package channel
import (
"context"
"fmt"
"github.com/chaosblade-io/chaosblade-spec-go/log"
"os"
"os/exec"
"strconv"
"strings"
"time"

"github.com/chaosblade-io/chaosblade-spec-go/log"

"github.com/chaosblade-io/chaosblade-spec-go/spec"
"github.com/chaosblade-io/chaosblade-spec-go/util"
"github.com/shirou/gopsutil/process"
Expand Down Expand Up @@ -69,7 +70,7 @@ func (l *LocalChannel) GetPidsByProcessCmdName(processName string, ctx context.C
for _, p := range processes {
name, err := p.Name()
if err != nil {
log.Debugf(ctx, "get process name error, pid: %s, err: %v", p.Pid, err)
log.Debugf(ctx, "get process name error, pid: %v, err: %v", p.Pid, err)
continue
}
if processName != name {
Expand Down Expand Up @@ -133,7 +134,7 @@ func (l *LocalChannel) GetPidsByProcessName(processName string, ctx context.Cont
}
cmdline, err := p.Cmdline()
if err != nil {
log.Debugf(ctx, "get command line error, pid: %s, err: %v", p.Pid, err)
log.Debugf(ctx, "get command line error, pid: %v, err: %v", p.Pid, err)
continue
}
if !strings.Contains(cmdline, processName) {
Expand Down Expand Up @@ -233,7 +234,7 @@ func (l *LocalChannel) GetPidUser(pid string) (string, error) {
}

func (l *LocalChannel) GetPidsByLocalPorts(ctx context.Context, localPorts []string) ([]string, error) {
if localPorts == nil || len(localPorts) == 0 {
if len(localPorts) == 0 {
return nil, fmt.Errorf("the local port parameter is empty")
}
var result = make([]string, 0)
Expand All @@ -243,7 +244,7 @@ func (l *LocalChannel) GetPidsByLocalPorts(ctx context.Context, localPorts []str
return nil, fmt.Errorf("failed to get pid by %s, %v", port, err)
}
log.Infof(ctx, "get pids by %s port returns %v", port, pids)
if pids != nil && len(pids) > 0 {
if len(pids) > 0 {
result = append(result, pids...)
}
}
Expand Down