mirror of https://github.com/wolfSSL/wolfssh.git
fix for FD_SET call on pipes and handling of channel EOF
parent
697f54a7e5
commit
ab3622e672
|
@ -816,7 +816,8 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
word32 shellChannelId = 0;
|
word32 shellChannelId = 0;
|
||||||
#ifndef EXAMPLE_BUFFER_SZ
|
#ifndef EXAMPLE_BUFFER_SZ
|
||||||
#define EXAMPLE_BUFFER_SZ 4096
|
/* default to try and read max packet size */
|
||||||
|
#define EXAMPLE_BUFFER_SZ 32768
|
||||||
#endif
|
#endif
|
||||||
byte shellBuffer[EXAMPLE_BUFFER_SZ];
|
byte shellBuffer[EXAMPLE_BUFFER_SZ];
|
||||||
int cnt_r, cnt_w;
|
int cnt_r, cnt_w;
|
||||||
|
@ -1166,7 +1167,8 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
|
||||||
pid_t childPid;
|
pid_t childPid;
|
||||||
|
|
||||||
#ifndef EXAMPLE_BUFFER_SZ
|
#ifndef EXAMPLE_BUFFER_SZ
|
||||||
#define EXAMPLE_BUFFER_SZ 4096
|
/* default to try and read max packet size */
|
||||||
|
#define EXAMPLE_BUFFER_SZ 32768
|
||||||
#endif
|
#endif
|
||||||
#ifndef MAX_IDLE_COUNT
|
#ifndef MAX_IDLE_COUNT
|
||||||
#define MAX_IDLE_COUNT 2
|
#define MAX_IDLE_COUNT 2
|
||||||
|
@ -1431,23 +1433,23 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
|
||||||
FD_SET(sshFd, &writeFds);
|
FD_SET(sshFd, &writeFds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* select on stdout/stderr pipes with forced commands */
|
|
||||||
if (forcedCmd) {
|
|
||||||
FD_SET(stdoutPipe[0], &readFds);
|
|
||||||
if (stdoutPipe[0] > maxFd)
|
|
||||||
maxFd = stdoutPipe[0];
|
|
||||||
|
|
||||||
FD_SET(stderrPipe[0], &readFds);
|
|
||||||
if (stderrPipe[0] > maxFd)
|
|
||||||
maxFd = stderrPipe[0];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
FD_SET(childFd, &readFds);
|
|
||||||
if (childFd > maxFd)
|
|
||||||
maxFd = childFd;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wolfSSH_stream_peek(ssh, tmp, 1) <= 0) {
|
if (wolfSSH_stream_peek(ssh, tmp, 1) <= 0) {
|
||||||
|
/* select on stdout/stderr pipes with forced commands */
|
||||||
|
if (forcedCmd) {
|
||||||
|
FD_SET(stdoutPipe[0], &readFds);
|
||||||
|
if (stdoutPipe[0] > maxFd)
|
||||||
|
maxFd = stdoutPipe[0];
|
||||||
|
|
||||||
|
FD_SET(stderrPipe[0], &readFds);
|
||||||
|
if (stderrPipe[0] > maxFd)
|
||||||
|
maxFd = stderrPipe[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
FD_SET(childFd, &readFds);
|
||||||
|
if (childFd > maxFd)
|
||||||
|
maxFd = childFd;
|
||||||
|
}
|
||||||
|
|
||||||
rc = select((int)maxFd + 1, &readFds, &writeFds, NULL, NULL);
|
rc = select((int)maxFd + 1, &readFds, &writeFds, NULL, NULL);
|
||||||
if (rc == -1)
|
if (rc == -1)
|
||||||
break;
|
break;
|
||||||
|
@ -1503,6 +1505,21 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* did the channel just receive an EOF? */
|
||||||
|
if (cnt_r == 0) {
|
||||||
|
int eof;
|
||||||
|
WOLFSSH_CHANNEL* current;
|
||||||
|
|
||||||
|
current = wolfSSH_ChannelFind(ssh, lastChannel,
|
||||||
|
WS_CHANNEL_ID_SELF);
|
||||||
|
eof = wolfSSH_ChannelGetEof(current);
|
||||||
|
if (eof) {
|
||||||
|
/* SSH is done, kill off child process */
|
||||||
|
kill(childPid, SIGKILL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if the window was previously full, try resending the data */
|
/* if the window was previously full, try resending the data */
|
||||||
|
|
Loading…
Reference in New Issue