Skip to content

Commit

Permalink
more aboutt #1
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Jul 30, 2020
1 parent 8ce0ac3 commit 93c7300
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ go 1.13
replace github.com/AlecAivazis/survey/v2 => github.com/kataras/survey/v2 v2.0.6

require (
github.com/AlecAivazis/survey/v2 v2.0.7
github.com/AlecAivazis/survey/v2 v2.0.8
github.com/cheggaaa/pb/v3 v3.0.4
github.com/creack/pty v1.1.9
github.com/creack/pty v1.1.11
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
github.com/denormal/go-gitignore v0.0.0-20180930084346-ae8ad1d07817
github.com/fsnotify/fsnotify v1.4.7
github.com/kataras/golog v0.0.10
github.com/kataras/neffos v0.0.12
github.com/spf13/cobra v0.0.5
golang.org/x/sync v0.0.0-20190423024810-112230192c58
github.com/fsnotify/fsnotify v1.4.9
github.com/kataras/golog v0.0.18
github.com/kataras/neffos v0.0.16
github.com/spf13/cobra v1.0.0
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
gopkg.in/src-d/go-git.v4 v4.13.1
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
)
40 changes: 23 additions & 17 deletions utils/cmd_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"io"
"os/exec"
"path"
"strings"
"syscall"

Expand Down Expand Up @@ -35,27 +36,32 @@ func KillCommand(cmd *exec.Cmd) error {
func FormatExecutable(bin string) string { return bin }

func StartExecutable(dir, bin string, stdout, stderr io.Writer) (*exec.Cmd, error) {
cmd := Command("/bin/sh", "-c", bin)
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} // set parent group id in order to be kill-able.
cmd.Dir = dir
cmd.Stdout = stdout
cmd.Stderr = stderr
_, err := pty.Start(cmd) // it runs cmd.Start().
if err != nil {
// fork/exec /bin/sh: operation not permitted
if !strings.Contains(err.Error(), "operation not permitted") {
return nil, err
}

cmd = Command(bin)
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
if IsInsideDocker() {
// If run through docker, this part is required,
// otherwise we should NOT try this because it always gives error:
cmd := Command("/bin/sh", "-c", bin)
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} // set parent group id in order to be kill-able.
cmd.Dir = dir
cmd.Stdout = stdout
cmd.Stderr = stderr
if err = cmd.Start(); err != nil {
return nil, err
_, err := pty.Start(cmd)
// fork/exec /bin/sh: operation not permitted, even without setpgid.

if err != nil {
if !strings.Contains(err.Error(), "operation not permitted") {
return nil, err
}
}
}

return cmd, err
cmd := Command(path.Join(dir, bin))
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
cmd.Dir = dir
cmd.Stdout = stdout
cmd.Stderr = stderr
if err := cmd.Start(); err != nil {
return nil, err
}

return cmd, nil
}
2 changes: 1 addition & 1 deletion utils/cmd_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func KillCommand(cmd *exec.Cmd) error {
}

func FormatExecutable(bin string) string {
if ext := ".exe"; !strings.HasPrefix(bin, ext) {
if ext := ".exe"; !strings.HasSuffix(bin, ext) {
bin += ext
}

Expand Down

0 comments on commit 93c7300

Please sign in to comment.