From ba3ef98d1e578b0547746c52c22588e6383b5948 Mon Sep 17 00:00:00 2001 From: pokamest Date: Wed, 16 Aug 2023 08:08:08 -0700 Subject: [PATCH] Fix for server busy check (#287) Fix for server busy check --- CMakeLists.txt | 4 ++-- client/amnezia_application.cpp | 2 +- client/android/build.gradle | 2 +- client/core/defs.h | 1 + client/core/servercontroller.cpp | 24 ++++++++++++++----- client/server_scripts/check_server_is_busy.sh | 9 +++---- 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e0876473..9c4985fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,11 +2,11 @@ cmake_minimum_required(VERSION 3.25.0 FATAL_ERROR) set(PROJECT AmneziaVPN) -project(${PROJECT} VERSION 3.0.9.0 +project(${PROJECT} VERSION 3.0.9.1 DESCRIPTION "AmneziaVPN" HOMEPAGE_URL "https://amnezia.org/" ) -set(RELEASE_DATE "2023-07-15") +set(RELEASE_DATE "2023-08-16") set(APP_MAJOR_VERSION ${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}.${CMAKE_PROJECT_VERSION_PATCH}) if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") diff --git a/client/amnezia_application.cpp b/client/amnezia_application.cpp index 2f405550..7228e18d 100644 --- a/client/amnezia_application.cpp +++ b/client/amnezia_application.cpp @@ -56,7 +56,7 @@ setQuitOnLastWindowClosed(false); // Fix config file permissions -#ifdef Q_OS_LINUX && !defined(Q_OS_ANDROID) +#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) { QSettings s(ORGANIZATION_NAME, APPLICATION_NAME); s.setValue("permFixed", true); diff --git a/client/android/build.gradle b/client/android/build.gradle index 987dc3ba..cfc53460 100644 --- a/client/android/build.gradle +++ b/client/android/build.gradle @@ -138,7 +138,7 @@ android { resConfig "en" minSdkVersion = 24 targetSdkVersion = 34 - versionCode 31 // Change to a higher number + versionCode 32 // Change to a higher number versionName "3.0.9" // Change to a higher number javaCompileOptions.annotationProcessorOptions.arguments = [ diff --git a/client/core/defs.h b/client/core/defs.h index 452038a5..4fb140e4 100644 --- a/client/core/defs.h +++ b/client/core/defs.h @@ -33,6 +33,7 @@ enum ErrorCode ServerDockerFailedError, ServerCancelInstallation, ServerUserNotInSudo, + ServerPacketManagerError, // Ssh connection errors SshRequsetDeniedError, SshInterruptedError, SshInternalError, diff --git a/client/core/servercontroller.cpp b/client/core/servercontroller.cpp index 80d3b797..05f422bc 100644 --- a/client/core/servercontroller.cpp +++ b/client/core/servercontroller.cpp @@ -369,6 +369,7 @@ ErrorCode ServerController::installDockerWorker(const ServerCredentials &credent genVarsForScript(credentials)), cbReadStdOut, cbReadStdErr); qDebug().noquote() << "ServerController::installDockerWorker" << stdOut; + if (stdOut.contains("lock")) return ErrorCode::ServerPacketManagerError; if (stdOut.contains("command not found")) return ErrorCode::ServerDockerFailedError; return error; @@ -697,7 +698,8 @@ ErrorCode ServerController::isServerDpkgBusy(const ServerCredentials &credential QFutureWatcher watcher; QFuture future = QtConcurrent::run([this, &stdOut, &cbReadStdOut, &cbReadStdErr, &credentials]() { - do { + // max 100 attempts + for (int i = 0; i < 100; ++i) { if (m_cancelInstallation) { return ErrorCode::ServerCancelInstallation; } @@ -705,12 +707,22 @@ ErrorCode ServerController::isServerDpkgBusy(const ServerCredentials &credential runScript(credentials, replaceVars(amnezia::scriptData(SharedScriptType::check_server_is_busy), genVarsForScript(credentials)), cbReadStdOut, cbReadStdErr); - if (!stdOut.isEmpty() || stdOut.contains("Unable to acquire the dpkg frontend lock")) { - emit serverIsBusy(true); - QThread::msleep(1000); + + // if 'fuser' is not installed, skip check + if (stdOut.contains("Not installed")) return ErrorCode::NoError; + + if (stdOut.isEmpty()) { + return ErrorCode::NoError; } - } while (!stdOut.isEmpty()); - return ErrorCode::NoError; + else { + #ifdef MZ_DEBUG + qDebug().noquote() << stdOut; + #endif + emit serverIsBusy(true); + QThread::msleep(5000); + } + } + return ErrorCode::ServerPacketManagerError; }); QEventLoop wait; diff --git a/client/server_scripts/check_server_is_busy.sh b/client/server_scripts/check_server_is_busy.sh index 17c27864..24c2924c 100644 --- a/client/server_scripts/check_server_is_busy.sh +++ b/client/server_scripts/check_server_is_busy.sh @@ -1,4 +1,5 @@ -pm_apt="/usr/bin/apt-get";\ -if [[ -f "$pm_apt" ]]; then pm=$pm_apt; else exit; fi;\ -if [[ ! -f "/usr/bin/sudo" ]]; then $pm update -y -q; $pm install -y -q sudo; fi;\ -sudo fuser /var/lib/dpkg/lock-frontend \ No newline at end of file +if which apt-get > /dev/null 2>&1; then LOCK_FILE="/var/lib/dpkg/lock-frontend";\ +elif which dnf > /dev/null 2>&1; then LOCK_FILE="/var/run/dnf.pid";\ +elif which yum > /dev/null 2>&1; then LOCK_FILE="/var/run/yum.pid";\ +else echo "Packet manager not found"; echo "Internal error"; exit 1; fi;\ +if command -v fuser > /dev/null 2>&1; then sudo fuser $LOCK_FILE; else echo "Not installed"; fi