[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 4 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) {
rr, err := common.CallLsofWithContext(ctx, invoke, p.Pid, "-FR")
out, err := common.CallLsofWithContext(ctx, invoke, p.Pid, "-FR")
if err != nil {
return nil, err
}
for _, r := range rr {
if strings.HasPrefix(r, "p") { // skip if process
continue
}
l := string(r)
v, err := strconv.Atoi(strings.Replace(l, "R", "", 1))
if err != nil {
return nil, err
for _, line := range out {
if len(line) >= 1 && line[0] == 'R' {
v, err := strconv.Atoi(line[1:])
if err != nil {
return nil, err
}
return NewProcessWithContext(ctx, int32(v))
}
return NewProcessWithContext(ctx, int32(v))
}
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) {
rr, err := common.CallLsofWithContext(ctx, invoke, p.Pid, "-FR")
out, err := common.CallLsofWithContext(ctx, invoke, p.Pid, "-FR")
if err != nil {
return nil, err
}
for _, r := range rr {
if strings.HasPrefix(r, "p") { // skip if process
continue
}
l := string(r)
v, err := strconv.Atoi(strings.Replace(l, "R", "", 1))
if err != nil {
return nil, err
for _, line := range out {
if len(line) >= 1 && line[0] == 'R' {
v, err := strconv.Atoi(line[1:])
if err != nil {
return nil, err
}
return NewProcessWithContext(ctx, int32(v))
}
return NewProcessWithContext(ctx, int32(v))
}
return nil, fmt.Errorf("could not find parent line")
}

Loading…
Cancel
Save