Properly close pipe file descriptors. Wait for input thread to close in SSH thread.

This commit is contained in:
Michael Jumper 2013-05-20 10:52:47 -07:00
parent 639389ced8
commit c220a4875c
3 changed files with 11 additions and 17 deletions

View File

@ -108,13 +108,6 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
return 1; 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 */ /* Open STDIN pipe */
if (pipe(client_data->stdin_pipe_fd)) { if (pipe(client_data->stdin_pipe_fd)) {
guac_error = GUAC_STATUS_SEE_ERRNO; guac_error = GUAC_STATUS_SEE_ERRNO;
@ -122,13 +115,6 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
return 1; 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 */ /* Set basic handlers */
client->handle_messages = ssh_guac_client_handle_messages; client->handle_messages = ssh_guac_client_handle_messages;
client->clipboard_handler = ssh_guac_client_clipboard_handler; client->clipboard_handler = ssh_guac_client_clipboard_handler;

View File

@ -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; ssh_guac_client_data* guac_client_data = (ssh_guac_client_data*) client->data;
/* Close SSH client */ /* Close terminal output pipe */
close(STDOUT_FILENO); close(guac_client_data->stdout_pipe_fd[1]);
close(STDIN_FILENO); 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); pthread_join(guac_client_data->client_thread, NULL);
/* Free terminal */ /* Free terminal */

View File

@ -262,6 +262,9 @@ void* ssh_client_thread(void* data) {
return NULL; return NULL;
} }
/* Wait for input thread to die */
pthread_join(input_thread, NULL);
guac_client_log_info(client, "SSH connection ended."); guac_client_log_info(client, "SSH connection ended.");
return NULL; return NULL;