procmail
[Top] [All Lists]

Re: Archiving mail

1997-11-13 14:45:34
At 11:02 AM, 13 November 1997, Matt Armstrong <matta(_at_)geoworks(_dot_)com> 
wrote:
#!/bin/sh
TODAY=`date +%m.%y`
PMDIR=$HOME/.procmail
echo "TODAY=$TODAY" >$PMDIR/date.rc

It outputs a file like this:

TODAY=11.97


What is to keep procmail from reading date.rc at the same time the
shell script is writing it out?  What's to keep procmail from seeing
something like this:

TO
-or-
TODAY=
-or-
TODAY=11.

I've often wondered about similar problems when saving my .procmailrc,
etc.  Is there something about Unix that keeps these things atomic?

No, it isn't atomic.  But, in this case echo should be using only one
call to write(2), which would be atomic.  So procmail would see either
the whole file or an empty file, not something between.

To ensure that procmail always sees the whole statement, replace the
last line with something like:

echo "TODAY=$TODAY" > $PMDIR/date.rc.tmp
mv $PMDIR/date.rc.tmp $PMDIR/date.rc

Since the rename(2) that will be done by mv is atomic.

-- 
Aaron Schrab     aaron(_at_)schrab(_dot_)com      http://www.execpc.com/~aarons/
 Disraeli was pretty close: actually, there are Lies, Damn lies,
 Statistics, Benchmarks, and Delivery dates.

<Prev in Thread] Current Thread [Next in Thread>