mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-05-14 10:58:51 +08:00
procutils: exec.Cmd setsid only for linux
This commit is contained in:
15
pkg/util/procutils/cmdsetsid_others.go
Normal file
15
pkg/util/procutils/cmdsetsid_others.go
Normal file
@@ -0,0 +1,15 @@
|
||||
// +build !windows
|
||||
|
||||
package procutils
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func cmdSetSid(cmd *exec.Cmd) {
|
||||
if cmd.SysProcAttr == nil {
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||
}
|
||||
cmd.SysProcAttr.Setsid = true
|
||||
}
|
||||
7
pkg/util/procutils/cmdsetsid_windows.go
Normal file
7
pkg/util/procutils/cmdsetsid_windows.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package procutils
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func cmdSetSid(cmd *exec.Cmd) {}
|
||||
@@ -67,17 +67,13 @@ type defaultExecutor struct{}
|
||||
|
||||
func (e *defaultExecutor) Command(name string, args ...string) Cmd {
|
||||
cmd := exec.Command(name, args...)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Setsid: true,
|
||||
}
|
||||
cmdSetSid(cmd)
|
||||
return &defaultCmd{cmd}
|
||||
}
|
||||
|
||||
func (e *defaultExecutor) CommandContext(ctx context.Context, name string, args ...string) Cmd {
|
||||
cmd := exec.CommandContext(ctx, name, args...)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Setsid: true,
|
||||
}
|
||||
cmdSetSid(cmd)
|
||||
return &defaultCmd{cmd}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user