[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Mailbox locking



Niko Tyni wrote:

On Tue, Dec 20, 2005 at 03:17:27PM +0200, Niko Tyni wrote:

Using fcntl() locks from Perl seems a bit tricky, since I'll have to
pack() the lock argument together myself. I need some advice here.

OK, I found this trick in Mail::Box::Locker::Posix (in libmail-box-perl):

fcntl($file, F_SETLK, pack('s @256', F_WRLCK))

I assume the 256 means "so many zero bytes that it's certainly enough".
That's good enough for me too.

It's easy if you're only worrying about Debian, as you don't have to worry about the different structures that different OSes use for the argument to fcntl.

I tried to write a "proper" portable fcntl locking function for perl when I was working on mailscanner, but never had access to some of the less common platforms to test it on. So mailscanner does it the "simple" way with pack() -- have a look at that for an example.


Cheers,


Nick

--
Nick Phillips / +64 3 479 4195 / nick.phillips@stonebow.otago.ac.nz
# these statements are my own, not those of the University of Otago



Reply to: