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



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.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.



Relevant Pages

  • Behavior of flock() oriented procedures
    ... If I lock a file descriptor using either flock() or open, ... descriptore without explicitly calling flockwith the unlock message, ...
    (comp.unix.programmer)
  • Re: Unable to lock a file to stop sendmail writing to it
    ... the file and unlock the file again. ... meaning of flock(). ... the nature of an flock() lock is advisory. ... how can I lock the file to stop sendmail spatting it? ...
    (comp.lang.perl.misc)
  • std::queue empty() is thread safe?
    ... just want to know if std::queue empty() is thread safe (running on 2 or more ...
    (microsoft.public.dotnet.languages.vc)
  • Re: I cant flock, it returns 0, any ideas.
    ... > I can't flock, it returns 0, any ideas. ... You can only hold a lock on an open file. ... will fail but attempts to get another LOCK_SH lock will ... this is not how you pause the script! ...
    (comp.lang.perl.misc)
  • Re: I cant flock, it returns 0, any ideas.
    ... # returns zero when I try to flock ... >> I wanted to run this script to see if it would affect my other perl ... If someone holds a LOCK_EX lock, all attempts to get a lock will ... > the flock call will fail, and if you don't flock will just not ...
    (comp.lang.perl.misc)