Skip to content

Commit

Permalink
Fix update locking
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Harding <kyle@balena.io>
  • Loading branch information
klutchell committed Nov 22, 2023
1 parent 514c0a7 commit 5200443
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions yocto-build-env/s6-overlay/s6-rc.d/lock-manager/run
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5200443

Please sign in to comment.