@@ -816,7 +816,8 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
816816 BOOL ret ;
817817 word32 shellChannelId = 0 ;
818818#ifndef EXAMPLE_BUFFER_SZ
819- #define EXAMPLE_BUFFER_SZ 4096
819+ /* default to try and read max packet size */
820+ #define EXAMPLE_BUFFER_SZ 32768
820821#endif
821822 byte shellBuffer [EXAMPLE_BUFFER_SZ ];
822823 int cnt_r , cnt_w ;
@@ -1166,7 +1167,8 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
11661167 pid_t childPid ;
11671168
11681169#ifndef EXAMPLE_BUFFER_SZ
1169- #define EXAMPLE_BUFFER_SZ 4096
1170+ /* default to try and read max packet size */
1171+ #define EXAMPLE_BUFFER_SZ 32768
11701172#endif
11711173#ifndef MAX_IDLE_COUNT
11721174 #define MAX_IDLE_COUNT 2
@@ -1431,23 +1433,23 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
14311433 FD_SET (sshFd , & writeFds );
14321434 }
14331435
1434- /* select on stdout/stderr pipes with forced commands */
1435- if (forcedCmd ) {
1436- FD_SET (stdoutPipe [0 ], & readFds );
1437- if (stdoutPipe [0 ] > maxFd )
1438- maxFd = stdoutPipe [0 ];
1436+ if (wolfSSH_stream_peek (ssh , tmp , 1 ) <= 0 ) {
1437+ /* select on stdout/stderr pipes with forced commands */
1438+ if (forcedCmd ) {
1439+ FD_SET (stdoutPipe [0 ], & readFds );
1440+ if (stdoutPipe [0 ] > maxFd )
1441+ maxFd = stdoutPipe [0 ];
14391442
1440- FD_SET (stderrPipe [0 ], & readFds );
1441- if (stderrPipe [0 ] > maxFd )
1442- maxFd = stderrPipe [0 ];
1443- }
1444- else {
1445- FD_SET (childFd , & readFds );
1446- if (childFd > maxFd )
1447- maxFd = childFd ;
1448- }
1443+ FD_SET (stderrPipe [0 ], & readFds );
1444+ if (stderrPipe [0 ] > maxFd )
1445+ maxFd = stderrPipe [0 ];
1446+ }
1447+ else {
1448+ FD_SET (childFd , & readFds );
1449+ if (childFd > maxFd )
1450+ maxFd = childFd ;
1451+ }
14491452
1450- if (wolfSSH_stream_peek (ssh , tmp , 1 ) <= 0 ) {
14511453 rc = select ((int )maxFd + 1 , & readFds , & writeFds , NULL , NULL );
14521454 if (rc == -1 )
14531455 break ;
@@ -1503,6 +1505,21 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
15031505 break ;
15041506 }
15051507 }
1508+
1509+ /* did the channel just receive an EOF? */
1510+ if (cnt_r == 0 ) {
1511+ int eof ;
1512+ WOLFSSH_CHANNEL * current ;
1513+
1514+ current = wolfSSH_ChannelFind (ssh , lastChannel ,
1515+ WS_CHANNEL_ID_SELF );
1516+ eof = wolfSSH_ChannelGetEof (current );
1517+ if (eof ) {
1518+ /* SSH is done, kill off child process */
1519+ kill (childPid , SIGKILL );
1520+ break ;
1521+ }
1522+ }
15061523 }
15071524
15081525 /* if the window was previously full, try resending the data */
0 commit comments