From a92fc5f553468b634b29ca86fb067b06595d601f Mon Sep 17 00:00:00 2001 From: Mark Kelly Date: Sat, 26 May 2018 20:30:36 -0400 Subject: [PATCH] Fix rare race condition for cache file --- usr/lib/byobu/updates_available | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/usr/lib/byobu/updates_available b/usr/lib/byobu/updates_available index ec3a8d9b..739e7e05 100755 --- a/usr/lib/byobu/updates_available +++ b/usr/lib/byobu/updates_available @@ -50,7 +50,8 @@ ___update_cache() { # Ensure that no more than one of these run at a given time if [ -x /usr/lib/update-notifier/apt-check ]; then # If apt-check binary exists, use it - flock -xn "$flock" /usr/lib/update-notifier/apt-check 2>&1 | awk '-F;' 'END { print $1, $2 }' >"$mycache" 2>/dev/null & + # orig - flock -xn "$flock" /usr/lib/update-notifier/apt-check 2>&1 | awk '-F;' 'END { print $1, $2 }' >"$mycache" 2>/dev/null & + flock -xn "$flock" sh -c "(/usr/lib/update-notifier/apt-check 2>&1 | awk '-F;' 'END { print \$1, \$2 }' >\"${mycache}-x\" 2>/dev/null ; mv \"${mycache}-x\" \"$mycache\")" & elif eval $BYOBU_TEST apt-get >/dev/null; then # If apt-get exists, use it flock -xn "$flock" apt-get -s -o Debug::NoLocking=true upgrade | grep -c ^Inst >$mycache 2>/dev/null & @@ -85,8 +86,19 @@ ___update_needed() { [ ! -e "$mycache" ] && return 0 if eval $BYOBU_TEST apt-get >/dev/null; then # Debian/ubuntu - [ "/var/lib/apt" -nt "$mycache" ] || [ "/var/lib/apt/lists" -nt "$mycache" ] - return $? + # orig - [ "/var/lib/apt" -nt "$mycache" ] || [ "/var/lib/apt/lists" -nt "$mycache" ] + # orig - return $? + d0=$(($(stat -c %Y $mycache 2>/dev/null)-5)) + d1=$(stat -c %Y /var/lib/apt) + d2=$(stat -c %Y /var/lib/apt/lists) + d3=$(stat -c %Y /var/log/dpkg.log) + now=$(date +%s) + delta=$(($now-$d0)) + if [ $d0 -lt 0 -o $d1 -ge $d0 -o $d2 -ge $d0 -o $d3 -ge $d0 -o $delta -ge 3605 ] ; then + return 0 + else + return 1 + fi elif [ -e "/var/lib/PackageKit/transactions.db" ]; then [ "/var/lib/PackageKit/transactions.db" -nt "$mycache" ] return $?