From a6b3a1871fcde0e0606f9f563f6cc337cf9de59a Mon Sep 17 00:00:00 2001 From: shenmo Date: Wed, 15 Jan 2025 06:33:31 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E6=97=A0=E9=99=90?= =?UTF-8?q?=E7=AD=89=E5=BE=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shenmo --- tool/apt-fast/ss-apt-fast | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tool/apt-fast/ss-apt-fast b/tool/apt-fast/ss-apt-fast index 88c8838..9f8217a 100755 --- a/tool/apt-fast/ss-apt-fast +++ b/tool/apt-fast/ss-apt-fast @@ -231,17 +231,25 @@ _create_lock() { eval "exec $LCK_FD>\"$LCK_FILE.lock\"" -# trap "cleanup_aptfast; exit_cleanup_state" EXIT -# This will hide the exit code + # 设置 trap 来清理资源 trap "cleanup_aptfast" EXIT trap "cleanup_aptfast; exit 1" INT TERM - timer=0 - until $(flock -xn $LCK_FD);do - msg_already_running - sleep 1 - let timer+=1 - done - unset timer + + timer=0 + max_wait=180 # 最大等待时间为180秒(3分钟) + + until $(flock -xn $LCK_FD); do + msg_already_running + sleep 1 + let timer+=1 + + if [ $timer -ge $max_wait ]; then + echo "timeout" + exit 1 + fi + done + + unset timer } # unlock and remove the lock file