From 13250ec081a96ce933c2094460c43209b421baf9 Mon Sep 17 00:00:00 2001 From: Apex Liu Date: Sun, 30 Apr 2017 17:46:11 +0000 Subject: [PATCH] 1. try to fix crash on Linux by use libssh multi-thread initialization function. 2. update libssh to v0.7.5. 3. update build script to match libssh threads library. --- build/builder/build-external.py | 11 ++++++++--- external/version.ini | 2 +- server/tp_core/core/CMakeLists.txt | 3 ++- server/tp_core/core/ts_main.cpp | 2 +- server/tp_core/protocol/ssh/CMakeLists.txt | 2 +- server/tp_core/protocol/ssh/tpssh.cpp | 5 +++++ 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/build/builder/build-external.py b/build/builder/build-external.py index 70b34db..badbd89 100644 --- a/build/builder/build-external.py +++ b/build/builder/build-external.py @@ -422,7 +422,7 @@ class BuilderLinux(BuilderBase): # os.rename(os.path.join(self.PATH_TMP, 'master'), os.path.join(self.PATH_TMP, 'libssh-{}'.format(LIBSSH_VER))) cc.n('build libssh...', end='') - if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')): + if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')) and os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh_threads.a')): cc.w('already exists, skip.') return cc.v('') @@ -482,7 +482,9 @@ class BuilderLinux(BuilderBase): # because make install will fail because we can not disable ssh_shared target, # so we copy necessary files ourselves. utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'libssh.a')) + utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads', 'libssh_threads.a')) utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src'), os.path.join(self.PATH_RELEASE, 'lib'), 'libssh.a') + utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads'), os.path.join(self.PATH_RELEASE, 'lib'), 'libssh_threads.a') utils.copy_ex(os.path.join(self.LIBSSH_PATH_SRC, 'include'), os.path.join(self.PATH_RELEASE, 'include'), 'libssh') def _build_sqlite(self, file_name): @@ -504,7 +506,8 @@ class BuilderLinux(BuilderBase): def fix_output(self): # remove .so files, otherwise will link to .so but not .a in default. - rm = ['libsqlite3.la', 'libsqlite3.so.0', 'libsqlite3.so', 'libsqlite3.so.0.8.6', 'libuv.la', 'libuv.so.1', 'libuv.so', 'libuv.so.1.0.0'] + # rm = ['libsqlite3.la', 'libsqlite3.so.0', 'libsqlite3.so', 'libsqlite3.so.0.8.6', 'libuv.la', 'libuv.so.1', 'libuv.so', 'libuv.so.1.0.0'] + rm = ['libuv.la', 'libuv.so.1', 'libuv.so', 'libuv.so.1.0.0'] for i in rm: _path = os.path.join(self.PATH_RELEASE, 'lib', i) if os.path.exists(_path): @@ -550,7 +553,9 @@ def main(): builder.build_libuv() builder.build_mbedtls() builder.build_libssh() - builder.build_sqlite() + + # do not need sqlite any more. + # builder.build_sqlite() builder.fix_output() diff --git a/external/version.ini b/external/version.ini index f327296..cc745b6 100644 --- a/external/version.ini +++ b/external/version.ini @@ -36,7 +36,7 @@ openssl = 1.0.2h,1000208f libuv = 1.11.0 mbedtls = 2.3.0 sqlite = 3170000 -libssh = 0.7.4 +libssh = 0.7.5 jsoncpp = 0.10.6 mongoose = 6.6 diff --git a/server/tp_core/core/CMakeLists.txt b/server/tp_core/core/CMakeLists.txt index 1944597..05cc6ab 100644 --- a/server/tp_core/core/CMakeLists.txt +++ b/server/tp_core/core/CMakeLists.txt @@ -35,4 +35,5 @@ include_directories( link_directories(../../../external/linux/release/lib) add_executable(tp_core ${DIR_SRCS}) -target_link_libraries(tp_core ssl crypto mbedx509 mbedtls mbedcrypto sqlite3 dl pthread rt util) +#target_link_libraries(tp_core ssl crypto mbedx509 mbedtls mbedcrypto sqlite3 dl pthread rt util) +target_link_libraries(tp_core ssl crypto mbedx509 mbedtls mbedcrypto dl pthread rt util) diff --git a/server/tp_core/core/ts_main.cpp b/server/tp_core/core/ts_main.cpp index db58208..9c312a1 100644 --- a/server/tp_core/core/ts_main.cpp +++ b/server/tp_core/core/ts_main.cpp @@ -153,7 +153,7 @@ bool TppManager::load_tpp(const ex_wstr& libname) lib->dylib = ex_dlopen(libfile.c_str()); if (NULL == lib->dylib) { - EXLOGE(L"[core] load dylib `%ls` failed, maybe it not exists.\n", libfile.c_str()); + EXLOGE(L"[core] load dylib `%ls` failed.\n", libfile.c_str()); delete lib; return false; } diff --git a/server/tp_core/protocol/ssh/CMakeLists.txt b/server/tp_core/protocol/ssh/CMakeLists.txt index 1ffc4de..b35d1e6 100644 --- a/server/tp_core/protocol/ssh/CMakeLists.txt +++ b/server/tp_core/protocol/ssh/CMakeLists.txt @@ -22,4 +22,4 @@ include_directories( link_directories(../../../../external/linux/release/lib) add_library(tpssh SHARED ${DIR_SSH_SRCS}) -target_link_libraries(tpssh ssh ssl crypto mbedx509 mbedtls mbedcrypto dl pthread rt util) +target_link_libraries(tpssh ssh ssh_threads ssl crypto mbedx509 mbedtls mbedcrypto dl pthread rt util) diff --git a/server/tp_core/protocol/ssh/tpssh.cpp b/server/tp_core/protocol/ssh/tpssh.cpp index c1114ac..3fc3fcb 100644 --- a/server/tp_core/protocol/ssh/tpssh.cpp +++ b/server/tp_core/protocol/ssh/tpssh.cpp @@ -3,6 +3,11 @@ TPP_API ex_rv tpp_init(TPP_INIT_ARGS* init_args) { +#ifdef EX_OS_UNIX + ssh_threads_set_callbacks(ssh_threads_get_pthread()); + ssh_init(); +#endif + if (!g_ssh_env.init(init_args)) return TSR_FAILED;