Truncate files used for sessions before writing

There was a race between opening a file for writing and lock acquistion,
which creates an opportunity for corruption.  This commit seeks to the
start of the file and truncates it after the lock is acquired.

It also changes the read lock to LOCK_SH, as reading doesn't require an
exclusive lock.  The usual application race between session reading and
session writing exists regardless of this change.

This resolves issue #448.
Merge branch 'truncate-session-files'