From 520044373f5f88367ce0e58641890f800e896ae4 Mon Sep 17 00:00:00 2001 From: Kyle Harding Date: Wed, 22 Nov 2023 15:58:53 -0500 Subject: [PATCH] Fix update locking Signed-off-by: Kyle Harding --- .../s6-overlay/s6-rc.d/lock-manager/run | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/yocto-build-env/s6-overlay/s6-rc.d/lock-manager/run b/yocto-build-env/s6-overlay/s6-rc.d/lock-manager/run index 0916d44..68e7a08 100644 --- a/yocto-build-env/s6-overlay/s6-rc.d/lock-manager/run +++ b/yocto-build-env/s6-overlay/s6-rc.d/lock-manager/run @@ -8,29 +8,23 @@ LOCKFILE=/tmp/balena/updates.lock while true; do ( + # request an exclusive lock in non-blocking mode + flock -n 200 || exit 0 + # check for active sessions while last | grep -q "still logged in"; do - # create the lockfile - touch $LOCKFILE - - # create a file descriptor over the given lockfile - exec {fd}<>${LOCKFILE} - - # request an exclusive lock in non-blocking mode - flock -n $fd || exit 0 - echo "Updates are locked while sessions are active..." last | grep "still logged in" # wait 30 seconds before checking again # updates are locked during this time sleep 30 - done - ) + ) 200>$LOCKFILE - # remove the lockfile (this should be unecessary?) + # remove the lockfile + # FIXME: why is this required when the lock is already released? rm -f $LOCKFILE # wait 5 seconds before checking again