From a2893bac7e180d4d9011bfad5277fc088a947cbd Mon Sep 17 00:00:00 2001 From: pokamest Date: Wed, 30 Aug 2023 20:39:14 +0100 Subject: [PATCH] Fixes for sudo error "host not found" --- client/core/servercontroller.cpp | 11 ++++++----- client/server_scripts/check_server_is_busy.sh | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/client/core/servercontroller.cpp b/client/core/servercontroller.cpp index 05f422bc..e5505d46 100644 --- a/client/core/servercontroller.cpp +++ b/client/core/servercontroller.cpp @@ -637,7 +637,8 @@ ErrorCode ServerController::isServerPortBusy(const ServerCredentials &credential QString defaultTransportProto = ProtocolProps::transportProtoToString(ProtocolProps::defaultTransportProto(protocol), protocol); QString transportProto = containerConfig.value(config_key::transport_proto).toString(defaultTransportProto); - QString script = QString("which lsof &>/dev/null || true && sudo lsof -i -P -n | grep -E ':%1 ").arg(port); + // TODO reimplement with netstat + QString script = QString("which lsof &>/dev/null || true && sudo lsof -i -P -n 2>/dev/null | grep -E ':%1 ").arg(port); for (auto &port : fixedPorts) { script = script.append("|:%1").arg(port); } @@ -699,7 +700,7 @@ ErrorCode ServerController::isServerDpkgBusy(const ServerCredentials &credential QFuture future = QtConcurrent::run([this, &stdOut, &cbReadStdOut, &cbReadStdErr, &credentials]() { // max 100 attempts - for (int i = 0; i < 100; ++i) { + for (int i = 0; i < 30; ++i) { if (m_cancelInstallation) { return ErrorCode::ServerCancelInstallation; } @@ -708,8 +709,8 @@ ErrorCode ServerController::isServerDpkgBusy(const ServerCredentials &credential replaceVars(amnezia::scriptData(SharedScriptType::check_server_is_busy), genVarsForScript(credentials)), cbReadStdOut, cbReadStdErr); - // if 'fuser' is not installed, skip check - if (stdOut.contains("Not installed")) return ErrorCode::NoError; + if (stdOut.contains("Packet manager not found")) return ErrorCode::ServerPacketManagerError; + if (stdOut.contains("fuser not installed")) return ErrorCode::NoError; if (stdOut.isEmpty()) { return ErrorCode::NoError; @@ -719,7 +720,7 @@ ErrorCode ServerController::isServerDpkgBusy(const ServerCredentials &credential qDebug().noquote() << stdOut; #endif emit serverIsBusy(true); - QThread::msleep(5000); + QThread::msleep(10000); } } return ErrorCode::ServerPacketManagerError; diff --git a/client/server_scripts/check_server_is_busy.sh b/client/server_scripts/check_server_is_busy.sh index 24c2924c..e1ba63f8 100644 --- a/client/server_scripts/check_server_is_busy.sh +++ b/client/server_scripts/check_server_is_busy.sh @@ -2,4 +2,4 @@ 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 +if command -v fuser > /dev/null 2>&1; then sudo fuser $LOCK_FILE 2>/dev/null; else echo "fuser not installed"; fi