summaryrefslogtreecommitdiff
path: root/bin/get-assignment
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2017-05-17 14:32:27 +0200
committerErich Eckner <git@eckner.net>2017-05-17 14:32:27 +0200
commitc6d7631949d194a44879ec87bedc81ce0293049c (patch)
tree141dc56bc42142c40f6f3bf06d42aade2734b798 /bin/get-assignment
parent72a0182a63d504c21083cffbc4e53af8d48da506 (diff)
downloadbuilder-c6d7631949d194a44879ec87bedc81ce0293049c.tar.xz
bin/get-assignment: use trap
Diffstat (limited to 'bin/get-assignment')
-rwxr-xr-xbin/get-assignment12
1 files changed, 7 insertions, 5 deletions
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