Skip to content

Commit 3485fbf

Browse files
committed
fix tests
1 parent 0c5920c commit 3485fbf

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

pkg/nginxprocess/process.go

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,34 +76,38 @@ func convert(ctx context.Context, p *process.Process, o options) (*Process, erro
7676

7777
cmdLine, _ := p.CmdlineWithContext(ctx) // slow: shells out to ps
7878
// ignore nginx processes in the middle of an upgrade
79-
if !strings.HasPrefix(cmdLine, "nginx:") || !strings.HasPrefix(cmdLine, "{nginx-debug} nginx:") ||
80-
strings.Contains(cmdLine, "upgrade") {
79+
80+
if strings.Contains(cmdLine, "upgrade") {
8181
return nil, errNotAnNginxProcess
8282
}
8383

84-
var status string
85-
if o.loadStatus {
86-
flags, _ := p.StatusWithContext(ctx) // slow: shells out to ps
87-
status = strings.Join(flags, " ")
88-
}
84+
if strings.HasPrefix(cmdLine, "nginx:") || strings.HasPrefix(cmdLine, "{nginx-debug} nginx:") {
8985

90-
// unconditionally run fast lookups
91-
var created time.Time
92-
if millisSinceEpoch, err := p.CreateTimeWithContext(ctx); err == nil {
93-
created = time.UnixMilli(millisSinceEpoch)
86+
var status string
87+
if o.loadStatus {
88+
flags, _ := p.StatusWithContext(ctx) // slow: shells out to ps
89+
status = strings.Join(flags, " ")
90+
}
91+
92+
// unconditionally run fast lookups
93+
var created time.Time
94+
if millisSinceEpoch, err := p.CreateTimeWithContext(ctx); err == nil {
95+
created = time.UnixMilli(millisSinceEpoch)
96+
}
97+
ppid, _ := p.PpidWithContext(ctx)
98+
exe, _ := p.ExeWithContext(ctx)
99+
100+
return &Process{
101+
PID: p.Pid,
102+
PPID: ppid,
103+
Name: name,
104+
Cmd: cmdLine,
105+
Created: created,
106+
Status: status,
107+
Exe: exe,
108+
}, ctx.Err()
94109
}
95-
ppid, _ := p.PpidWithContext(ctx)
96-
exe, _ := p.ExeWithContext(ctx)
97-
98-
return &Process{
99-
PID: p.Pid,
100-
PPID: ppid,
101-
Name: name,
102-
Cmd: cmdLine,
103-
Created: created,
104-
Status: status,
105-
Exe: exe,
106-
}, ctx.Err()
110+
return nil, errNotAnNginxProcess
107111
}
108112

109113
// List returns a slice of all NGINX processes. Returns a zero-length slice if no NGINX processes are found.

0 commit comments

Comments
 (0)