X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?p=bin.git;a=blobdiff_plain;f=bsmtp-pull;h=5a0305f6bf071b9c52b387a84785817f4d636877;hp=5c95f92e4c067b2e1a149b2487f8b595c9494056;hb=1f1be658c6eacdc7065cfacd503c59009e803248;hpb=14b864f3bf2ae03124cd966476a3cc3aec671b33 diff --git a/bsmtp-pull b/bsmtp-pull index 5c95f92..5a0305f 100755 --- a/bsmtp-pull +++ b/bsmtp-pull @@ -19,13 +19,15 @@ HOST="$1" # By default, lockfile-create gives up after three minutes, so don't cron # this any more frequently than that without supplying a --retry argument. lockfile-create "$HOST" +# Race condition pointed out by pjb: this doesn't guarantee that the lock is +# held before the critical section starts. lockfile-touch "$HOST" & TOUCH="$!" trap 'kill "$TOUCH"; lockfile-remove "$HOST"' EXIT ERR HUP INT QUIT TERM ssh -2 -i "$HOME/.ssh/id-bsmtp-$HOST" -C "$HOST" bsmtp-pull-server > "$HOST" [ -s "$HOST" ] || exit 0 -/usr/sbin/sendmail -bS < "$HOST" +/usr/sbin/sendmail -bS -odq < "$HOST" rm -f "$HOST" exit 0