Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions cdba.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ static int tty_callback(int *ssh_fds)
ssize_t n;

n = read(STDIN_FILENO, buf, sizeof(buf));
if (n < 0)
if (n <= 0)
return n;

for (k = 0; k < n; k++) {
Expand Down Expand Up @@ -553,7 +553,7 @@ static int tty_callback(int *ssh_fds)
}
}

return 0;
return n;
}

/**
Expand Down Expand Up @@ -909,6 +909,7 @@ int main(int argc, char **argv)
struct timeval timeout_total_tv;
struct timeval *timeout = NULL;
struct termios *orig_tios;
bool watch_stdin = true;
const char *server_binary = "cdba-server";
const char *status_pipe = NULL;
bool bump_inactivity_timer;
Expand Down Expand Up @@ -1054,7 +1055,7 @@ int main(int argc, char **argv)
FD_SET(ssh_fds[2], &rfds);
nfds = MAX(ssh_fds[1], ssh_fds[2]);

if (orig_tios) {
if (watch_stdin) {
FD_SET(STDIN_FILENO, &rfds);

nfds = MAX(nfds, STDIN_FILENO);
Expand Down Expand Up @@ -1092,8 +1093,10 @@ int main(int argc, char **argv)

bump_inactivity_timer = false;

if (FD_ISSET(STDIN_FILENO, &rfds))
tty_callback(ssh_fds);
if (watch_stdin && FD_ISSET(STDIN_FILENO, &rfds)) {
if (tty_callback(ssh_fds) <= 0)
watch_stdin = false;
}

if (FD_ISSET(ssh_fds[2], &rfds)) {
n = read(ssh_fds[2], buf, sizeof(buf));
Expand Down
Loading