mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
remove dependency on SysProcAttr
This commit is contained in:
parent
dab48497c1
commit
c139a33954
@ -9,6 +9,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"reflect"
|
||||
"syscall"
|
||||
|
||||
"github.com/creack/pty"
|
||||
@ -34,6 +35,18 @@ func (sp *ShellProc) Close() {
|
||||
}()
|
||||
}
|
||||
|
||||
func setBoolConditionally(rval reflect.Value, field string, value bool) {
|
||||
if rval.Elem().FieldByName(field).IsValid() {
|
||||
rval.Elem().FieldByName(field).SetBool(value)
|
||||
}
|
||||
}
|
||||
|
||||
func setSysProcAttrs(cmd *exec.Cmd) {
|
||||
rval := reflect.ValueOf(cmd.SysProcAttr)
|
||||
setBoolConditionally(rval, "Setsid", true)
|
||||
setBoolConditionally(rval, "Setctty", true)
|
||||
}
|
||||
|
||||
func StartShellProc(termSize TermSize) (*ShellProc, error) {
|
||||
shellPath := shellutil.DetectLocalShellPath()
|
||||
ecmd := exec.Command(shellPath, "-i", "-l")
|
||||
@ -60,8 +73,7 @@ func StartShellProc(termSize TermSize) (*ShellProc, error) {
|
||||
ecmd.Stdout = cmdTty
|
||||
ecmd.Stderr = cmdTty
|
||||
ecmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||
ecmd.SysProcAttr.Setsid = true
|
||||
ecmd.SysProcAttr.Setctty = true
|
||||
setSysProcAttrs(ecmd)
|
||||
err = ecmd.Start()
|
||||
cmdTty.Close()
|
||||
if err != nil {
|
||||
@ -90,8 +102,7 @@ func RunSimpleCmdInPty(ecmd *exec.Cmd, termSize TermSize) ([]byte, error) {
|
||||
ecmd.Stdout = cmdTty
|
||||
ecmd.Stderr = cmdTty
|
||||
ecmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||
ecmd.SysProcAttr.Setsid = true
|
||||
ecmd.SysProcAttr.Setctty = true
|
||||
setSysProcAttrs(ecmd)
|
||||
err = ecmd.Start()
|
||||
cmdTty.Close()
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user