X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?p=bin.git;a=blobdiff_plain;f=bsmtp-pull;h=ebaee7ed7a652a2962456ab9756e907e40757cae;hp=2c7e7b9813135bca6a6d73d47e24abd8e891189f;hb=8dabab27b9384f2587eee2cdeb3c35644dd7bc36;hpb=008357a5011fe968dcdcebc9ce15758651ac0bda diff --git a/bsmtp-pull b/bsmtp-pull index 2c7e7b9..ebaee7e 100755 --- a/bsmtp-pull +++ b/bsmtp-pull @@ -1,4 +1,4 @@ -#! /bin/sh +#! /bin/bash # Depends: lockfile-progs, ssh set -e @@ -7,7 +7,7 @@ if [ -z "$1" ]; then exit 1 fi -DIR="$HOME/.bsmtp" +DIR="$HOME/tmp/.bsmtp" mkdir -p "$DIR" cd "$DIR" @@ -19,13 +19,16 @@ 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 +disown %1 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