From c6d7631949d194a44879ec87bedc81ce0293049c Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Wed, 17 May 2017 14:32:27 +0200 Subject: bin/get-assignment: use trap --- bin/get-assignment | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/get-assignment b/bin/get-assignment index 1161444..dc881e8 100755 --- a/bin/get-assignment +++ b/bin/get-assignment @@ -38,12 +38,11 @@ hand_out_assignment() { sed 's|$|.locked|' | \ xargs -rn1 touch - rm -f "${lock_file}" exit 0 } -# Create a lock file. +# Create a lock file and a trap. exec 9> "${lock_file}" if ! flock -n 9; then @@ -51,6 +50,12 @@ if ! flock -n 9; then exit 1 fi +function clean_up { + rm -f "${lock_file}" +} + +trap clean_up EXIT + # Check if there are any pending packages at all and if the requester # has already hit its max_parallel_build_per_client limit. @@ -72,13 +77,11 @@ done < "${work_dir}/build-list" if ! ${pending_packages}; then >&2 echo 'come back after the next run of get-package-updates - currently there are no pending packages' - rm -f "${lock_file}" exit 3 fi if [ ${num_jobs} -ge ${max_parallel_build_per_client} ]; then >&2 echo "come back, when you've done your work - you hit the limit on maximum allowed parallel jobs per ip" - rm -f "${lock_file}" exit 4 fi @@ -125,5 +128,4 @@ done # Remove the lock file >&2 echo 'come back later - there are still packages to be built, but currently none has all its dependencies ready' -rm -f "${lock_file}" exit 2 -- cgit v1.2.3-54-g00ecf