forked from gwoo/goforever
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_other.go
63 lines (55 loc) · 1.36 KB
/
process_other.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
60
61
62
63
//go:build !windows
package goforever
import (
"errors"
"fmt"
"os"
"os/user"
"strconv"
"syscall"
)
func (p *Process) StartProcess(name string, argv []string, attr *os.ProcAttr) (Processer, error) {
if len(p.User) > 0 {
userInfo, err := user.Lookup(p.User)
if err != nil {
return nil, errors.New("failed to get user: " + err.Error())
}
uid, err := strconv.ParseUint(userInfo.Uid, 10, 32)
if err != nil {
return nil, fmt.Errorf("failed to ParseUint(userInfo.Uid=%q): %w", userInfo.Uid, err)
}
gid, err := strconv.ParseUint(userInfo.Gid, 10, 32)
if err != nil {
return nil, fmt.Errorf("failed to ParseUint(userInfo.Gid=%q): %w", userInfo.Gid, err)
}
attr.Sys.Credential = &syscall.Credential{
Uid: uint32(uid),
Gid: uint32(gid),
NoSetGroups: true,
}
}
process, err := os.StartProcess(name, argv, attr)
if err != nil {
return nil, err
}
return &osProcess{Process: process}, nil
}
func (p *Process) kill() error {
pid := p.Pid()
if pid == 0 {
return nil
}
return syscall.Kill(-pid, syscall.SIGKILL)
}
type osProcess struct {
*os.Process
}
func (p *osProcess) Pid() int {
return p.Process.Pid
}
func buildOption(options map[string]interface{}) map[string]interface{} {
return options
}
func SetOption(options map[string]interface{}, name string, value interface{}) map[string]interface{} {
return options
}