Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/Remmina/Remmina.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntenore Gatta (tmow) <antenore@simbiosi.org>2022-04-07 17:53:58 +0300
committerAntenore Gatta (tmow) <antenore@simbiosi.org>2022-04-07 17:53:58 +0300
commit131a0d619bbdae3f0cdf68730716083411b037df (patch)
tree3635d3886373a41a51fe6d62a027bdb5987ff40c
parent561d08c84d38cb5b3f2e3d093afd7ae571ad4427 (diff)
Thread issues fixesissue/2713-ssh-x11-forward
-rw-r--r--CMakeLists.txt4
-rw-r--r--src/remmina_ssh.c100
2 files changed, 18 insertions, 86 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ee844f6c4..ec06950da 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -452,6 +452,10 @@ if(CMAKE_COMPILER_IS_GNUCC AND WITH_GCC_SANITIZE_ADDRESS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
endif()
+if(CMAKE_COMPILER_IS_GNUCC AND WITH_GCC_SANITIZE_THREAD)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
+endif()
+
# LLVM coverage flags - https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
if("${CMAKE_C_COMPILER_ID}" MATCHES "Clang" AND WITH_CLANG_COVERAGE)
message(STATUS "Enabling coverage.")
diff --git a/src/remmina_ssh.c b/src/remmina_ssh.c
index 755550b82..e46b972ca 100644
--- a/src/remmina_ssh.c
+++ b/src/remmina_ssh.c
@@ -135,7 +135,6 @@ typedef struct item {
node_t *node = NULL;
-//pthread_mutex_t mutex;
pthread_mutex_t mutex;
// Linked nodes to manage channel/fd tuples
@@ -534,7 +533,7 @@ remmina_ssh_cp_to_fd_cb(ssh_session session, ssh_channel channel, void *data, ui
TRACE_CALL(__func__);
(void)session;
(void)is_stderr;
- //RemminaSSHShell *ssh = (RemminaSSHShell *)userdata;
+ (void)userdata;
node_t *temp_node = remmina_ssh_search_item(channel);
int fd = temp_node->fd_out;
@@ -553,8 +552,7 @@ remmina_ssh_ch_close_cb(ssh_session session, ssh_channel channel, void *userdata
{
TRACE_CALL(__func__);
(void)session;
- //(void)userdata;
- //RemminaSSHShell *ssh = (RemminaSSHShell *)userdata;
+ (void)userdata;
node_t *temp_node = remmina_ssh_search_item(channel);
@@ -580,8 +578,7 @@ remmina_ssh_x11_open_request_cb(ssh_session session, const char *shost, int spor
REMMINA_DEBUG("Entering function %s", __func__);
(void)shost;
(void)sport;
- //(void)userdata;
- //RemminaSSHShell *shell = (RemminaSSHShell *)userdata;
+ (void)userdata;
ssh_channel channel = ssh_channel_new(session);
@@ -595,7 +592,6 @@ remmina_ssh_x11_open_request_cb(ssh_session session, const char *shost, int spor
ssh_event_add_session(event, session);
// SSH Channel Callbacks
- //ssh_set_channel_callbacks(channel, &channel_cb);
ssh_add_channel_callbacks(channel, &channel_cb);
return channel;
@@ -622,7 +618,6 @@ remmina_ssh_main_loop(RemminaSSHShell *shell)
return -1;
}
- //if (ssh_event_add_fd(event, fileno(stdin), events, remimna_ssh_cp_to_ch_cb, shell) != SSH_OK) {
if (ssh_event_add_fd(event, shell->slave, events, remimna_ssh_cp_to_ch_cb, shell->channel) != SSH_OK) {
REMMINA_DEBUG("Couldn't add an fd to the event");
return -1;
@@ -638,7 +633,6 @@ remmina_ssh_main_loop(RemminaSSHShell *shell)
} while (!ssh_channel_is_closed(shell->channel));
remmina_ssh_delete_item(shell->channel);
- //ssh_event_remove_fd(event, fileno(stdin));
ssh_event_remove_fd(event, shell->slave);
ssh_event_remove_session(event, session);
ssh_event_free(event);
@@ -704,7 +698,6 @@ remmina_ssh_auth_interactive(RemminaSSH *ssh)
gint n;
gint i;
const gchar *name, *instruction = NULL;
- //gchar *prompt,*ptr;
ret = SSH_AUTH_ERROR;
if (ssh->authenticated) return REMMINA_SSH_AUTH_SUCCESS;
@@ -2886,14 +2879,10 @@ remmina_ssh_shell_thread(gpointer data)
RemminaProtocolWidget *gp = (RemminaProtocolWidget *)shell->user_data;
RemminaFile *remminafile;
remminafile = remmina_protocol_widget_get_file(gp);
- fd_set fds;
- struct timeval timeout;
ssh_channel channel = NULL;
- ssh_channel ch[2], chout[2];
gchar *buf = NULL;
gint buf_len;
- gint len;
- gint i, ret;
+ gint ret;
gchar *filename;
const gchar *dir;
const gchar *sshlogname;
@@ -2912,7 +2901,7 @@ remmina_ssh_shell_thread(gpointer data)
// TRANSLATORS: The placeholder %s is an error message
remmina_ssh_set_error(REMMINA_SSH(shell), _("Could not open channel. %s"));
if (channel) ssh_channel_free(channel);
- shell->thread = 0;
+ //shell->thread = 0;
return NULL;
}
@@ -2967,9 +2956,6 @@ remmina_ssh_shell_thread(gpointer data)
buf_len = 1000;
buf = g_malloc(buf_len + 1);
- ch[0] = channel;
- ch[1] = NULL;
-
GFile *rf = g_file_new_for_path(remminafile->filename);
if (remmina_file_get_string(remminafile, "sshlogfolder") == NULL)
@@ -3000,62 +2986,9 @@ remmina_ssh_shell_thread(gpointer data)
UNLOCK_SSH(shell)
REMMINA_DEBUG("Run_line written to channel");
}
-#if 0
- while (!shell->closed) {
- timeout.tv_sec = 1;
- timeout.tv_usec = 0;
-
- FD_ZERO(&fds);
- FD_SET(shell->slave, &fds);
-
- ret = ssh_select(ch, chout, shell->slave + 1, &fds, &timeout);
- if (ret == SSH_EINTR) continue;
- if (ret == -1) break;
-
- if (FD_ISSET(shell->slave, &fds)) {
- len = read(shell->slave, buf, buf_len);
- if (len <= 0) break;
- LOCK_SSH(shell)
- ssh_channel_write(channel, buf, len);
- UNLOCK_SSH(shell)
- }
-
- for (i = 0; i < 2; i++) {
- LOCK_SSH(shell)
- len = ssh_channel_poll(channel, i);
- UNLOCK_SSH(shell)
- if (len == SSH_ERROR || len == SSH_EOF) {
- REMMINA_DEBUG("SSH shell error or EOF, closing the channel");
- shell->closed=TRUE;
- break;
- }
- if (len <= 0) continue;
- if (len > buf_len) {
- buf_len = len;
- buf = (gchar *)g_realloc(buf, buf_len + 1);
- }
- LOCK_SSH(shell)
- len = ssh_channel_read_nonblocking(channel, buf, len, i);
- UNLOCK_SSH(shell)
- if (len <= 0) {
- shell->closed=TRUE;
- break;
- }
- while (len > 0) {
- ret = write(shell->slave, buf, len);
- if (fp != NULL) {
- fwrite(buf, ret, 1, fp );
- fflush(fp);
- }
- if (ret <= 0) break;
- len -= ret;
- }
- }
- }
-
-#endif
ret = remmina_ssh_main_loop(shell);
- if (ret != SSH_OK) return NULL;
+ //if (ret != SSH_OK) return NULL;
+ if (ret != SSH_OK) REMMINA_DEBUG("Problem starting a shell");
LOCK_SSH(shell)
if (remmina_file_get_int (remminafile, "sshsavesession", FALSE))
@@ -3124,21 +3057,16 @@ void
remmina_ssh_shell_free(RemminaSSHShell *shell)
{
TRACE_CALL(__func__);
- pthread_t thread = shell->thread;
- void *ret;
+ //pthread_t thread = shell->thread;
shell->exit_callback = NULL;
- if (thread) {
- shell->closed = TRUE;
- //pthread_join(thread, NULL);
- REMMINA_DEBUG("Waiting for thread %s to end", thread);
- if (pthread_join(thread, &ret) != 0) {
- perror("pthread_join() error");
- REMMINA_DEBUG("pthread_join cannot wait for %s to end because of %s", thread, ret);
- //exit(3);
- }
- REMMINA_DEBUG("Thread added");
+ shell->closed = TRUE;
+ REMMINA_DEBUG("Cancelling the shell thread if needed");
+ if (shell->thread) {
+ pthread_cancel(shell->thread);
+ if (shell->thread) pthread_join(shell->thread, NULL);
}
+
close(shell->slave);
if (shell->exec) {
REMMINA_DEBUG("Closing exec");