[process][darwin] Fix Parent() when lsof returns warnings

Same as #867, the error being:
error strconv.Atoi: parsing "      Output information may be incomplete.": invalid syntax
pull/989/head
Lomanic 5 years ago
parent 148a662b06
commit 5641beec4c

@ -146,20 +146,18 @@ func (p *Process) createTimeWithContext(ctx context.Context) (int64, error) {
} }
func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) { func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
rr, err := common.CallLsofWithContext(ctx, invoke, p.Pid, "-FR") out, err := common.CallLsofWithContext(ctx, invoke, p.Pid, "-FR")
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, r := range rr { for _, line := range out {
if strings.HasPrefix(r, "p") { // skip if process if len(line) >= 1 && line[0] == 'R' {
continue v, err := strconv.Atoi(line[1:])
} if err != nil {
l := string(r) return nil, err
v, err := strconv.Atoi(strings.Replace(l, "R", "", 1)) }
if err != nil { return NewProcessWithContext(ctx, int32(v))
return nil, err
} }
return NewProcessWithContext(ctx, int32(v))
} }
return nil, fmt.Errorf("could not find parent line") return nil, fmt.Errorf("could not find parent line")
} }

@ -146,20 +146,18 @@ func (p *Process) createTimeWithContext(ctx context.Context) (int64, error) {
} }
func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) { func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
rr, err := common.CallLsofWithContext(ctx, invoke, p.Pid, "-FR") out, err := common.CallLsofWithContext(ctx, invoke, p.Pid, "-FR")
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, r := range rr { for _, line := range out {
if strings.HasPrefix(r, "p") { // skip if process if len(line) >= 1 && line[0] == 'R' {
continue v, err := strconv.Atoi(line[1:])
} if err != nil {
l := string(r) return nil, err
v, err := strconv.Atoi(strings.Replace(l, "R", "", 1)) }
if err != nil { return NewProcessWithContext(ctx, int32(v))
return nil, err
} }
return NewProcessWithContext(ctx, int32(v))
} }
return nil, fmt.Errorf("could not find parent line") return nil, fmt.Errorf("could not find parent line")
} }

Loading…
Cancel
Save