Re: Unable to lock a file to stop sendmail writing to it




Quoth "GarfGarf" <garfield_99999@xxxxxxxxx>:

Gunnar Hjalmarsson wrote:
GarfGarf wrote:
I am trying to write a script that reads a mailbox that sendmail
updates, but I want to be able to lock the file, read the file, empty
the file and unlock the file again.
The problem I have is that locking doesn't seem to work.

I think your problem is merely a misconception with respect to the
meaning of flock(). As stated in

perldoc -f flock

the nature of an flock() lock is advisory.

sendmail writes into the file while i'm writing and that
causes all sorts of problems.

That's probably because sendmail doesn't use flock on the mailboxes.



Ok, thanks for the replies.
It seems flock is not the way to go..

So, how can I lock the file to stop sendmail spatting it?

You need to find out how sendmail *does* lock the files, then do the
same. It might use flock locking, fcntl locking or create a lockfile.
Then you do the same.

FWIW, if you use maildir mail folders you don't need locking...

Ben

--
The cosmos, at best, is like a rubbish heap scattered at random.
Heraclitus
benmorrow@xxxxxxxxxxxxx
.