+ # We need to use flock(1) (from util-linux) to avoid timeouts
+ # and SQLite locking problems.
+ # FreeBSD has a similar lockf(1) utility, but it unlinks by
+ # default so we use `-k' to keep the lock on the FS.
+ FLOCK=flock
+ case $(uname -s) in
+ FreeBSD) FLOCK='lockf -k' ;;
+ # ... other OSes here
+ esac
+
+ n=$(echo 'SELECT COUNT(*) FROM msgmap' | \
+ $FLOCK $inbox_lock sqlite3 -readonly "$msgmap")