This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goclient. commit 07a37d3aa378f18de6a8aa9a268fc90ef10e38bc Author: Mihai Moldovan <ionic@ionic.de> Date: Sat Sep 9 05:37:56 2017 +0200 src/{onmainwindow,sshmasterconnection}.{cpp,h}: correctly initialize and finalize libssh. We ought to do both only once - in our main thread. Previously, we initialized libssh in a new thread, which might be problematic. --- debian/changelog | 4 ++++ src/onmainwindow.cpp | 22 +++++++++++++++++++++- src/onmainwindow.h | 2 ++ src/sshmasterconnection.cpp | 41 ----------------------------------------- src/sshmasterconnection.h | 1 - 5 files changed, 27 insertions(+), 43 deletions(-) diff --git a/debian/changelog b/debian/changelog index c81d01c..43bfe2a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -188,6 +188,10 @@ x2goclient (4.1.0.1-0x2go1) UNRELEASED; urgency=medium Client is multi-threaded. - copy-deps-win32.bat: also copy libssh_threads.dll to go with the previous change. + - src/{onmainwindow,sshmasterconnection}.{cpp,h}: correctly initialize and + finalize libssh. We ought to do both only once - in our main thread. + Previously, we initialized libssh in a new thread, which might be + problematic. * x2goclient.spec: - Respect %{optflags} and pass QMAKE_STRIP=: to fix missing debug info issues. diff --git a/src/onmainwindow.cpp b/src/onmainwindow.cpp index b7f65d7..0cb4f2c 100644 --- a/src/onmainwindow.cpp +++ b/src/onmainwindow.cpp @@ -550,6 +550,8 @@ ONMainWindow::ONMainWindow ( QWidget *parent ) :QMainWindow ( parent ) activateWindow(); raise(); } + + QTimer::singleShot (200, this, SLOT (slotInitLibssh ())); } @@ -1607,7 +1609,13 @@ void ONMainWindow::closeClient() #endif cleanPortable(); } - SshMasterConnection::finalizeLibSsh(); + + if (ssh_finalize ()) { + x2goDebug << "Unable to finalize libssh. Something may be wrong!"; + } + else { + x2goDebug << "libssh finalized."; + } x2goInfof(7)<<tr("Finished X2Go Client closing hooks."); } @@ -12935,6 +12943,18 @@ long ONMainWindow::findWindow ( QString text ) return 0; } +void ONMainWindow::slotInitLibssh () { + /* Initialize libssh. This must be done outside of any threading context. */ + x2goDebug << "libssh not initialized yet. Initializing."; + ssh_threads_set_callbacks(ssh_threads_get_pthread ()); + if (ssh_init ()) { + x2goDebug << "Cannot initialize libssh."; + QMessageBox::critical (this, tr ("libssh initialization failure"), + tr ("Unable to initialize libssh.")); + trayQuit (); + } +} + //////////////////////////plugin stuff////////////// #ifdef CFGPLUGIN diff --git a/src/onmainwindow.h b/src/onmainwindow.h index a7aa00d..a5d518f 100644 --- a/src/onmainwindow.h +++ b/src/onmainwindow.h @@ -45,6 +45,7 @@ #include <QLocale> #include <QProcessEnvironment> #include <QDirIterator> +#include <libssh/callbacks.h> #include "sshmasterconnection.h" #include "non_modal_messagebox.h" @@ -1166,6 +1167,7 @@ private slots: void slotReconnectSession(); void slotStartBroker(); void slotStartNewBrokerSession (); + void slotInitLibssh (); #ifdef Q_OS_DARWIN void slotSetModMap(); void handle_xmodmap_error (QProcess &proc); diff --git a/src/sshmasterconnection.cpp b/src/sshmasterconnection.cpp index e0ea7d2..c0360b8 100644 --- a/src/sshmasterconnection.cpp +++ b/src/sshmasterconnection.cpp @@ -54,8 +54,6 @@ #undef SSH_DEBUG // #define SSH_DEBUG -static bool isLibSshInited=false; - const QString SshMasterConnection::challenge_auth_code_prompts_[] = { "Verification code:", // GA (http://github.com/google/google-authenticator) "One-time password (OATH) for", // OATH (http://www.nongnu.org/oath-toolkit/pam_oath.html) @@ -566,29 +564,6 @@ void SshMasterConnection::run() } } disconnectSessionFlag=false; - if ( !isLibSshInited ) - { -#ifdef DEBUG - x2goDebug<<"libssh not initialized yet. Initializing."; -#endif - if ( ssh_init() !=0 ) - { - QString err=tr ( "Cannot initialize libssh." ); -#ifdef DEBUG - x2goDebug<<err<<endl; -#endif - emit connectionError ( err,"" ); - quit(); - return; - } - isLibSshInited=true; - } -#ifdef DEBUG - else - { - x2goDebug<<"libssh already initialized."; - } -#endif #ifdef SSH_DEBUG int verbosity=SSH_LOG_PACKET; @@ -836,22 +811,6 @@ SshMasterConnection::~SshMasterConnection() } -void SshMasterConnection::finalizeLibSsh() -{ - if ( !isLibSshInited ) - { -#ifdef DEBUG - x2goDebug<<"libssh not initialized yet."; -#endif - return; - } - - ssh_finalize(); -#ifdef DEBUG - x2goDebug<<"libssh finalized."; -#endif -} - bool SshMasterConnection::sshConnect() { int rc; diff --git a/src/sshmasterconnection.h b/src/sshmasterconnection.h index 18ef0a4..e6924e0 100644 --- a/src/sshmasterconnection.h +++ b/src/sshmasterconnection.h @@ -81,7 +81,6 @@ public: QString proxylogin=QString::null, QString proxypassword=QString::null, QString proxyKey=QString::null, bool proxyAutologin=false, bool proxyKrbLogin=false); ~SshMasterConnection(); - static void finalizeLibSsh(); void addChannelConnection(SshProcess* creator, int sock, QString forwardHost, int forwardPort, QString localHost, int localPort, void* channel=0l); void addChannelConnection(SshProcess* creator, QString uuid, QString cmd); -- Alioth's /srv/git/code.x2go.org/x2goclient.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2goclient.git