remove dependency on SysProcAttr

This commit is contained in:
sawka 2024-06-12 11:33:45 -07:00
parent dab48497c1
commit c139a33954

View File

@ -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 {