diff --git a/protocols/ssh/src/client.c b/protocols/ssh/src/client.c index bce1c6af..0bfbf088 100644 --- a/protocols/ssh/src/client.c +++ b/protocols/ssh/src/client.c @@ -108,13 +108,6 @@ int guac_client_init(guac_client* client, int argc, char** argv) { return 1; } - /* Redirect STDOUT to pipe */ - if (dup2(client_data->stdout_pipe_fd[1], STDOUT_FILENO) < 0) { - guac_error = GUAC_STATUS_SEE_ERRNO; - guac_error_message = "Unable redirect STDOUT"; - return 1; - } - /* Open STDIN pipe */ if (pipe(client_data->stdin_pipe_fd)) { guac_error = GUAC_STATUS_SEE_ERRNO; @@ -122,13 +115,6 @@ int guac_client_init(guac_client* client, int argc, char** argv) { return 1; } - /* Redirect STDIN to pipe */ - if (dup2(client_data->stdin_pipe_fd[0], STDIN_FILENO) < 0) { - guac_error = GUAC_STATUS_SEE_ERRNO; - guac_error_message = "Unable redirect STDIN"; - return 1; - } - /* Set basic handlers */ client->handle_messages = ssh_guac_client_handle_messages; client->clipboard_handler = ssh_guac_client_clipboard_handler; diff --git a/protocols/ssh/src/guac_handlers.c b/protocols/ssh/src/guac_handlers.c index be3b8e7d..5a16edb0 100644 --- a/protocols/ssh/src/guac_handlers.c +++ b/protocols/ssh/src/guac_handlers.c @@ -354,9 +354,14 @@ int ssh_guac_client_free_handler(guac_client* client) { ssh_guac_client_data* guac_client_data = (ssh_guac_client_data*) client->data; - /* Close SSH client */ - close(STDOUT_FILENO); - close(STDIN_FILENO); + /* Close terminal output pipe */ + close(guac_client_data->stdout_pipe_fd[1]); + close(guac_client_data->stdout_pipe_fd[0]); + + /* Close user input pipe */ + close(guac_client_data->stdin_pipe_fd[1]); + close(guac_client_data->stdin_pipe_fd[0]); + pthread_join(guac_client_data->client_thread, NULL); /* Free terminal */ diff --git a/protocols/ssh/src/ssh_client.c b/protocols/ssh/src/ssh_client.c index f5f43feb..eb54a34a 100644 --- a/protocols/ssh/src/ssh_client.c +++ b/protocols/ssh/src/ssh_client.c @@ -262,6 +262,9 @@ void* ssh_client_thread(void* data) { return NULL; } + /* Wait for input thread to die */ + pthread_join(input_thread, NULL); + guac_client_log_info(client, "SSH connection ended."); return NULL;