From 7c0900182487367b083ce03452b521d3e7d87812 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Mon, 21 Nov 2011 14:19:43 +0100 Subject: [PATCH 1/1] improved lock handling --- .bin/offlineimap | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.bin/offlineimap b/.bin/offlineimap index 82428cd..ae82806 100755 --- a/.bin/offlineimap +++ b/.bin/offlineimap @@ -5,12 +5,15 @@ set -eu VAR=$HOME/.var/offlineimap LOCKFILE="$VAR/.cron.lock" -trap "rm -f $LOCKFILE" 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15 +trapfn() { rm -f "$LOCKFILE"; trap - 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15; } +trap trapfn 1 2 3 4 5 6 7 8 10 11 12 13 14 15 if ! lockfile -0 -r0 -l 3600 "$LOCKFILE" 2>/dev/null; then echo "E: offlineimap is already running." >&2 exit 1 fi +trap trapfn 0 + if ! test -t 0; then echo Renicing because we are not run interactively… renice 20 -p $$ >/dev/null @@ -18,4 +21,7 @@ if ! test -t 0; then fi ret=0 -/usr/bin/offlineimap "$@" || exit $? +/usr/bin/offlineimap "$@" || ret=$? + +trapfn +exit $ret -- 2.39.5