@@ -892,21 +892,11 @@ impl SshHandler {
892892 let no_login_shell = state. no_login_shell ;
893893 let pty = state. pty_request . take ( ) ;
894894 let pty_requested = pty. is_some ( ) ;
895- let ( program, args) = command. map_or_else (
896- || {
897- if pty_requested {
898- ( "/bin/bash" . to_string ( ) , vec ! [ "-i" . to_string( ) ] )
899- } else {
900- ( "/bin/bash" . to_string ( ) , vec ! [ ] )
901- }
902- } ,
903- |command| {
904- (
905- "/bin/bash" . to_string ( ) ,
906- vec ! [ login_shell_flag( no_login_shell) . to_string( ) , command] ,
907- )
908- } ,
909- ) ;
895+ // The supervisor shares the workload filesystem, so select a shell
896+ // that actually exists in the image. Alpine and other minimal images
897+ // provide `/bin/sh` but not `/bin/bash`.
898+ let shell = openshell_core:: shell:: detect_login_shell ( ) ;
899+ let ( program, args) = shell_command ( shell, command, pty_requested, no_login_shell) ;
910900 let env = pty
911901 . as_ref ( )
912902 . map ( |request| vec ! [ ( "TERM" . to_string( ) , request. term. clone( ) ) ] )
@@ -1084,6 +1074,25 @@ const fn login_shell_flag(no_login_shell: bool) -> &'static str {
10841074 if no_login_shell { "-c" } else { "-lc" }
10851075}
10861076
1077+ fn shell_command (
1078+ shell : String ,
1079+ command : Option < String > ,
1080+ pty_requested : bool ,
1081+ no_login_shell : bool ,
1082+ ) -> ( String , Vec < String > ) {
1083+ let args = command. map_or_else (
1084+ || {
1085+ if pty_requested {
1086+ vec ! [ "-i" . to_string( ) ]
1087+ } else {
1088+ Vec :: new ( )
1089+ }
1090+ } ,
1091+ |command| vec ! [ login_shell_flag( no_login_shell) . to_string( ) , command] ,
1092+ ) ;
1093+ ( shell, args)
1094+ }
1095+
10871096#[ allow( dead_code) ]
10881097#[ derive( Clone ) ]
10891098struct PtyRequest {
@@ -1400,6 +1409,27 @@ mod tests {
14001409 main_session. end_terminal_attachment ( ) ;
14011410 }
14021411
1412+ #[ test]
1413+ fn shell_command_uses_the_resolved_image_shell ( ) {
1414+ let ( program, args) = shell_command (
1415+ "/bin/sh" . to_string ( ) ,
1416+ Some ( "printf ready" . to_string ( ) ) ,
1417+ false ,
1418+ false ,
1419+ ) ;
1420+
1421+ assert_eq ! ( program, "/bin/sh" ) ;
1422+ assert_eq ! ( args, [ "-lc" , "printf ready" ] ) ;
1423+ }
1424+
1425+ #[ test]
1426+ fn interactive_shell_uses_the_resolved_image_shell ( ) {
1427+ let ( program, args) = shell_command ( "/bin/sh" . to_string ( ) , None , true , false ) ;
1428+
1429+ assert_eq ! ( program, "/bin/sh" ) ;
1430+ assert_eq ! ( args, [ "-i" ] ) ;
1431+ }
1432+
14031433 #[ cfg( unix) ]
14041434 fn file_mode ( path : & Path ) -> u32 {
14051435 use std:: os:: unix:: fs:: PermissionsExt ;
0 commit comments