-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproc.go
59 lines (44 loc) · 836 Bytes
/
proc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package proc
import (
"context"
"fmt"
"net/url"
"github.com/go-waitfor/waitfor"
"github.com/mitchellh/go-ps"
)
const Scheme = "proc"
type Process struct {
name string
}
func Use() waitfor.ResourceConfig {
return waitfor.ResourceConfig{
Scheme: []string{Scheme},
Factory: New,
}
}
func New(u *url.URL) (waitfor.Resource, error) {
if u == nil {
return nil, fmt.Errorf("%q: %w", "url", waitfor.ErrInvalidArgument)
}
return &Process{name: u.Host}, nil
}
func (p *Process) Test(ctx context.Context) error {
if ctx.Err() != nil {
return ctx.Err()
}
list, err := ps.Processes()
if err != nil {
return err
}
var found bool
for _, proc := range list {
if proc.Executable() == p.name {
found = true
break
}
}
if found {
return nil
}
return fmt.Errorf("process not found: %s", p.name)
}