fix race conditions reading/writing datafile

Description and repro:

If several processes simultaneously try to read and write the datafile,
you may wind up with an empty datafile.

I noticed this when opening up many shells at once with `screen -c dev`,
where `dev` contains:

    source /etc/screenrc
    screen -t home
    chdir /tmp
    screen -t tmp1
    screen -t tmp2
    screen -t tmp3
    screen -t tmp4
    screen -t tmp5

In one or more of the screen windows I see

    mv: cannot stat `/home/adamm/.j.tmp': No such file or directory

and I notice my datafile has been truncated.