diff --git a/src/cmd/run.go b/src/cmd/run.go index 5ad7c30..83e6480 100644 --- a/src/cmd/run.go +++ b/src/cmd/run.go @@ -300,7 +300,12 @@ func runCommandWithFallbacks(container string, command []string, emitEscapeSeque workDir := workingDirectory for { - execArgs := constructExecArgs(container, command, detachKeysSupported, envOptions, workDir) + execArgs := constructExecArgs(container, + command, + detachKeysSupported, + envOptions, + fallbackToBash, + workDir) if emitEscapeSequence { fmt.Printf("\033]777;container;push;%s;toolbox;%s\033\\", container, currentUser.Uid) @@ -421,8 +426,14 @@ func callFlatpakSessionHelper(container string) error { return nil } -func constructCapShArgs(command []string) []string { - capShArgs := []string{"capsh", "--caps=", "--", "-c", "exec \"$@\"", "bash"} +func constructCapShArgs(command []string, useLoginShell bool) []string { + capShArgs := []string{"capsh", "--caps=", "--"} + + if useLoginShell { + capShArgs = append(capShArgs, []string{"--login"}...) + } + + capShArgs = append(capShArgs, []string{"-c", "exec \"$@\"", "bash"}...) capShArgs = append(capShArgs, command...) return capShArgs @@ -432,6 +443,7 @@ func constructExecArgs(container string, command []string, detachKeysSupported bool, envOptions []string, + fallbackToBash bool, workDir string) []string { var detachKeys []string @@ -470,7 +482,7 @@ func constructExecArgs(container string, container, }...) - capShArgs := constructCapShArgs(command) + capShArgs := constructCapShArgs(command, !fallbackToBash) execArgs = append(execArgs, capShArgs...) return execArgs diff --git a/test/system/104-run.bats b/test/system/104-run.bats index 41947af..b067bad 100644 --- a/test/system/104-run.bats +++ b/test/system/104-run.bats @@ -13,6 +13,21 @@ teardown() { cleanup_containers } +@test "run: Ensure that a login shell is used to invoke the command" { + create_default_container + + cp "$HOME"/.bash_profile "$HOME"/.bash_profile.orig + echo "echo \"~/.bash_profile read\"" >>"$HOME"/.bash_profile + + run $TOOLBOX run true + + mv "$HOME"/.bash_profile.orig "$HOME"/.bash_profile + + assert_success + assert_line --index 0 "~/.bash_profile read" + assert [ ${#lines[@]} -eq 1 ] +} + @test "run: Try to run a command in the default container with no containers created" { local default_container_name="$(get_system_id)-toolbox-$(get_system_version)"