blob: 387df90547406067ff9eb640e3a89e7833f16132 (
plain)
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
|
// +build !windows
package osutil
import (
"os/exec"
"os/user"
"strconv"
"syscall"
)
// IsolateProcess change gpid for the process to avoid bypassing signals to php processes.
func IsolateProcess(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true, Pgid: 0}
}
func ExecuteFromUser(cmd *exec.Cmd, u string) error {
usr, err := user.Lookup(u)
if err != nil {
return err
}
usrI32, err := strconv.Atoi(usr.Uid)
if err != nil {
return err
}
grI32, err := strconv.Atoi(usr.Gid)
if err != nil {
return err
}
cmd.SysProcAttr.Credential = &syscall.Credential{
Uid: uint32(usrI32),
Gid: uint32(grI32),
}
return nil
}
|