Skip to content

Commit

Permalink
Merge pull request #1166 from 99designs/always-try-execve
Browse files Browse the repository at this point in the history
Support execve syscall on all OSs that can
  • Loading branch information
mtibben authored Feb 27, 2023
2 parents ea3c3d6 + 7a00a0c commit b5e394d
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions cli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func ConfigureExecCommand(app *kingpin.Application, a *AwsVault) {
input.Config.NonChainedGetSessionTokenDuration = input.SessionDuration
input.Config.AssumeRoleDuration = input.SessionDuration
input.Config.SSOUseStdout = input.UseStdout
input.ShowHelpMessages = input.Command == "" && isATerminal() && os.Getenv("AWS_VAULT_DISABLE_HELP_MESSAGE") != "1"
input.ShowHelpMessages = !a.Debug && input.Command == "" && isATerminal() && os.Getenv("AWS_VAULT_DISABLE_HELP_MESSAGE") != "1"

f, err := a.AwsConfigFile()
if err != nil {
Expand Down Expand Up @@ -200,12 +200,14 @@ func ExecCommand(input ExecCommandInput, f *vault.ConfigFile, keyring keyring.Ke
}
printHelpMessage(subshellHelp, input.ShowHelpMessages)

if osSupportsExecSyscall() {
return doExecSyscall(input.Command, input.Args, cmdEnv)
err = doExecSyscall(input.Command, input.Args, cmdEnv) // will not return if exec syscall succeeds
if err != nil {
log.Println("Error doing execve syscall:", err.Error())
log.Println("Falling back to running a subprocess")
}
}

return runChildProcess(input.Command, input.Args, cmdEnv)
return runSubProcess(input.Command, input.Args, cmdEnv) // will only return once subprocess ends
}

func printHelpMessage(helpMsg string, showHelpMessages bool) {
Expand Down Expand Up @@ -319,8 +321,8 @@ func getDefaultShell() string {
return command
}

func runChildProcess(command string, args []string, env []string) error {
log.Printf("Starting subprocess: %s %s", command, strings.Join(args, " "))
func runSubProcess(command string, args []string, env []string) error {
log.Printf("Starting a subprocess: %s %s", command, strings.Join(args, " "))

cmd := osexec.Command(command, args...)
cmd.Stdin = os.Stdin
Expand Down Expand Up @@ -353,10 +355,6 @@ func runChildProcess(command string, args []string, env []string) error {
return nil
}

func osSupportsExecSyscall() bool {
return runtime.GOOS == "linux" || runtime.GOOS == "darwin" || runtime.GOOS == "freebsd" || runtime.GOOS == "openbsd"
}

func doExecSyscall(command string, args []string, env []string) error {
log.Printf("Exec command %s %s", command, strings.Join(args, " "))

Expand Down

0 comments on commit b5e394d

Please sign in to comment.